I classed live session events as "nobody is waiting on this." Somebody was.
Earlier this week an operator ran a handful of sessions from the interface and watched the page stay empty. Two of the sessions finished before their first prompt showed up. The operator, reasonably assuming something had hung, stopped one and started the same prompt again a few seconds later. Nothing was hung. The transcript was arriving 20 to 25 minutes after it was written, and on the rest of the fleet nothing newer than roughly 40 minutes old had been recorded at all.
I designed the change that caused this, two days before it bit. This is what I got wrong and what I’m changing.
The design
The controller had a problem with contention on its store under load, so I introduced a priority scheme for writes. Every write was classed as either foreground (“one someone is waiting on”: operator actions, placements, command outcomes, server requests) or background (“one no one waits on”: agent reports, telemetry, output lines, retention sweeps). Foreground runs ahead of background, background gets a bounded share of each second, and a background write is never failed for waiting; it just queues until it’s written.
That part is fine. The mistake is one entry in the background list: session events.
I put them there because, from the controller’s point of view, no request blocks on a session event. The agent sends it, the controller records it, the controller acknowledges it. Nothing upstream is waiting for a response. By the definition I wrote, it’s background.
But the definition I wrote was wrong, or rather, I applied it to the wrong actor. The question is not whether a request is waiting. It’s whether a person is. An operator with a session page open is waiting on every single event in that session. They’re reading it as it happens. They’re typing into it. I filed the transcript of the thing the operator is actively watching under “no one waits on this.”
How it compounded
Three details made it worse than a simple misclassification:
- The interface stream was published after the write. The controller records the event, then publishes it to the channel the interface subscribes to. So the interface didn’t just see events in background order; it saw them only after the full background queue had drained ahead of them.
- The agent’s send window was gated on the acknowledgement. The agent sends a window of events and waits for the controller to acknowledge before sending more. Since the acknowledgement came after the write, the agent’s outbound side stalled behind the same queue.
- A later addition inherited the class without re-examining it. When I added a read-ahead hold to tell overloaded connections to keep their background frames in their local journal, running-session events were held back too, because they were “background.” Frames sitting in agent journals weren’t counted in the controller’s queue metric, so the controller’s own log said the oldest wait was about 500 seconds when the real lag was about 1400. The one number I would have looked at understated the problem by more than half.
And the design doc said this would happen. I wrote: “a report may be recorded seconds late under load” and “background work lags without ever stopping.” No bound. No list of which interface surfaces read background data live. Two sentences earlier in the same document, a paragraph I hadn’t touched still said the interface draws a session from its events “as they arrive.” I added a paragraph that contradicted it and didn’t notice.
The bitter irony is that over the preceding days I had carefully moved every other interactive path onto a latency-first shape: the command lane reads regardless of queue depth, a session’s requests don’t wait on reports ahead of them, terminals bypass the controller entirely. The one interactive surface I left on the slow path was the transcript, the surface the operator reads while typing to it.
There was also a lag indicator in the design, meant precisely to distinguish “this session is quiet” from “this stream is behind.” It was marked done. It wasn’t in the deployed API. So the page read as a working session with no events, which is exactly the ambiguity the indicator was meant to remove.
What I should have done
“Session events” is not one kind of write. A live event from a running session that someone may be watching is read by a person as it happens. A replayed event from an ended session’s journal is not. These need different classes. I collapsed them because they share a frame type, and a frame type is not a latency requirement.
Stream before you write. For a live event, the controller should publish to the interface as soon as it reads the frame, before the store write. What the operator sees should trail the agent by network latency alone. The stream cursor can be the event’s id so a page loaded after a reload dedups against what was already streamed. Durability and display are different concerns; I serialized them for no reason.
Live events get their own lane on the agent too. The same way the command lane isn’t held back by the read-ahead hold, live session events shouldn’t be either. An event is live if its session is running and the event is younger than a stall bound; otherwise it’s background. That rule belongs in the design, not in someone’s head.
State the latency budget per surface. If the design had said “a session page is held to low-hundreds of milliseconds under load,” then “seconds, unbounded” would have been a visible violation at review time rather than a sentence that read as acceptable. “Seconds late under load” sounded fine for telemetry. It is not fine for a transcript, and the doc should have made that distinction impossible to miss.
Ship the lag indicator, and alert on it. The stream being behind must be reported as behind, on the page the operator is looking at, and it must alert past the stall bound. A queue depth metric on the controller is not a substitute, especially when, as here, it doesn’t count frames that haven’t reached the controller yet.
Where review could have caught it
- A check that every item on the background list genuinely has no one waiting on it would have failed on the first interactive surface in the list.
- Tracing the interface’s subscribe path backward from the publish call to the write class would have shown the stream waiting on the queue.
- Reading the two sentences of the “Events” section together, old and new, would have shown they contradict each other.
- When I added the read-ahead hold, asking “is everything currently classed background actually safe to hold on the agent?” would have surfaced it a second time.
None of these are exotic. They’re the kind of thing I’d have done if I’d been thinking about the operator at the keyboard rather than the controller’s request graph. I was optimizing the thing I could measure and forgot that the measurement didn’t include the person.
The fix is in progress: a third write class for running-session events, hook reports, and question-server requests, served between foreground and background with a stated share; publish-before-write for live events; a live lane on the agent; a latency budget in the design; and the lag indicator actually deployed and wired to an alert. I’ll write a follow-up once it’s in and measured against the budget rather than against my assumptions.