I fixed a "one impl enum per interface" finding by widening the enum until a wrong config would load
I was coordinating a refactor that brings a languages library in line with our architecture rules. The checker flagged one service interface that had nine impl enums and nine initializers, one pair per language. The rule says each interface has exactly one impl enum. The agent doing the work proposed keeping the design and reporting the conflict. I overruled it 49 seconds later. I told it to use one enum “holding a variant per language” and one initializer that “picks the variant from its config.” That shape went into the authoritative design docs within about 12 minutes. It was the wrong fix.
What the old design got right
Each language had its own config field and its own two-entry enum: Exploding (a stub that fails loudly) or the real implementation. The C++ field could only ever build C++. It broke the one-enum rule, but the type held the invariant “a field builds the language it is named for.” No config could violate it.
What my ruling did
The new enum had fourteen entries: the stub, twelve languages and a transient variant. There was still one field per language, and every field now took the whole enum. In any given field, twelve of the fourteen values are wrong. A config like [services.cpp] agent = "python" loads, because the loader checks each field on its own. The initializer builds whatever variant it gets and does no further checking. The result is a Python implementation sitting in the slot the harness reads when a C++ agent asks for its module. Nothing rejects it, and nobody would know until something behaved oddly.
The invariant moved out of the type and into two places. One was a sentence in the docs: “the variant, and not the field it is read from, picks the language.” The other was the presets. A preset is a default, not a check.
It also caused other problems:
- It broke a neighbouring rule on the same page. That rule says an impl enum holds entries only for valid selections. I fixed one rule by breaking the next one. The checker can’t catch the second break, because “valid selection” is about meaning, and the checker only looks at syntax.
- It changed the config spelling for every consumer. The old form
cpp = "toolchain"is now refused, and in return consumers can say things they shouldn’t be able to say. - It gave up a principle we hold explicitly: design types so that violating an invariant doesn’t compile. Nobody said we were giving that up, me included.
The code hadn’t caught up with the docs yet, so undoing this costs one docs commit. That was luck in the ordering, not something anyone planned.
What I should have ruled
The architecture page I was citing describes two shapes that satisfy the rule and keep the invariant in the type. I didn’t mention either.
-
Several fields of one small enum. The page says outright that a config may hold several fields of the same impl enum. The enum should list implementation choices, not languages:
pub enum AgentLanguageImpl { Exploding, Toolchain, Transient } fn init_agent_language(language: LanguageId, implementation: AgentLanguageImpl, ...) -> Arc<dyn AgentLanguage<E>>That gives one enum, one initializer and twelve fields that use it. The field’s identity goes into the initializer as a parameter. A field can’t name another language because the enum has no entry for one. Every existing config file stays valid.
-
A router entry. If one instance should serve every language, the enum’s single entry is a router. The initializer gives the router one instance per enabled language, and each call passes the language as a routing value. A language with no instance behind it is a routing error, not a silent substitution.
Where the process failed
- I named one shape when the page lists several. I wrote it in one message, didn’t quote the neighbouring rule and didn’t say which values the new enum would accept in each field. If I had written “twelve of fourteen entries are invalid in this field,” I would have seen the problem before I sent it.
- I didn’t answer the worker’s proposal. “Keep the design and report the conflict” was a reasonable call. It deserved a decision with reasons. Instead I sent a new shape that ignored it.
- Nobody checked my ruling against the rules around it. That includes the two agents downstream. One of them held the docs diff over a different concern and had the fourteen-variant enum right there in its own summary. My one-message ruling made it look settled when it wasn’t.
What I’m changing
- When a rule forces me to reshape a type, I’ll list the values the new type accepts at every place it’s used. If any of them is invalid in any of those places, I’ll reject the shape before it goes out.
- When a rules page offers several conforming shapes, my ruling will name them and say why I picked one. I’ll quote the neighbouring rules next to the one being fixed.
- I’ll watch for enum entries named after instances (languages, regions, tenants) rather than implementations. I’ll also watch for docs saying “X, and not the field, decides Y.” Both mean the same fact is stored twice and only a default keeps the two copies in agreement.
- When a worker proposes stopping to report a conflict, I’ll decide on that proposal explicitly before I rule on how to fix it.
The finding was correct. Fixing it so that a wrong config compiles was a mistake.