# What happens when an instance resumes an MCP stream against a re-established SSE session ID that the server has already garbage-collected **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers using the HTTP-native transport with Server-Sent Events (SSE) streaming and `Last-Event-ID`-based resumption, where the client reconnects after an interruption. Does not apply to stdio transports, to WebSocket-based MCP bindings, or to stateless request/response MCP profiles where no session channel exists. ## Core Distinction There are two distinct things a client can "resume," and conflating them is the failure. The **session ID** (`Mcp-Session-Id` header) identifies a logical conversation context on the server — it gates tool state, negotiated capabilities, and per-session caches. The **event stream position** (`Last-Event-ID`) identifies a cursor into a specific SSE stream instance. A resumption attempt is valid only if *both* are still live. The MCP HTTP transport spec lets the server terminate a session at any time (idle timeout, restart, memory pressure) and independently rotate the SSE stream behind a still-valid session. A client that reconnects carrying a valid-looking `Mcp-Session-Id` plus a stale `Last-Event-ID` will be accepted at the HTTP layer and silently served a *fresh* stream whose event IDs restart from a different sequence — or worse, an empty stream — producing a gap that the client never observes as an error. The invariant that must hold: **an event ID is only meaningful within the stream incarnation that minted it.** Resumption is sound only when the server can prove the `Last-Event-ID` belongs to the current incarnation; otherwise it must reject with an explicit `400`/`409` and force full re-initialization, not fall through to a new stream. ## What Was Observed A long-running agent issued `tools/call` for a multi-minute operation (a code-index build) that streamed progress notifications over SSE. The TCP connection dropped at the 90-second mark due to an intermediate proxy idle timeout. The client's reconnect logic did the "reasonable" thing: it re-issued the GET to the SSE endpoint with the stored `Mcp-Session-Id` and `Last-Event-ID: 4471`. The server had, 12 seconds earlier, garbage-collected the session's stream buffer after emitting event 4471 but *not* the session itself — the session record had a 300-second TTL, the stream buffer a 60-second TTL. These two TTLs were independent. On reconnect: - Session validation passed (`Mcp-Session-Id` still in the session table). - Stream lookup found no live stream for that session. - The server's handler, written defensively, **created a new stream** and began emitting events with IDs starting at 1, while responding `200 OK`. The client, seeing `200 OK` and a valid content type, assumed resumption succeeded and applied its dedup filter: "drop any event with ID ≤ last seen (4471)." Every new event (1, 2, 3, …) was ≤ 4471 and was therefore **discarded as a duplicate**. The agent waited on a completion notification that had already been emitted into the void. After the client's own 600-second operation timeout, it surfaced a generic `tool call timeout` — a symptom with no causal relationship to the actual fault. The trace signature to recognize: a reconnect that returns `200`, followed by a stream that delivers zero *accepted* events, followed by a timeout rather than a protocol error. The agent did not fail to reconnect. It reconnected perfectly and threw away everything it received. ## Condition of Validity `Last-Event-ID` resumption is only sound under the conjunction: 1. The server maintains a per-stream-incarnation ID sequence, and the incarnation is identified in-band (e.g., an initial `event: stream-init` carrying an incarnation UUID) or bound to the session such that a new incarnation invalidates old IDs. 2. The server, on receiving a `Last-Event-ID` it cannot place within the current incarnation, returns an explicit non-2xx (recommended: `409 Conflict` with a body indicating `resume-impossible`) rather than opening a fresh stream. 3. The client treats "stream opened but no event with ID > last-seen within the first N events" as a resumption failure, not as "nothing new happened." A monotonicity check on the first received event ID is the cheap detector: if `first_new_id <= last_seen_id`, the incarnation rotated and the client must re-initialize. 4. Session TTL and stream-buffer TTL are either equal or the stream buffer is *shorter* with an explicit tombstone recording the last emitted ID and its incarnation, so the server can answer "you missed nothing / you missed N events / you must re-init" definitively for the retention window. The failure requires only that (2) or (3) be absent. In practice both were absent: the server fell through to a new stream, and the client's dedup filter was written assuming IDs are globally monotonic for a session — an assumption the transport spec does not grant. ## Decision Boundary When a reconnect returns `200` but the first event ID is not strictly greater than `Last-Event-ID`, the client has exactly two correct moves and one forbidden one: - **If the server advertises an incarnation marker** (init event, or a `Mcp-Stream-Incarnation` response header), compare it. Same incarnation + non-monotonic ID ⇒ protocol violation, abort. Different incarnation ⇒ full re-initialize (`initialize` → renegotiate capabilities → re-issue any in-flight `tools/call` whose result was not observed). - **If no marker exists**, treat non-monotonic first-ID as resumption failure by default. Do not silently continue. - **Forbidden:** continuing to consume the new stream while applying the old dedup filter. This is the exact state that produced the silent gap. On the server side, the boundary is: never mint a new stream in response to a resume request that carries a `Last-Event-ID` you cannot resolve. Return `409` with a machine-readable reason. A `200` with a fresh stream is a lie about continuity. ## Operational Effect The practical consequence is that **resumption must be a verified handshake, not an optimistic reconnect.** Agents that treat SSE reconnect as fire-and-forget will exhibit the worst possible failure profile: they appear healthy (connection up, HTTP 200, bytes flowing) while making zero forward progress, and they fail via timeout far from the fault site, poisoning any downstream error attribution, retry policy, or auditor replay that keys off the timeout. The guardrail is cheap: one monotonicity assertion on the first post-reconnect event, one incarnation check, and a server that refuses to fabricate continuity it cannot prove. The cost of omitting it is a class of silent, self-inflicted event loss that no amount of client-side retry logic can recover, because the client has already decided the events it is discarding are duplicates. ```python from dataclasses import dataclass class StreamResumptionError(RuntimeError): """Raised when a resumed MCP SSE stream cannot be proven continuous with the stream the client last observed.""" @dataclass class ResumeState: session_id: str last_event_id: int incarnation: str | None def verify_resumption(state: ResumeState, response_incarnation: str | None, first_event_id: int | None) -> None: """Validate that a 200-OK reconnect actually continues the prior stream. Must be called before any event from the new stream is consumed or deduplicated. Raises if continuity cannot be established. """ if first_event_id is None: # Stream opened but delivered nothing; cannot confirm continuity. raise StreamResumptionError( f"session {state.session_id}: stream opened with no events; " f"cannot confirm resumption past Last-Event-ID={state.last_event_id}" ) if response_incarnation is not None and state.incarnation is not None: if response_incarnation != state.incarnation: raise StreamResumptionError( f"session {state.session_id}: stream incarnation rotated " f"({state.incarnation} -> {response_incarnation}); " f"event IDs are not comparable, full re-initialize required" ) if first_event_id <= state.last_event_id: raise StreamResumptionError( f"session {state.session_id}: non-monotonic event ID on resume " f"(first_new={first_event_id} <= last_seen={state.last_event_id}); " f"server likely minted a fresh stream under a stale session — " f"refusing to apply dedup filter over a gap" ) ```