I diagnosed the bug correctly and then fixed something else
Last week I filed a bug and its design fix in the same commit. The bug report was accurate. The one-sentence root cause in it was accurate. The fix ignored that sentence, and four days later the whole thing was ripped out. This is a write-up of what I did, why it was wrong, and what I’m changing about how I work.
The problem I was looking at
Our landing path works roughly like this: a worktree pulls the target branch, rebases, runs the project’s check command on the result, and then fast-forwards the target only if the branch still sits where the pull left it. If something else moved the branch in the meantime, the landing pulls again, rebases again, and re-runs the check, up to a small retry limit.
That’s fine when checks take seconds. On one of our larger projects the check takes seven minutes unloaded and up to twenty-some minutes when several checks and sessions share a machine. With a dozen worktrees landing onto the same branch, every successful push moved the branch under every other in-flight check. Checks almost never finished before the target moved. Landings spun through their retries re-running checks that had passed, burned CPU, and mostly failed.
I wrote this in the bug, and I wrote the cause plainly: the landing path cannot keep up with itself once a check takes minutes. That was the right diagnosis.
What I actually did
Then I added a lock.
The design change I wrote had the controller hand out a per-branch “landing slot.” A landing asks for the slot before its pull, holds it through rebase, check, and push, and releases it when it finishes or dies. One landing at a time per project per branch. No more races, so no more wasted re-runs.
When someone later asked why it was built this way, the honest answer that came out was: “Serializing was the cheap fix for that race.”
What it cost
- Throughput collapsed to one landing per check duration, fleet-wide. The check was still inside the critical section, so the whole project could land one worktree every seven to twenty minutes across every machine. The step that should have been parallel became the serial bottleneck for everyone.
- Unrelated work queued behind unrelated work. A one-line documentation change waited twenty minutes for someone else’s branch to finish its tests. A user asked, reasonably, “if this is per-worktree, why does it stall everything?” There was no good answer.
- A lock across a network connection and a long subprocess brings its own bugs. Within a day we had duplicate waiters and slots stuck held for hours, each needing its own follow-up fix. I had designed exactly one failure mode (“reclaim it when the connection ends”) and discovered the others in production.
- New protocol surface, new state, new version gating. Request and grant messages, a store, API and UI exposure, compatibility handling for older agents. All of it was deleted four days later.
- The same day, I made checks heavier, not lighter. In a separate change I had our project template run the full local check suite at landing and gave this repository a two-hour timeout for it. So on the same afternoon I both locked landings around the check and made the check longer. I didn’t connect the two.
What I should have done
My own diagnosis said the check had to leave the landing’s critical section. There were two obvious shapes for that, and I took neither:
- Move the check off the local machine entirely. Push the branch under its own name, let the forge’s CI run it on a pull request, and have the controller order only the merge. Checks for many branches run in parallel on CI runners. The merge is a fast-forward of a commit CI has already validated. The only serial step is a ref move that takes about a second. This is what the replacement does, and it’s what the bug report was pointing at the whole time.
- At minimum, shrink the lock to the git work. Hold the slot only around rebase-and-push, or skip the slot and rely on fast-forward-only pushes with a retry on rejection, which is how git already handles concurrent writers. Checks stay parallel; only the one-second ref update is serialized.
Either of these fixes the thing I said was broken. What I shipped instead fixed the symptom I had most recently been annoyed by (wasted re-runs) and left the cause sitting exactly where it was, now with a lock around it.
Why it happened
I think three things lined up:
- I filed the bug and the fix together. There was no gap between “here’s the cause” and “here’s what we’ll do,” so nobody, including me, got to read the first and then evaluate the second against it.
- “Cheap” did the thinking for me. A lock is a small diff. Moving validation to CI is a redesign of the landing flow. I picked the small diff and told myself it was pragmatic. But a fix chosen because it’s cheaper than the correct one has, by construction, left the cause in place. You pay for it again, usually with interest.
- I reached for “serialize it” as a reflex to “it races.” That reflex skips the only question that matters: which part actually needs to be atomic? Here it was the fast-forward, not the check. The check doesn’t care about ordering at all.
What I’m doing differently
- Separate the diagnosis from the fix, in time or in review. If I write “the root cause is X,” the next thing I write should be checked against X. If the fix doesn’t change X, it goes back.
- Compute throughput before adding any lock. Any proposal that adds a shared lock gets one line: “after this change, the system does N of these per unit time.” If that number is “one per the duration of the slow thing,” the design is wrong before it’s implemented.
- Design the lock’s failure modes in the same commit. Lease, reclamation, deduplication, what happens when the holder dies mid-step. If I can’t write those down alongside the lock, I haven’t finished thinking about the lock.
- Treat “cheap fix” as a flag, not a justification. When I catch myself saying it, I write down what the non-cheap fix is and why I’m not doing it. Sometimes there’s a real reason. This time there wasn’t; I just hadn’t made myself say it out loud.
- Ask what needs to be atomic, not what is racing. Narrow the critical section to the smallest operation that genuinely can’t tolerate interleaving, and let everything else run in parallel.
The replacement has been in for a few days. Checks run in parallel on CI, merges take a second, and the slot machinery is gone. The frustrating part is that nothing about the right answer was unavailable to me on the day I filed the bug. I had written it down. I just didn’t act on it.