# What structural signals indicate session resumption failure in MCP HTTP-native streaming under SSE backpressure **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers exposing streamable HTTP transport with `Last-Event-ID`-based resumption (the 2025-03-26 spec's SSE fallback and later revisions), where a client reconnects mid-stream after a dropped connection. Does not apply to stdio transport, nor to servers that emit a single terminal response without a resumable event log. ## Core Distinction A resumable SSE stream is not a durable queue. The `Last-Event-ID` header tells the server *where the client stopped reading*, but it says nothing about *what the client actually processed*. Under backpressure these two diverge silently, and the divergence is the failure. The server's event log is an append-only sequence bounded by a retention window; the client's read position is a cursor that advances on socket flush, not on application acknowledgement. When the transport stalls—because the client's read loop is blocked on a slow tool handler, or the TCP receive window fills because the consumer is a synchronous JSON-RPC dispatcher—the server keeps appending. On reconnect the client sends the last ID it *received into its buffer*, which may be dozens of events behind the last ID it *handled*. The server replays from the buffer cursor, and the gap between buffer and handler is never re-delivered. The structural signal that distinguishes this from a clean resume is that the replayed event sequence is contiguous from the client's declared ID but the client's internal state machine has already advanced past events that were never re-sent. ## What Was Observed A tool-calling agent connected to an MCP server that streamed `notifications/progress` and interleaved `sampling/createMessage` requests over a single SSE channel. The agent's read loop fed events into a bounded `asyncio.Queue(maxsize=64)` drained by a single consumer coroutine that awaited each downstream tool call before pulling the next event. A batch of 200 progress events arrived in a burst while the consumer was blocked ~4s on a `fetch` tool call. The kernel socket buffer absorbed the burst; the server's `sse-starlette` writer never observed backpressure and never applied its per-connection queue limit, so nothing was dropped *server-side*. The client's `asyncio.Queue` hit `maxsize` and the read loop blocked on `put()`. TCP receive window then filled, the server's write blocked, and eventually the connection was torn down by an intermediate proxy's 30s idle timer. On reconnect the client sent `Last-Event-ID: 1187`—the ID of the last event it had *dequeued*, not the last it had *received*. Events 1188–1203 had been sitting in the socket buffer and were discarded by the kernel on close. The server, seeing `1187`, replayed from 1188. The client's consumer had, in the meantime, already executed side effects corresponding to events 1195–1203 (because the read loop had pulled them into the queue before blocking). Replay re-executed 1188–1194 and *re-delivered* 1195–1203, producing duplicate tool invocations and a corrupted progress counter that reported 312% completion. The non-obvious signal: **the replayed stream was internally consistent**—monotonic IDs, no gaps, valid JSON-RPC framing. Nothing at the transport layer flagged the failure. The only observable tell was a downstream invariant violation (progress > 100%, duplicate `idempotency_key` on tool calls) that surfaced two hops away from the transport. ## Condition of Validity The failure requires all of the following to co-occur: 1. The client uses a **bounded internal buffer** between the SSE read loop and the event consumer, and the read loop blocks on `put()` rather than dropping or applying flow control. 2. The client's `Last-Event-ID` is derived from **dequeue position**, not from an explicit application-level acknowledgement. Most SDKs derive it from "last event parsed," which is the read loop, not the handler. 3. The server retains events **past the client's buffer horizon**—i.e., retention window > buffer depth. If retention is shorter, the server returns `404`/`410` on resume and the client is forced into a full re-initialization, which is *safe* (state is rebuilt) rather than *silently divergent*. 4. The events carry **non-idempotent side effects** (tool calls, sampling requests, state mutations) rather than pure telemetry. Remove any one and the failure collapses into either a clean error or a benign duplicate. The dangerous regime is precisely where all four hold: bounded buffer, dequeue-based cursor, generous retention, side-effecting events. This is also the *default* configuration of most MCP client libraries, which is why the failure is common and under-diagnosed. ## Decision Boundary The architectural invariant required to bound this is: **the resumption cursor must be a function of handler completion, not of transport receipt.** Concretely, the client must not advance `Last-Event-ID` past an event until the consumer has returned from processing it. This forces a monotonic, gap-free acknowledgement discipline: - Maintain a single `acked_id` counter, advanced only after the handler for event `N` returns successfully (or is recorded as failed-and-terminal). - On reconnect, send `Last-Event-ID: acked_id`, never the read-loop position. - On replay, **deduplicate by event ID before dispatch**: any event with `id <= acked_id` is discarded at the read loop, never enqueued. This handles the case where the server replays further back than requested (some implementations replay from the last retained event on `404`). - Bound the server's retention window to be *shorter* than the client's worst-case handler stall, so that a stall longer than retention forces a `410 Gone` and a clean re-init rather than a silent gap. The trade-off is explicit: this discipline converts a *silent divergence* into a *loud re-initialization* when the client stalls beyond retention. That is the correct direction of failure. The alternative—unbounded retention with dequeue-based cursors—trades a visible reset for an invisible state corruption, which is strictly worse for any agent whose tool calls are non-idempotent. A second boundary: SSE backpressure must be handled at the **application layer**, not left to TCP. The server should apply a per-connection send queue with a hard limit and, on overflow, emit a terminal `event: error` with a resumption hint rather than blocking the writer. Blocking the writer is what converts a slow consumer into a proxy timeout, which is what triggers the reconnect in the first place. ## Operational Effect In production this manifests as three recurring symptoms, none of which point at the transport: - **Duplicate tool invocations** with matching `idempotency_key`, usually clustered after a network blip, with the second invocation arriving within the retention window of the first. - **Monotonic counters that exceed their terminal value** (progress > 100%, sequence numbers that skip backward then forward). - **Sampling requests answered twice**, where the second answer overwrites the first in the agent's semantic memory, producing a state that is internally inconsistent with the transcript. The diagnostic is to log `(received_id, dequeued_id, acked_id)` as a triple at every event boundary. A healthy stream has all three equal modulo in-flight depth ≤ buffer size. A failing stream shows `received_id - acked_id` growing without bound during stalls and *not* resetting to zero on reconnect—the gap persists because replay only covers `[acked_id, received_id]` if the client is disciplined, and covers nothing if it is not. The guardrail is a startup assertion: on every session resume, the client must verify that `replayed_first_id == acked_id + 1` and that no enqueued event has `id <= acked_id`. Violation is a hard error, not a warning, because continuing means dispatching events whose side effects may already have occurred. ```python class ResumptionDivergenceError(RuntimeError): """Raised when SSE replay is not contiguous with the handler-acknowledged cursor.""" pass class ResumableSSEConsumer: def __init__(self, retention_window: int, buffer_depth: int): self.acked_id: int = 0 # advanced only after handler returns self.enqueued_ids: set[int] = set() self.retention_window = retention_window self.buffer_depth = buffer_depth def on_reconnect(self, last_event_id_header: int, first_replayed_id: int) -> None: # The client MUST send acked_id, not the read-loop position. if last_event_id_header != self.acked_id: raise ResumptionDivergenceError( f"client sent Last-Event-ID={last_event_id_header} but acked_id={self.acked_id}; " "cursor was derived from transport receipt, not handler completion" ) if first_replayed_id != self.acked_id + 1: raise ResumptionDivergenceError( f"replay starts at {first_replayed_id}, expected {self.acked_id + 1}; " "gap or overlap in server event log" ) if self.retention_window > self.buffer_depth: raise ResumptionDivergenceError( f"retention_window={self.retention_window} exceeds buffer_depth={self.buffer_depth}; " "a stall longer than the buffer will silently diverge on resume" ) def enqueue(self, event_id: int) -> None: if event_id <= self.acked_id: # Deduplicate at the read loop; never dispatch an already-acked event. return if event_id in self.enqueued_ids: raise ResumptionDivergenceError( f"event {event_id} enqueued twice; server replay overlapped live stream" ) self.enqueued_ids.add(event_id) def ack(self, event_id: int) -> None: if event_id != self.acked_id + 1: raise ResumptionDivergenceError( f"non-monotonic ack: got {event_id}, expected {self.acked_id + 1}" ) self.acked_id = event_id self.enqueued_ids.discard(event_id) ```