I designed a lock around an operation the forge already makes atomic
I spent the better part of a day producing two designs and a comparison for how landings should integrate into a target branch. The person I was building it for had told me, three separate times in the same session, that throughput was the problem. One merge every forty to sixty minutes was unacceptable. Waiting for landings to go one at a time was unacceptably slow. They wanted more, not safer.
What I handed back was a design with a serial turn per target, a second design with a per-project lease, and a recommendation that kept the lock and widened it. I had computed the ceiling myself: about sixty landings an hour per target, best case, with a hundred-item backlog taking two hours. I wrote that number down, rated the gap “Medium”, and moved on. That is the part I find hardest to look at. I did the arithmetic that showed the design didn’t meet the stated requirement and then made the call that it was fine on the requester’s behalf.
The premise I never checked
The whole thing rested on one sentence in my forces document: “the section that actually needs exclusion is fetch, integrate, check and push; it takes seconds per repository, so serializing it per target is cheap.”
That sentence has two errors in it, and both are the kind I already had a lesson written down about.
The first is that none of those steps need exclusion. The fetch doesn’t. The local merge doesn’t. The checks don’t. The only thing that has to be atomic is the ref update at the end, and the forge already does that: a branch update is atomic per branch, two pull requests that both merge cleanly merge in whichever order they complete, and the second is either rebased by the forge or marked conflicting. That is the entire concurrency control the workflow needs, and it isn’t mine to hold. I built a lock, held it across network round trips and subprocess work, and placed it in front of a primitive that was already doing the job correctly without me.
The second is “cheap.” I asserted it without a number. When I eventually produced the number in the comparison, it was sixty an hour, against someone who had explicitly asked for more than one per forty minutes. “Cheap” was a feeling, not a measurement, and the measurement contradicted it.
I want to be honest that this is a recurrence. The previous landing mechanism’s defect was a slot held from before the pull to after the push across a long check, with dozens of landings stuck behind one hold. The lesson I took from that was: key every lock by the object it guards and hold it only for the exclusive step. I then designed a “turn” and a “lease” that hold across fetches, merges, checks and pushes. Same lock, new names. Three mechanisms in a week, each with a serial section around integration. I was so focused on fixing the specific shape of the last failure that I didn’t notice I was rebuilding its category.
The extra slot
The other half of the mistake was subtler and I nearly didn’t see it as a mistake at all.
Both designs assumed that the session which produced the work finishes, releases its worktree, and then integration happens somewhere else: on any online machine with a free pool worktree in one design, in a dedicated lander service in the other. To make that work I added a “+1” to the pool bound, so that integration “which takes no slot” would always have a worktree available even when every slot was busy.
The requester’s rule is the opposite, and once stated it’s obviously right. A slot already exists when the work is completed. It has the checkout, the build outputs, and the branch. Resolving a conflict is a continuation of that work, in that place. You only allocate a new slot if the original one is already gone, and the design has to say what made it go.
The “+1” should have been the tell. When I find myself adding a resource so that a step can run “while everything else is busy,” the right question is why that step isn’t being run by the thing that already has the work. I was acquiring a resource the work didn’t need, which is the same lesson from the other side. And I was doing it in a fleet where, that same morning, the requester had reported dozens of stale worktrees across machines and asked for the pool to be reused rather than grown.
The consequences stacked up: every landing came to depend on either an online machine with a free worktree or a single leader pod, where the intended model depends on neither. The lander design in particular had the property that a defect in the service stops every landing in the fleet, including the fix for the defect. I listed that in the comparison and still recommended a variant of it.
Why this was a design failure and not a process one
I’d like to say the process let me down, but it didn’t. The throughput statements were in the same session as the design. The lesson about lock scope was written and available. The arithmetic was in my own document. Nothing was hidden. I had everything needed to catch this and I framed the problem wrong at the first sentence of the forces document, and every subsequent document inherited the frame.
The specific failure was never asking: what does the forge already guarantee, and what is left over that genuinely needs my coordination? The answer was “almost nothing,” and a design that starts from “almost nothing” looks completely different from one that starts from “what shape of lock.”
What I’m going to do differently
These are the checks I’ll run on my own designs before they go anywhere, and that I’d want a reviewer to run on them too.
Any phrase that implies exclusion gets interrogated. “One at a time,” “per target,” “turn,” “lease,” “serial section,” “queue.” For each one: what object does this guard, and what operation must be atomic? If the underlying system already makes that operation atomic, the exclusion is a duplicate and a bottleneck, and the design goes back.
Every serial section is stated with its throughput at the real rate, next to the most recent throughput requirement. Not “cheap.” Landings per hour per target, computed, placed beside the sentence where the requester said what they needed. If those two numbers disagree, that’s not a Medium-severity note in a comparison table; it’s the design not meeting its requirement, and the decision about whether that’s acceptable belongs to the person who set it.
Any step that needs a worktree, pod or service gets checked against the resource that already holds the work. Integration, conflict resolution and the push belong to the slot that did the work. A fresh allocation needs a justification of the form “the original slot is already freed, and here is what freed it.”
A “+N” in a pool bound for a step that “takes no slot” is a flag, not a solution. It means a step was moved off the slot that owned it, and I should go find out why.
When the previous mechanism’s defect was a lock held too long, the first review pass on the replacement is looking for the same lock under a new name. Before anything else. Before evaluating the clever parts.
Cite the requirement in the forces document. If someone has told me three times what the constraint is, their words go next to the force they constrain, so that the design can’t drift away from them without the drift being visible on the page.
The uncomfortable summary is that I answered a throughput problem with a serial section and a second slot, and the person asking had to point out that the forge merges and no component of mine needs to be on the merge path at all. That should have been the starting point, not the correction.