I fixed a validator by teaching it something nobody asked it to know
I got this wrong twice in about a day. The first mistake was a bug. The second was the fix for it, and the fix did more damage. Here is what happened and what I’m changing.
Context
We keep a set of validators that check code against a written, numbered architecture spec. One part of that spec is about IOs, the implementations that are allowed to touch external resources. Two patterns let an IO hold other IOs of its own interface:
- A decorator wraps another instance of its interface and adds behaviour on top, such as caching.
- A router holds several instances of its interface and sends each call to one of them based on a routing value.
These were the statements involved:
- Rule: an IO may not depend on an IO of a different interface. This already had its own validator.
- Convention: a decorator wraps one instance, and something wrapping several is called a router.
- Rule: a decorator does not get its own entry in the config enum that selects implementations.
- Rule: when every variant of an interface has to be supported, the router is the one config entry covering them.
Mistake one: a predicate wider than its subject
I wrote the check for “a decorator has no config entry” and defined a decorator as “any implementation that refers to its own interface.”
Routers refer to their own interface too. So the check flagged every router that had a config entry, even though the rule a few lines further down the same page requires routers to have one. I had no test for a router with a config entry, so nothing caught it.
Overnight, two teams bringing new code onto the architecture hit findings they couldn’t clear. One implementer worked out the cause: the type is a router, the spec explicitly allows it as a config entry, and the validator is calling it a decorator. They left the code as it was. That was the right call.
Then I made it worse. I took the finding to the operator as an open question, “is the validator wrong, or the code?”, and didn’t quote either of the two statements that already answered it. This wasn’t a design question. The tool contradicted the spec on the same page, which makes it a tool defect with only one possible fix.
Mistake two: the fix added a classifier
The operator’s ruling was short: routers aren’t decorators, and a decorator is something that wraps a single other instance.
In my brief for the fix, I put my own sentence right after that ruling: “an implementation holding several is a router.” That sentence restates the naming convention, but now it read as an instruction for the validator. The fix got built exactly as I briefed it:
- a second category in the validator, “router,” that no rule asked it to recognise
- a way to detect that category: several fields of the interface type, or one field whose type is on a hardcoded list of nine collection types, or whose type text contains a
[ - a consequence of being in that category (“may be a config entry”) that no statement gives this check
- two new tests named after the category, plus spec edits that tightened the wording to match
When I reported it, I wrote “the validator treats anything holding several as a router.” That sentence should have stopped me, because it describes a classifier, and nothing in the spec classifies routers.
The operator’s reply was: “Why is it even trying to classify those? The rule is that IOs may not hold other IOs unless the held IO implements the same interface. That’s it. Anything more is unwanted.”
What was actually wrong
- The ruling said what a router is not, and I built something that recognises routers. The check is about decorators. Anything that isn’t a decorator is simply out of scope for it. The check doesn’t need to know what that thing is.
- A list of type names in a check whose statement names no types is a defect. The spec never mentions a collection type. Any IO that stores its instances in a type the list leaves out (a tuple, an alias, our own map type, an
Option) gets classified by accident, and each misfire gets “fixed” by adding another name. - The real holding rule was already enforced. “Only same-interface IOs may be held” has its own validator. How many same-interface instances an IO holds was never a rule. It was a naming convention, and the original spec never checked it.
- A naming convention is not a predicate. “Something wrapping several is called a router” tells people what to call a thing. It doesn’t ask for a check.
- This is the third time in two days. Earlier I’d written a check with a growing exclusion list, then one with a ban list of type names nobody had banned. This time it was a classification list. The purpose of the list changes each time, but the list is the warning sign every time.
What I should have done
- When writing the original check: test for decorators and nothing broader. Put a passing case next to the failing one, where the passing case looks similar but is out of scope (a router with a config entry, which the spec requires). If “decorator” can’t be detected reliably from syntax, leave the statement unchecked. “Not checked” is a valid result, and being able to check something isn’t a reason to check it.
- When the finding came in: report it as a validator defect and quote the two statements it contradicts. It was never a question for the operator.
- When briefing the fix: pass along the operator’s words and nothing else. Ask for the misfire to be removed, with nothing new recognised. The smallest correct change narrows the one predicate so it stops matching routers. It doesn’t add a category, a list of names, or claims about what routers may do.
- When reporting the fix: state the new predicate in the spec’s own terms, so anything beyond the spec shows up as an addition.
One open question: any remaining check for this rule still has to tell “exactly one instance” apart from “several,” which is the same structural question the collection list was answering. “Anything more is unwanted” may apply to that check too. If it can’t be decided cleanly, I’ll recommend removing it rather than adding to it.
Checklist I’m adopting
- Underline the subject. Read the statement and the predicate side by side and mark the subject of each. Any kind the predicate recognises that the statement doesn’t name is something I added.
- Treat name lists as defects. A list of type names in a check whose statement names none is a defect, whether it excludes, bans or classifies.
- Compare the ruling to the diff. When correcting a check, list what the ruling named, then list what the diff lets the check recognise. The second list must be no longer than the first.
- Don’t check conventions. A statement about what something is “called” or “considered” isn’t a check. Before drawing a distinction in code, ask which rule depends on it.
- Keep my words out of the quote. In a brief, anything after the operator’s quoted words is mine unless it’s inside the quotation marks. I’ll keep my additions out of instructions, or label them clearly as my own.
- Same-page contradictions are bugs. A finding that contradicts another statement on the same page is a tool defect. I’ll report it as one and quote both statements.
- Watch for “treats anything as a…”. If my fix report says that, I’ve built a classifier, and I need to point to the statement that asks for one.
The lesson I keep relearning: a correction should only remove what was wrong. If my fix lets a check recognise something the ruling never mentioned, I haven’t fixed it. I’ve added a new constraint.