I Put Every Failure in One Bucket, and Got the Retry Decision Wrong Both Ways
This is a postmortem on a habit I had, not on one bug. The habit caused a whole group of bugs in the scheduler and worker code I wrote. Wherever my code called something external (git, the container runtime, a remote, an agent’s start command, a credential check), I handled the success case and then wrote one generic failure case. Everything that wasn’t success went to that one place.
The trouble is that those calls fail in many different ways, and each way needs a different response. A timeout, a lock someone else holds, a push rejected as non-fast-forward, a busy machine, an expired account and a message too large to encode all need different handling. Since they all hit the same branch, my code did the wrong thing for most of them. It either retried forever in the same spot, or it gave up for good on a fault that one more try would have cleared.
What I wrote
Failures I treated as “not started, try again here”
- Expired account. When the agent refused to start because the account behind it had lapsed, I reported it as a plain “not started.” The issue stayed eligible, no failed placement was recorded, and the scheduler kept sending it to the same machine. The issue was never held and nobody was asked to fix the account.
- Timeout while creating a worktree. I had written a rule that counts git refusals as failed placements. A timeout came back as a different answer, so it skipped that rule entirely, and the issue retried every few minutes indefinitely. No report or alert said what was going on.
- Refused start. After a start was refused, the code excluded that workspace from the next attempt, but the exclusion was used up before anything else had a chance to happen. In one case the scheduler sent the same issue to the same workspace more than a hundred times in ten minutes.
- Busy machine. “This machine is busy” is about the machine, but I handled it as if it were about the issue. That produced nearly two thousand warnings in a day, almost all “start refused, machine busy.” Meanwhile the fleet-level scheduler, which should have stopped sending work to that machine, reported that no machines were being withheld.
Failures I treated as “stop and hold”
- Git index lock. If another git process held the lock, I counted it as a failed placement, which moved the issue toward being held. A lock held by someone else is a short wait, not a problem with the issue.
- Non-fast-forward push. If someone else pushed to the branch first, my code held the issue. The branch was fine and the operator had nothing to do. With several machines landing changes into one project, this race is expected and happens all the time.
- Two fetches at once. If two fetches ran at the same moment, the landing stopped and the failure counted toward withholding the machine, even though fetching again would have worked.
- Container runtime deadline. When a loaded machine missed the container runtime’s deadline, filing a task failed permanently. A landing that stopped the same way would have been retried after the next pull and held only on its second failure. The same fault got two different policies.
- Missing git identity. A rebase that stopped because git had no user identity configured was classified as a merge conflict. That filed a conflict issue, the session sent to resolve it found nothing to resolve and closed it, and the next landing failed the same way. Round and round.
Permanent failures I treated as temporary
- Oversized frame. A frame over the size limit was handled as if the socket had failed, so the code reconnected and sent it again. The new connection failed on the same frame as soon as it opened. The result was a reconnect loop that kept raising “offline” alerts.
- Pending mark cleared too early. The cleanup after a session cleared the “pending” mark no matter what the landing returned. The failures the design said to retry were never retried, because the code had already forgotten them.
What it cost
- Retry loops that used up agent sessions and worktrees
- Issues held for faults that weren’t theirs
- Conflict issues filed for situations no session could fix
- Machines withheld because of an ordinary race
- A reconnect loop that kept raising offline alerts
None of this was caught by tests or by the code reporting on itself. The operator found every case, by noticing a warning count, a held list or an alert that looked wrong. That is the worst part for me. The code was not only wrong, it also failed to say that it was wrong.
What I should have written
For every external call, both the design and the code should list every answer the call can give. For each answer, they should state three things:
- Temporary or permanent? If temporary: where to retry (same place or somewhere else), how many times, and with what back-off. If permanent: stop, and say what fixes it.
- What is at fault? The issue, the machine, the account, the branch or the environment. This decides what gets held, withheld or flagged. Getting it wrong is how a busy machine turned into a problem with an issue.
- What gets reported, and to whom?
In practice that looks something like this:
| Answer | Temporary? | At fault | Response |
|---|---|---|---|
| Lock held | Yes | Nobody (contention) | Retry here with back-off |
| Non-fast-forward / ref moved | Yes | Nobody (race) | Fetch, rebase, retry |
| Concurrent fetch | Yes | Nobody (race) | Retry here |
| Deadline on a loaded machine | Yes, bounded | Machine | Retry with back-off, then try elsewhere |
| Machine busy | Yes | Machine | Withhold the machine, place the issue elsewhere |
| Account unavailable | No | Account | Stop and report to the operator |
| Git identity missing | No | Environment | Stop and report. Not a conflict. |
| Frame over limit | No | Message | Drop or split it, report. Do not reconnect. |
| Real merge conflict | No | Branch | File a conflict issue |
| Anything else | Unknown | Unknown | Report and stop |
The list has to include the runner’s own failures too, like hitting its deadline or losing the resident process, not just the answers from the tool it calls. For git in particular, “conflict” is only one of many ways a command can fail. Lock held, missing identity, non-fast-forward, moved ref and unreachable remote all need their own rows.
The last row matters most. A catch-all branch should mean “unknown: report and stop.” It should never reuse the handling for the most common failure. Nearly all of the bugs above came from an unknown answer quietly taking over the handling meant for a known one.
What I’m changing
- I won’t merge code that handles an external call’s result unless the answers are written down, with the three points for each, before I write the
match. - I’ll write one test per row: simulate that answer and check the retry behavior, the attribution and the report.
- When a fault can show up in more than one place (for example, a deadline during filing and during landing), I’ll give it one policy in one place, not a separate improvised one at each call site.
For reviewers
Look for every match or if let Err on the result of an external call. If one branch handles more than one named answer, or a catch-all leads to a specific fix (conflict, failed placement, retry here), ask to see the list of answers from the design and a test for each one. If neither exists, the code isn’t ready, and that includes mine.