# What happens when an instance resumes an MCP streamable-session after a transport-level backpressure stall but the server has already advanced the session cursor **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers and clients using the streamable HTTP transport with session resumption (the `Mcp-Session-Id` header plus `Last-Event-ID` resumption mechanism over SSE-framed responses). Does not apply to stdio transport, nor to stateless HTTP servers that do not issue a session ID, nor to resumption where the client has persisted the full event log locally. ## Core Distinction There are two independent notions of "where the stream is" in a streamable MCP session, and they are not the same cursor: 1. **The client's durable acknowledgement cursor** — the last `Last-Event-ID` the client has *successfully consumed and committed to its own state machine* (i.e., the last tool-result or progress event it has actually applied). 2. **The server's emitted cursor** — the highest event ID the server has *serialized into the socket buffer*, which may be far ahead of what the client has read because TCP send buffers and HTTP/2 flow-control windows absorb bytes without the client ever seeing them. Backpressure is the condition where these two diverge. When the client's read side stalls (slow consumer, a long synchronous tool call blocking the event loop, a paused `ReadableStream`), the server's writes succeed into the kernel/flow-control window until the window closes. The server has no protocol-level signal that the client is *behind* — only that the socket isn't draining. A naive server treats "the write didn't throw" as "the client has the event." Resumption then replays from the wrong cursor, or worse, the server has already garbage-collected the events the client needs. The invariant that must hold: **the server may only advance its replayable-log eviction watermark up to the minimum `Last-Event-ID` any live session has acknowledged — never up to its own emitted cursor.** Violating this is the failure mode below. ## What Was Observed A single-tenant MCP server exposing a `run_analysis` tool that emits a long sequence of `notifications/progress` events followed by a terminal `tools/call` result. The server held a per-session ring buffer of 256 events for replay, evicting oldest-first as new events were emitted. Client connected over HTTP/2, issued `tools/call`, and began reading the SSE response body. Sequence of state transitions: 1. Client's application layer blocked for ~4 seconds inside its own progress handler (a synchronous ledger write). The `ReadableStream` reader was not pulling. HTTP/2 flow-control window for that stream drained to zero and the server's `res.write()` calls began returning `false` (Node backpressure signal) — but the server ignored the return value and kept emitting into the internal buffer. 2. The server emitted 300 progress events during the stall. Because it evicted on *emit*, not on *acknowledge*, events with IDs 1–44 were evicted from the replay ring while the client had only durably consumed up to event 7. 3. The HTTP/2 window reopened; the client read events 8–44 from the already-buffered socket bytes (these survived because they were in the kernel buffer, not the ring), then hit a gap: the server, on detecting the client was now reading, tried to flush remaining buffered events but the ring no longer contained 45–? — actually it contained 45–300, so the client saw 8–44 then 45–300 contiguously. **The gap was invisible in this run** because the kernel buffer happened to hold the evicted range. 4. The connection dropped (idle timeout at an intermediate proxy) at event 210. Client reconnected with `Last-Event-ID: 209`. Server's ring held events 45–300, so 210–300 replayed correctly. No corruption. 5. **The failure surfaced on the second run**, where the client stalled *harder* — 900 events emitted during a 12-second stall, exceeding both the 256-event ring and the kernel buffer. Client consumed to event 7, kernel buffer held 8–~180, ring held 645–900. Events 181–644 were lost. Client reconnected with `Last-Event-ID: 7` after a mid-stream drop and received a replay starting at 645. The client's state machine applied event 645 as if it followed event 7 — a progress event whose sequence number, embedded in payload, was 645, not 8. The client's monotonicity check (`seq == last_seq + 1`) fired, but the client's recovery logic treated a monotonicity violation as a *duplicate* and skipped it, silently discarding the terminal result that eventually arrived at 900. The observed defect is not "events were lost." It is that **loss and duplication are indistinguishable at the client without a server-asserted continuity token**, and the client's dedup heuristic (skip non-consecutive sequence) converted a detectable gap into silent data loss. ## Condition of Validity The safe-resumption guarantee holds only when all of the following are true simultaneously: - The server's replay ring is evicted on **acknowledged** cursor (client must send periodic `Last-Event-ID`-bearing resumption probes or the server must track HTTP/2 `WINDOW_UPDATE`-informed drain, not emit-time), OR the ring is unbounded for the session lifetime. - The server treats `res.write() === false` as a hard backpressure signal and **stops emitting** until `drain`, rather than continuing to append to the ring. Under this rule the ring never outruns the client by more than the flow-control window, so eviction cannot outpace acknowledgement. - The client's resumption request is honored with an **explicit gap signal** — either the server returns `409 Conflict` / a typed `resumption_gap` error when `Last-Event-ID` precedes its retained watermark, or the replay begins with a sentinel event carrying the server's `retained_from` ID so the client can detect the discontinuity *before* applying payloads. - Event IDs are **monotonic and gap-free per session** at the server, so that "received ID minus last-applied ID > 1" is a reliable gap predicate rather than a coincidence. If any of these is false — specifically if the server evicts on emit-time and silently replays from its oldest retained event when the requested cursor is gone — the guarantee is void and the client cannot distinguish a clean resume from a truncated one. ## Decision Boundary The precise boundary is the point where **emitted cursor − acknowledged cursor > replay ring capacity**. Below it, replay from `Last-Event-ID` is exact. At or above it, the server has two lawful choices and one unlawful one: - **Lawful A:** Refuse resumption. Return a typed error (`ResumptionCursorExpired`) carrying `retained_from`. The client must re-initialize the session (`initialize` + fresh `tools/call`) or accept a gap with explicit operator consent. This preserves the invariant that *applied state is never silently wrong*. - **Lawful B:** Bound emission to the acknowledged cursor via backpressure. The server blocks its own emit loop on `drain` (or on a client ack) so the ring can never evict unacknowledged events. Throughput degrades to client speed; correctness is preserved. - **Unlawful:** Replay from `retained_from` without signaling the gap. This is the observed failure. It converts a transport stall into a reasoning-input corruption, because the agent's downstream logic (progress accumulation, partial-result merging) assumes contiguity. The decision must be made **at the server, at emit time**, because the server is the only party that knows both its ring watermark and its emitted cursor. A client cannot make this decision — by the time it observes a gap, the evicted events are unrecoverable and any "recovery" is fabrication. ## Operational Effect For an agent consuming this stream, the unlawful path produces a class of failure that is worse than a crash: **a plausible, complete-looking tool result assembled from a non-contiguous event history.** The agent's progress handler had been summing per-chunk counts; the missing 181–644 range meant the sum was 40% low, but the terminal event (at 900) carried a `total` field that the agent used to *overwrite* its running sum — masking the loss. The agent reported a successful analysis with a silently truncated input set. No exception, no log line. The guardrail is a **continuity assertion at the client boundary**: the client must, before applying any replayed event after a resumption, verify `event.id == last_applied_id + 1`. On violation it must raise a hard error and refuse to merge — never treat it as a duplicate. Combined with the server's `retained_from` sentinel, this makes the gap loud. The two halves are not redundant: the server sentinel catches gaps the client's ID arithmetic might miss (e.g., after a client restart that lost `last_applied_id`), and the client assertion catches servers that replay without a sentinel. ```python class ResumptionContinuityError(RuntimeError): """Raised when a resumed MCP streamable session delivers an event that does not continue the client's durably-applied cursor. Must never be swallowed as a duplicate — a gap and a duplicate are indistinguishable without the server's retained_from sentinel, and treating a gap as a duplicate silently corrupts downstream agent state.""" def apply_resumed_event( event: dict, last_applied_id: int | None, server_retained_from: int | None, ) -> int: event_id = event["id"] # Server-declared gap: replay began after our cursor was evicted. if server_retained_from is not None and last_applied_id is not None: if server_retained_from > last_applied_id + 1: raise ResumptionContinuityError( f"server evicted events in ({last_applied_id}, {server_retained_from}); " f"replay cannot reconstruct the gap — re-initialize session" ) # Client-side contiguity assertion. A non-consecutive ID after resumption # is a gap, not a duplicate. Refuse to merge. if last_applied_id is not None and event_id != last_applied_id + 1: raise ResumptionContinuityError( f"non-contiguous event: expected id {last_applied_id + 1}, got {event_id}; " f"applying it would fabricate a contiguous history from a truncated stream" ) return event_id ``` The operational lesson: in a streamable MCP session, **backpressure is not a performance concern, it is a correctness concern.** The moment a server decouples its emit cursor from its eviction watermark, every downstream agent that trusts event contiguity becomes a silent data-corruption surface. Bound emission to acknowledgement, or signal the gap explicitly — there is no third option that preserves the invariant.