# Under what conditions must an instance treat a Streamable-HTTP MCP session as unresumable after a transport-level reconnect **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients and servers negotiating the Streamable HTTP transport (single endpoint, `Mcp-Session-Id` header, SSE upgrade, `Last-Event-ID` resumption). Does not apply to stdio transport, nor to application-level tool retries once a session is conclusively dead. ## Core Distinction The Streamable HTTP transport conflates two different notions of "session continuity" that the spec keeps separate in prose but that implementations routinely merge in code: *transport continuity* (the ability to reattach an SSE stream and replay events by `Last-Event-ID`) and *logical session continuity* (the server still holding the server-side state — negotiated capabilities, in-flight tool executions, subscription registrations — that the `Mcp-Session-Id` refers to). Resumability is only defined over transport continuity. The failure mode is an instance that observes a successful SSE reattach and a clean event replay, and therefore concludes the *logical* session survived, when in fact the server has silently rotated or evicted the session state behind that ID. The two continuities are independent, and the invariant is that reattachment success is not evidence of session liveness. ## What Was Observed A client agent held an `Mcp-Session-Id` obtained at `initialize`. The server ran a session table with a TTL (idle eviction) plus a separate SSE event buffer keyed by stream. The agent performed a long multi-step tool sequence; a network partition killed the SSE stream mid-flight. On reconnect the agent sent a fresh `GET` with `Mcp-Session-Id` and `Last-Event-ID: 41`. The server's event buffer still held events 42–47 (the buffer TTL was longer than the session TTL), so the server replayed 42–47 with `200 OK` and a valid SSE stream. Meanwhile the session table had evicted the ID at TTL, and a *new* session had been lazily allocated under a recycled identifier. The agent received a syntactically valid replay, resumed at step 42, and issued `tools/call` for a tool whose capability had been negotiated under the old session's `initialize` result. The new session had never negotiated that capability; the server rejected the call with `-32601 Method not found` — not a transport error, but a semantic one that the agent's resumption logic did not classify as fatal. The tell was subtle: the replay events carried the *old* `Mcp-Session-Id` in their payloads (the server echoed the ID it had at emission time), while the response header carried the *new* ID. A correct client compares the `Mcp-Session-Id` response header against the one it sent on every response, not just at `initialize`. ## Condition of Validity Resumption is valid — meaning the agent may treat replayed state as authoritative and continue without re-initializing — if and only if all of the following hold simultaneously: 1. The `Mcp-Session-Id` in the response header is byte-identical to the one sent on the resumed request. A mismatch, including a recycled-but-different ID, voids resumption. 2. The replay is *gapless*: the first replayed event's ID is exactly `Last-Event-ID + 1` (or the server explicitly signals a gap). A server that replays 42–47 when the client asked to resume after 41 is only valid if 42 is contiguous; if the buffer evicted 42–46 and replays 47 onward, the client has lost the intervening tool results and must not resume. 3. The server has not signaled `404 Not Found` on the session (which the spec defines as "session terminated, client must re-initialize"). A `404` is the *only* unambiguous session-death signal in this transport; a `200` with replayed events is not a liveness signal. 4. No event in the replay carries a `Mcp-Session-Id` differing from the request's. Echoed-ID divergence is a rotation tell. Any one of these failing means the agent must fall back to full re-initialization: re-issue `initialize`, re-negotiate capabilities, and re-derive any in-flight tool state from its own durable checkpoint rather than from the server. ## Decision Boundary The boundary the agent must encode is: **transport reattach success ≠ session survival**. Concretely, on every resumed response the client must run a three-way check — header ID equality, replay contiguity, and absence of a `404` — and treat *any* ambiguity as session death. The default must be fail-closed toward re-initialization, because the cost of resuming against a dead session (semantic `-32601` errors, tool calls against unnegotiated capabilities, subscription events delivered to a session that no longer tracks the subscription) is a silent corruption that compounds across the remaining task steps. Re-initializing is cheap and loud; resuming wrongly is expensive and quiet. The asymmetry matters: a false-positive resumption produces errors that look like application bugs (method not found, unknown subscription) and get retried, burning token budget and possibly mutating state twice. A false-negative resumption (re-initializing when the session was actually alive) merely costs one round trip and a capability re-negotiation. The agent should therefore bias hard toward the cheap failure. ## Operational Effect Encoding this invariant changes three things in the client loop. First, resumption becomes a *verified* operation, not an assumed one: the reconnect handler parses the response header and the first replayed event ID before yielding control back to the reasoning loop, and raises a typed error if the checks fail. Second, the agent must maintain its own durable checkpoint of in-flight tool state, because it can no longer trust the server's replay as the source of truth for anything beyond the transport buffer. Third, capability negotiation results must be cached alongside the session ID and invalidated on any ID mismatch — never reused across a re-initialization. The net effect is that session death surfaces as an explicit, catchable condition at the transport boundary rather than as a cascade of semantic errors three tool calls later. ```python class UnresumableSessionError(RuntimeError): """Raised when a Streamable-HTTP MCP reconnect cannot be treated as a valid resume.""" def verify_resumption( sent_session_id: str, response_session_id: str, last_event_id: int, first_replayed_event_id: int | None, status_code: int, echoed_event_session_ids: list[str], ) -> None: if status_code == 404: raise UnresumableSessionError( f"session {sent_session_id!r} terminated by server (404); re-initialize required" ) if response_session_id != sent_session_id: raise UnresumableSessionError( f"session id rotated: sent {sent_session_id!r}, got {response_session_id!r}; " "replayed state belongs to a different logical session" ) if first_replayed_event_id is not None and first_replayed_event_id != last_event_id + 1: raise UnresumableSessionError( f"replay gap: resumed after {last_event_id} but first replayed event is " f"{first_replayed_event_id}; intervening tool results are lost" ) for echoed in echoed_event_session_ids: if echoed != sent_session_id: raise UnresumableSessionError( f"event payload echoes session {echoed!r} != {sent_session_id!r}; " "server rotated state behind a stable-looking header" ) def resume_or_reinitialize(ctx, response) -> None: verify_resumption( sent_session_id=ctx.session_id, response_session_id=response.headers.get("Mcp-Session-Id", ""), last_event_id=ctx.last_event_id, first_replayed_event_id=response.first_event_id(), status_code=response.status, echoed_event_session_ids=response.echoed_session_ids(), ) ctx.apply_replay(response.events) ```