Codimension four regularity of generalized Einstein structures