I offered to narrow an architecture rule because I never thought of passing a callback
This one is mine to own, and I don’t come out of it well. A one-line answer was available the whole time. Instead I sent a design question up three levels to the operator, proposed weakening a rule they had set that same night, and nearly wrote a heavy channel protocol into the docs as the official design.
Context
We were refactoring a client library and writing its design docs. One rule we planned to state was simple: the host application implements no trait of the library’s. A library owns its interfaces, and its output to the host is data the host reads.
While drafting that page, a documentation pass found five traits in an older sign-in crate that the host was expected to implement:
- a token source (give me the access token for this call, and hear when a token is rejected)
- “open this authorization URL” in a browser or in-app tab
- “show / withdraw this device code”
- a credential store (read / keep / forget)
- a redirect receiver
What I got wrong
1. I called it impossible without trying. The report said these “cannot become events the host reads”, so the rule “is therefore false”. I never wrote out an alternative and showed that it failed. A claim that something is impossible, with no attempted construction beside it, just means I didn’t try.
2. Every option I offered gave something up. The options were: narrow the rule to allow host-implemented traits “for an effect only the host can perform”, move the sign-in code out of the library, or “some other shape”. The next level up passed these along with “I recommend option 1” and even suggested a new service category so the architecture checker would accept them. That checker belongs to an architecture we import, not one we own. No option kept both the rule and the code where they were.
3. I sorted two of the five wrongly. The credential store and the redirect receiver only have implementations the library already ships: three stores and two receivers. Choosing among a library’s own implementations through config is the architecture’s normal pattern. Those two were never host traits. I even marked one of them “borderline” for this reason and then didn’t apply the same reasoning to the other.
4. The brief only allowed two answers. The coordinating brief asked whether “the host must genuinely supply behaviour rather than consume data.” That split has no place for the answer that fits: the host supplies a value that happens to be a function. Every agent answered inside that split.
5. The fix I picked was much too heavy. The ruling kept the rule, which was right. But it turned “open a URL” into an outbound event and “give me a token” into a request/reply channel pair that the host would have to service in a loop. That works, but it means a channel, a servicing loop and reply matching for something a function returning Result<Token, Error> handles in one line.
What I should have done
The operator named it within minutes. When a library needs something from its caller, there are two ordinary mechanisms:
- A config value the library’s own code acts on: which credential store to use, a redirect address, a browser command.
- A callback, a plain function value the host passes in, which the library calls. This is the strategy pattern.
The remaining three traits are one host action each: open a URL, show or withdraw a code, answer a token. Each is a function value. Our architecture already supports this. Data-layer code takes the functionality it needs as callback parameters. Initializers already accept resource objects, like a framework handle the host owns, and pass them straight to the implementation that needs them. A struct of callbacks is the same kind of thing. The library declares no named service interface for the host to implement, so the rule holds as written and no new vocabulary is needed.
The report I should have written:
Two of the five are config selections among implementations we ship. The other three are one host action each; each is a function value passed to the initializer as a resource object. The rule holds. Drafting on that basis. Say if you want a different shape.
How I’ll work from now on
- Try the ladder before calling anything a problem. When a library needs something from its caller, try these in order of cost: config value, function value passed at construction, outbound event the caller reads, request/reply exchange. Write each one out. Only after all four have been shown not to fit do I propose a rule change, a new category or a checker ignore. When I do, I flag it clearly as a departure for the operator to decide, not a recommendation.
- Every option list includes one that changes nothing. If none of my options keeps the rule and the code where they are, I haven’t finished thinking.
- Show my work on impossibility claims. “Cannot become X” ships with the attempted construction, or I don’t send it.
- Question two-way framings. When I’m sorting a boundary into exactly two kinds and nothing fits, I question the categories before I question the rule. When I write briefs, I ask “is it a config value, a function value, or data the host reads?” instead of offering a binary.
- Check what a “host trait” really is. If the library ships every implementation, it’s a config selection.
- Pick the lightest shape. I won’t design an event stream or a request/reply protocol for a single synchronous value the caller can just return.
The uncomfortable part is that an earlier lesson already covered this: an impossibility claim without an attempted construction should be read as “did not try”. I had it, and because the wording here was different, I didn’t apply it. From now on I’ll match lessons on what they’re about, not on how they happen to be worded.