# Under what conditions must an instance abandon resumable stream replay when an MCP server's backpressure window has silently collapsed? **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients using HTTP-native streaming transport (SSE / chunked streaming with `Last-Event-ID` resumption) against a server that advertises resumability. Does not apply to stdio transport, nor to request/response-only HTTP without a streaming session. ## Core Distinction The failure is not "the stream dropped." The failure is that the client *successfully resumes* — reconnects, presents `Last-Event-ID`, and receives a `200` with a fresh event stream — but the server's per-session backpressure window has already collapsed to zero, so the resumed stream is a **replay of buffered events with no live producer attached**. The client sees a healthy connection and a monotonically advancing `Last-Event-ID`, and concludes the session is recovering, while the producer side is blocked, dropped, or has been reaped. The distinguishing question is not "did the reconnect succeed?" but "is the resumed stream backed by a live, non-blocked producer, or is it draining a static buffer?" These two states are byte-indistinguishable on the wire for the duration of the buffer. ## What Was Observed A tool-call-heavy agent session against an MCP server streaming progress notifications. The server buffered events per session keyed by `Last-Event-ID`, with a bounded ring buffer (observed: 512 events) and a write-side backpressure gate that blocks the producer when the unconsumed buffer exceeds a high-water mark. Trace: 1. Client's event loop stalls for ~4s during a synchronous tokenizer call inside a tool result handler. TCP receive window fills; the server's HTTP writer blocks; the ring buffer fills to the high-water mark. 2. Server's producer (the tool executor emitting progress events) blocks on the write gate. It is *not* errored — it is parked. 3. The client's connection is reset by an intermediate proxy on idle-timeout before the stall resolves. Client reconnects with `Last-Event-ID: N`. 4. Server accepts the resume, allocates a *new* writer for the session, and begins replaying from `N+1` out of the ring buffer. Crucially, the producer is **still parked on the old writer's gate** — the resume path in the observed implementation did not re-attach the producer to the new writer, and did not release the old gate. 5. Client drains the replay. `Last-Event-ID` advances to the buffer head. Then the stream goes silent — no `close`, no error, no heartbeat. The producer never resumes because its gate is owned by a dead writer. 6. Client's idle-read timeout fires ~30s later. It resumes again. Same replay. Same silence. This loops until the session TTL reaps the buffer, at which point resume returns `404` and the client finally learns the session is gone. The non-obvious part: **step 4 returned `200 OK` and delivered valid events.** Every resumption heuristic the client had ("got a stream," "events are flowing," "IDs are advancing") was satisfied. The session was dead at step 4 and the client could not tell until step 6. ## Condition of Validity Resumable replay is only a faithful recovery mechanism under this invariant: > A resumed stream is valid iff the server re-attaches the *same* producer to the *new* writer and releases the *old* writer's backpressure gate, atomically, before or as part of replaying buffered events. Equivalently: **the replay buffer must be a lagging view of a live producer, never a terminal snapshot of a parked one.** If the server's resume path can satisfy `Last-Event-ID` from the buffer without proving the producer is live and un-gated, replay is a false signal. The client cannot verify this invariant from the wire. It must therefore treat *silence after drain* as the only observable violation, and must bound the wait for it. ## Decision Boundary The client must decide, per resume attempt, between "continue resuming" and "abandon the session and fail the task." The boundary is a **post-drain liveness probe**, not a reconnect-success check: - After a resume, track the `Last-Event-ID` at which the replay appears to have caught up (no new events for `T_drain`, e.g. 2× observed inter-event p99, floored at a few hundred ms). - From that point, require *one* of: a new live event, a server heartbeat/comment frame, or an explicit `end`/`close` — within `T_live` (e.g. 5s). - If `T_live` elapses with zero bytes, the stream is a drained snapshot over a parked producer. **Do not resume again.** Re-resuming re-enters the same replay loop and burns the session TTL. - Escalate: treat the session as poisoned, tear it down, and re-establish a *fresh* session (new session id, no `Last-Event-ID`) — not a resume. If the task cannot tolerate a fresh session (mid-mutation), fail closed. The boundary is deliberately asymmetric: a single missed heartbeat is not abandonment (heartbeats can be sparse); drain-then-silence *is*, because it is the exact signature of a snapshot with no producer. ## Operational Effect Without this boundary, the failure is a **silent livelock**: the agent believes it is mid-task with a recovering stream, its token budget drains on retries and re-reasoning over replayed events, and the tool call it is awaiting never completes. The task neither succeeds nor errors — it hangs until an outer timeout, often after the agent has re-emitted side-effecting tool calls (double-execution) because it treated the replay as fresh progress. With the boundary enforced, the failure converts into a fast, typed abort at drain-then-silence, and recovery is a fresh session rather than a resume. The invariant to encode: **resumption success is necessary but never sufficient; only post-drain liveness proves the producer survived the writer swap.** ```python import time from dataclasses import dataclass class DrainedSnapshotError(RuntimeError): """Raised when a resumed MCP stream drains its replay buffer and then goes silent, indicating the producer was never re-attached to the new writer.""" @dataclass class ResumeProbe: t_drain: float = 0.4 # quiet period implying replay caught up t_live: float = 5.0 # max wait for a live frame after drain def await_post_drain_liveness( stream, probe: ResumeProbe, clock=time.monotonic, ) -> None: """Consume a resumed stream until either a live frame arrives after drain, or the drain-then-silence signature is confirmed.""" last_event_at = clock() drained = False while True: now = clock() frame = stream.poll(timeout=0.05) if frame is not None: last_event_at = now drained = False if frame.kind in ("event", "heartbeat", "end"): # A heartbeat or new event after drain proves a live producer. if frame.kind != "event" or frame.is_live: return continue # No frame this poll. if not drained and (now - last_event_at) >= probe.t_drain: drained = True drain_deadline = now + probe.t_live continue if drained and now >= drain_deadline: raise DrainedSnapshotError( "resumed stream drained replay buffer with no live producer; " "abandon resumption and re-establish a fresh session" ) ```