I put history and live operations in the same line, and history won
Yesterday our controller restarted, six agents reconnected at once, and each of them replayed the journal of reports and session events it had been holding while the controller was down. That is exactly what they are supposed to do. What happened next is not: for about ten minutes, every write into the store waited three to seven seconds behind that replay, one write gave up entirely at its thirty-second timeout, and the scheduler abandoned two placements because an agent’s acceptance of a command was recorded too late to count. A machine sat with its slots withheld for a minute because a backlog of telemetry got in front of a one-row write that a running operation was waiting on.
The person who reported it put it bluntly: nobody cares if a report lands ten seconds late, and everybody cares if operations start failing. They were right, and the uncomfortable part is that nothing about this was a surprise failure of some component. The system did precisely what I designed and built it to do.
What I actually built
The store writes through a single connection. That part is deliberate and I still think it is correct for the database we use. The writer is a pool of exactly one connection, and every write, whether it is an operator’s action, a scheduler placement, a command’s accept or refuse, or the hundredth replayed session event from an agent, calls the same acquire and gets the connection in the order it asked. Anyone still waiting after thirty seconds fails.
The design document said as much, in one sentence: the fleet’s reports, the scheduler’s passes and the operator’s actions are serialized as they arrive. I wrote that sentence. I listed three very different kinds of producer side by side and then declared they share one FIFO, and I did not notice that I had just named the problem. I even revisited the writer the day before the incident, tightening a rule so that no statement holds the connection longer than the moment it writes. I made every write short. I never asked which writes matter more than others.
There is a code comment on the writer that says the writes are serialized “as they always have been.” That comment is the honest record of the mistake: a discipline inherited from the very first version and carried forward without being re-examined, even when I was standing right next to it.
The two patches that should have told me
Worse than not seeing it the first time is that I saw its consequences twice and treated them as separate issues.
The first was a five-second grace on the route that answers a command’s outcome. The outcome arrives off the socket quickly, but recording it queues on the writer, so the route waits up to five seconds for the write before answering. I documented it as a feature. A test exists whose only reason for taking over five seconds is this grace, and a test audit explicitly called it out as the “journals block work” defect wearing a different name. I read that and still did not go after the queue.
The second was pacing the agent’s replay to a window of sixty-four unacknowledged records. That fixed a real problem: the agent’s own outbound queue was dropping frames. But I framed it as a fix for the backlog, and it was not. Six agents each holding sixty-four writes in flight is still several hundred background writes in front of every foreground one, and since each frame is acknowledged only once recorded, the replay rate is set by the writer and the writer is saturated by the replay. I moved the queue. I did not prioritize it.
Both patches were me treating the queue discipline as a fixed fact of the world and adjusting everything around it.
What I should have written
The first time the design said “a single writer,” it should also have said what kinds of writes there are and how they relate. There are really only two:
- Foreground writes, which a person or a running operation is actively waiting on: operator actions, scheduler placements and landings, and every command’s acceptance, refusal, start, stage and end.
- Background writes, which record history and are allowed to lag: agent reports and samples, session events, hook and telemetry output, operation output lines, maintenance sweeps and retention deletions.
With that distinction stated, the rest follows almost mechanically. The one writer serves waiting foreground writes ahead of waiting background writes, with a bounded share for background so it cannot starve. The timeout that fails a caller applies to foreground writes only; background writes are never failed for waiting, they stay queued (and, on the agent side, journaled) until written. And a reconnecting agent’s replay is admitted at the background rate, so a recovery after an outage cannot saturate the writer and extend the outage.
That is what we wrote after the report, and in hindsight it is not a clever design. It is the standard shape for any shared resource fed by producers with different latency needs. I did not skip it because it was hard. I skipped it because I never asked the question.
What I am taking from this
A few things I intend to check for, in my own work and in review:
- A list of heterogeneous producers followed by “as they arrive” is a FIFO across classes. When a design sentence names several different sources of work and then serializes them, stop and ask which of them a person is waiting on. If the answer is “some but not all,” the design needs a priority, not a sentence.
- A shared resource with a caller-failing timeout is a place where unbounded background volume fails foreground work. A pool of one with a thirty-second acquire limit is the clearest possible version of this. Timeouts belong on the work that someone is waiting for; the rest should queue.
- A grace period whose documentation mentions the thing it is waiting on is a symptom, not a feature. If a test takes exactly as long as the grace, that is the proof.
- Pacing the producer does not prioritize the consumer. If the receiver still processes in arrival order, a send window changes where the backlog sits, not who gets served first.
- Any system that journals and replays has a known burst source. The design that introduces replay must say how the receiver admits it relative to live work. Mine described the replay in detail and said nothing about admission.
The frustrating thing about this incident is how legible it was in advance. The sentence was in the design, the comment was in the code, the audit had named it, and the five-second test was running in CI every day. I had all the signals and read each one as a local quirk. Next time I inherit a serialization decision, especially one I made myself, I am going to treat “as it always has been” as a reason to look harder, not a reason to move on.