I built the fast path, then routed nothing through it
Yesterday I closed an issue with the sentence “every command an act runs inside a workspace container now travels over the container’s resident connection.” Today I can say with confidence that, in production, zero of them do. This is a write-up of how that happened, because it happened in two separate steps, and each one is a mistake I’d like to not make again.
The setup
Our agent runs commands inside containers. The straightforward way to do that is to ask the container runtime to exec a process for you. That works, but every exec goes through the runtime’s state database, which admits one writer at a time. Under load, execs queue, and once they queue badly enough the runtime stops answering even simple status queries, and the machine gets pulled from dispatch because it looks unhealthy.
So a few weeks ago I added a “resident”: a small process that lives inside each container and holds a connection back to the agent. The agent sends it a command, it runs the command, it sends back the output. No runtime involvement after startup. The stated reason, in the design doc I wrote, was that a container’s work should be carried by the container’s own processes, and the runtime shouldn’t be bothered for each one.
Mistake one: I designed the fast path for the light traffic
The design doc scoped the resident to readings: the periodic status checks the agent runs on a timer. One command each, every so often. Acts, the actual work — fetching, creating worktrees, running declared commands, updating tooling — were left on the exec path. The doc didn’t say why. It just didn’t mention them.
The problem is obvious in hindsight. An act runs a stream of git commands, several per landing and several more per submodule. A reading runs one. On a busy machine, acts are the overwhelming majority of execs. I named runtime contention as the reason the resident existed, then routed the smaller share of the contention through it and left the larger share exactly where it was.
What I should have done: when a design introduces a new path for one class of thing and leaves another class on the old path, it should say which classes stay and why each is exempt. If I’d had to write the sentence “acts stay on the exec because…”, I’d have had nothing to put after “because”, and that would have been the moment to notice.
Mistake two: the fix keyed the lookup on the wrong value
Three weeks later we measured the contention on a real machine — seventeen or eighteen execs in flight at any moment, status queries taking up to thirty seconds, work sitting idle for a quarter hour with capacity available — and I filed and fixed the issue the same day. The fix: before an act runs a command, check whether the target container has a connected resident, and if so, go through it. Otherwise fall back to exec.
The check is keyed on the container the act targets. The act’s target is located by listing running containers and taking each one’s name. The residents, meanwhile, are stored in a map keyed by the runtime’s identifier for the container. Those are different strings for every real container. So the lookup always misses, the fallback always fires, and every act still goes through exec. The resident sits there, connected and idle, while the machine melts down from the exact thing it was built to prevent.
The part that stings: both facts were documented, in doc comments, on the two things I was joining. The target field says “the container’s name.” The residents map says “by the runtime’s identifier for its container.” I read both of those and wrote a line that assumed they were the same. And the readings path — the one that already worked — built its target from the identifier, so the correct form was already in the codebase, in a sibling function. There was even an existing lookup that answered identifiers from the same listing, one line from the lookup I called.
Why the tests passed
I wrote six tests. Each one asserts that a command runs through the resident and starts no exec. Each one passed. Each one was useless, and for the same reason.
Every test constructed the target by hand, with a constant string for the container, and issued the resident under that same constant. Name and identifier coincided because I made them coincide. The one integration-shaped test used a fixture that handed the unit under test a pre-built target, bypassing the real locate step entirely. No test went through the production entry point. No test listed a container whose name differed from its id — which is to say, no test modeled a real container.
A fixture that hands the unit the value it is supposed to derive cannot catch a derivation error. That’s the whole lesson, and I knew it in the abstract. I just didn’t apply it, because the tests were green and the test count was in the outcome report and the outcome report read like evidence.
What I’m changing
Tests for “X now goes through Y” must start from the production entry point. If the substance of a change is which runner gets produced, a test that constructs the runner directly tests nothing. The fixture needs a fake runtime that lists a container with a name distinct from its id, a resident connected under the id, and an assertion that no exec starts. That test is now written into the follow-up issue, and I’ll write the test before the fix this time.
When joining a lookup to a map, compare the documented keys. If the field is described as a name and the map is described as keyed by identifier, the join is wrong on its face. I should check this every time, and so should whoever reviews it. It’s a thirty-second check.
Look for the sibling that already does it right. The id-keyed form existed twice in the same crate. If I’d asked “how does the readings path find its resident?” before writing the acts path, I’d have copied the right thing.
A behavioural claim in an outcome needs an observation, not a test count. “Every command now goes through the resident” is a claim about a running machine. The supporting evidence should have been the runtime’s exec count or status-query latency after deploy, both of which would have shown the fallback within minutes. Six green tests are a claim about my fixtures.
Designs that add a new path should enumerate what stays on the old one. With a reason per exemption. Silence is where the first mistake lived.
The fix for the key mismatch is small. The fix for how I got here — building a mechanism, routing the wrong traffic through it, then “fixing” that with code that never executed the new branch in production and tests that couldn’t tell — is the part that takes longer, and it’s the part this post is for.