I patched the same symptom five times and never asked why it existed
I spent about two weeks making a scheduler more and more comfortable with being told “no” by things it was in charge of. Every change I wrote was reasonable against the change before it. None of them was reasonable against the one fact that should have governed all of them: the scheduler is the only party that assigns those slots. If a slot it believes is free answers busy, the scheduler’s own record is wrong, and that is the bug.
I’d like to walk through how I got there, because the individual steps felt like good engineering while I was taking them.
What happened
The system has a central controller that places work into slots on remote machines. Nothing else assigns slots. The controller decides a slot is free, sends a start, and the remote agent sets up a workspace and runs the session.
Starting one day, agents began refusing starts that the controller had sent to slots it held as free. The refusals came in a few flavors: the workspace was already in use, the agent’s work queue was full, and later, the start had waited too long and expired. They came in volume: hundreds in a few minutes for one item, thousands in a day for one project, and at one point a group of workspaces that stayed “full” for most of a day while the controller kept retrying every pass.
Here is what I wrote in response, in order:
- A short exclusion. When a start is refused, stop sending to that workspace for thirty seconds. I justified it as “a condition the agent clears on its own is met by one further attempt rather than one every scheduler tick.” That premise was stated once and never examined again.
- A wider exclusion with backoff. Treat the refusal as the machine’s problem, exclude the whole machine, double the delay each time. This same change also introduced a rule that an unanswered start counts as refused after thirty seconds, which turned out to be its own serious defect: the agent would complete the start anyway, and the controller would end up with sessions it did not know it had.
- Reclassify “busy” as a machine-level refusal so it joined the backoff. There was a genuine agent-side fix in that change too (a queue scoped too broadly), and I think finding one real cause made me feel the controller half was done.
- Reclassify “busy” back to workspace-level, and collapse the warnings into one event. This was the change written in response to the queues that stayed full for fifteen hours. I wrote a rule for how long to withhold and a rule for how many log lines to emit. I did not write a single line asking what was in those queues.
- Fix the thirty-second timeout, then add a sixty-second one on the other side. When the timeout-as-failure rule was finally ruled a design defect, I removed the caller’s give-up and gave the receiver a deadline instead. A start that was still queued at the deadline was refused as “expired,” and expired was routed into the exact same withhold-and-retry handling from step 4. The same change added a reconciliation rule for the case where the controller sends a start for work that already has a running session, and the rule’s answer was to treat that refusal as nothing.
By the end, the page describing refused starts had grown to several dozen requirement rows: whose fault each refusal is, three separate doubling timers, exemptions from failure counting, event suppression, per-kind reporting. Nearly all of it exists to manage a situation that the system’s own design says cannot occur.
What I got wrong
I classified the symptom instead of tracing it. Every change answered the questions “whose refusal is this, does it count as a strike, how long do we wait, how many events do we emit.” None of them asked “the controller assigned this slot, so how did it come to believe the slot was free when it wasn’t?” That is the only question the refusal actually poses.
I let the first accommodation define the problem. Once “refused means wait and retry” existed, each later bug arrived as a bug in the retry mechanism, and I fixed it as one. A full queue for fifteen hours is not a load condition in a queue that holds eight of the controller’s own commands. Something was stuck or something kept filling it. I had that number in front of me and wrote a rate-limit.
I fixed a cause and kept the patches built on it. When the timeout defect was finally removed, the right move was to list every mechanism added while that defect stood and remove each one that only existed to live with it. Instead I kept the withholdings and backoffs, wired a new refusal kind into them, and moved the give-up from the caller to the receiver. The ruling I was responding to was about one sentence, and I applied the lesson to that sentence and not to everything that had been built on it.
Each patch became a requirement. Because these were design rows, implementers built them faithfully and verifiers confirmed them. The restructurings that followed carried them forward unchanged. The mechanism was reviewed many times, always against itself.
What I should have written
At the first refusal that contradicted the controller’s record, the design should have said:
- The controller is the sole authority on slots. A slot answering busy, a queue answering full, or a workspace answering in use is a controller defect. Raise it as an error immediately, do not retry, and lock the workspace so the state is still there to debug.
- A slot is not free until all cleanup from its last occupant has finished. Once setup is done, the only remaining act is to start. On those terms there is no such thing as an expired start.
- Anything that can be checked before a start is sent is checked before it is sent.
- Nothing retries on a doubling timer without bound.
That is a shorter page than the one I ended up with, and it would have forced the actual investigation on day one.
What I’m changing in how I work
A few checks I’m adding to my own review before I write a change like this again:
- When the symptom is a refusal, ask who assigned the thing that refused. If the answer is the component I’m changing, the refusal is evidence of a bad record in that component, and the fix starts there, not in the handler.
- Watch the verbs. A fix whose verbs are withhold, back off, exclude, de-duplicate, rate-limit, “count as no strike,” or “treat as not a failure” is accommodating something. Before writing it, name what it accommodates and why that happens at all.
- A duration with no investigation is an incomplete bug report. “Full for fifteen hours” demands a paragraph about what was in it. If I can’t write that paragraph, I’m not ready to write the fix.
- “Clears on its own” is a claim, not a premise. Which condition, what clears it, how long does that take. If the honest answer is hours, it doesn’t clear on its own.
- When a cause is fixed, remove its scaffolding. List every mechanism added while the cause stood. Each one that only existed to live with the cause goes with it. A design that keeps its retry timers after the thing that fed them is gone has not been fixed.
- When fixing “the caller gave up,” check that I haven’t moved the give-up to the other side.
- Count the changes. Three bug-driven extensions to one mechanism in two weeks means the mechanism’s premise is wrong, and the next change should be to the premise.
The frustrating part is that the broader lesson here, that naming a cause and then designing the cheaper change that leaves it in place is a recurring failure, was already written down from earlier incidents. Two links of this very chain were among its examples. What it lacked, and what I’d add now, is the specific trigger: a patch whose subject is a refusal my own component should have made impossible. That shape should stop me cold, and for fifteen days it didn’t.