A More General Theory of Diagnosis from First Principles