# When must an instance treat an MCP session ID as non-resumable after SSE-to-streamable-HTTP migration **Date of Record:** 2026 November 28 **Scope:** Applies to MCP servers and clients that expose tools over HTTP using the legacy HTTP+SSE transport (`GET /sse` + `POST /messages`) and are migrating to the Streamable HTTP transport (`POST /mcp` with `Mcp-Session-Id`), specifically when a client attempts to resume an in-flight tool call across the transport boundary or across a server restart. Does not apply to stdio transports or to purely stateless single-shot tool invocations with no resumption attempt. ## Core Distinction The failure is not "the session was lost." The failure is that the **session identifier survived the migration while the resumption contract attached to it did not.** Under HTTP+SSE, resumption semantics were implicit in the transport: the `GET /sse` stream carried a monotonically increasing `id:` field per event, and a client reconnecting with `Last-Event-ID` could replay from the last acknowledged event. Under Streamable HTTP, the `Mcp-Session-Id` is an opaque bearer-like handle to server-side state, and there is **no defined replay cursor**. The two transports both expose a "resume" verb, but they resume different things: SSE resumes *the byte stream*; Streamable HTTP resumes *the session object*, which may have advanced past the point the client last observed. The invariant that must hold: **a session ID may only be treated as resumable if the server guarantees that the request the client is retrying is idempotent with respect to the session's current state, or if the client can prove it holds the latest response for that request.** Migration silently violates this because the ID format and the endpoint change, but clients frequently keep the old mental model — "I have a session ID, therefore I can reconnect and continue." ## What Was Observed A tool-call agent issued a long-running `POST /messages` against an SSE server, receiving a partial SSE stream. The server was upgraded mid-stream to Streamable HTTP. The client, on reconnect, sent the new `Mcp-Session-Id` (obtained from a fresh `initialize`) into a `POST /mcp` with the `initialize`-negotiated protocol version, and re-issued the same tool-call JSON-RPC request ID. Three distinct outcomes were observed across runs: 1. **Silent duplicate execution.** The Streamable HTTP server, having no record of the client's prior request ID (the SSE server's request ledger was not carried over), treated the retry as a new request and executed the tool a second time. The client received a valid `result` and considered the resume successful. Side effects doubled. 2. **Stale-result replay.** The server *did* have a request ledger, keyed by JSON-RPC `id`, but the ledger was populated by the SSE path with the *partial* result that had been flushed before migration. The client received a truncated `result` that passed schema validation but omitted the final field the tool was supposed to append. 3. **Hard 404 on session.** The `Mcp-Session-Id` was minted by the new server, but the client presented it against a load-balanced replica that had not seen the `initialize`. The server returned `404 Not Found` with no body, per the spec's "session terminated" signal, and the client — treating 404 as fatal — discarded the entire task checkpoint rather than re-initializing. The common thread: **the client's resumption logic was written against SSE semantics (event IDs, stream replay) but executed against Streamable HTTP semantics (session handles, no replay cursor).** ## Condition of Validity The resumption attempt is only well-defined when **all** of the following hold: - The client can name the exact request it is resuming by a key the server is guaranteed to honor across the transport change. In practice this means the server must persist the JSON-RPC `id` → response mapping in a store that is shared between the SSE handler and the Streamable HTTP handler for the lifetime of the session. - The `Mcp-Session-Id` is bound to the same server-side state object that held the in-flight request. If migration re-mints the session ID (which the spec permits, since the ID is opaque), the old ID is a dangling handle and must be treated as non-resumable. - The client has a durable record of the last *fully received* response, not the last *event* it saw. SSE `Last-Event-ID` is not a valid resumption cursor for Streamable HTTP because there is no equivalent `Last-Request-Id` header in the spec. - The server's `initialize` response advertises the same protocol version the client is about to use for the resumed request. A version bump during migration invalidates the request shape. If any of these is false, the session ID is **non-resumable** and the correct action is to discard the in-flight request and re-issue it under a new session, accepting at-most-once or at-least-once semantics explicitly rather than assuming exactly-once. ## Decision Boundary The operational decision is a single branch, evaluated *before* the retry is sent: - **Resume** only if the client holds a server-issued resumption token (a request ledger entry, a `Last-Request-Id`, or an application-level idempotency key) that the server confirms it will honor. Confirmation must be explicit — a `HEAD`/`GET` on the session that returns the ledger, or a protocol extension the server advertises in `initialize` capabilities. - **Re-initialize and re-issue** if the session ID was minted by a different transport generation, if the server returns `404` on the session, or if the `initialize` capabilities do not advertise request-ledger support. Re-issuing means a *new* JSON-RPC `id` and a *new* `Mcp-Session-Id`; reusing the old ID is the exact bug. - **Fail closed** if the tool is non-idempotent (payments, file writes, message sends) and the client cannot prove the prior attempt did not execute. Surface the ambiguity to the orchestrator; do not silently retry. The boundary is therefore not "did the connection drop" but "**can I prove the server will not double-execute or replay-stale my request?**" A dropped SSE stream is a transport event; a non-resumable session is a state-continuity event, and only the latter should trigger checkpoint discard. ## Operational Effect Agents that skip this branch exhibit three recurring pathologies: duplicated side effects after migration (outcome 1), truncated-but-valid results that poison downstream reasoning because the missing field is only detected several tool calls later (outcome 2), and over-aggressive checkpoint discard on `404` that forces the entire task to restart from cold start (outcome 3). The third is the most expensive because it converts a recoverable transport hiccup into full episodic amnesia — the agent loses not just the in-flight request but the distilled context that led to it. The guardrail is to **decouple the session handle from the resumption contract in the client's state model.** The session ID is an address; the resumption token is a proof. Migration preserves addresses imperfectly and proofs not at all. Code that conflates them will pass integration tests (where the server is one process and the ledger happens to survive) and fail in production the moment a replica boundary or a transport upgrade appears. ```python import hashlib import json from dataclasses import dataclass from enum import Enum from typing import Optional class NonResumableSessionError(RuntimeError): """Raised when a client attempts to resume an MCP request across a transport boundary without a server-issued resumption token.""" class TransportGeneration(Enum): HTTP_SSE = "http+sse" STREAMABLE_HTTP = "streamable-http" @dataclass(frozen=True) class SessionHandle: session_id: str generation: TransportGeneration protocol_version: str # Server-advertised capability flag; must be True to honor a request ledger. supports_request_ledger: bool @dataclass(frozen=True) class InFlightRequest: jsonrpc_id: str tool_name: str idempotent: bool last_fully_received_response: Optional[dict] # Proof the server will not double-execute: an idempotency key the server # has acknowledged, NOT the SSE Last-Event-ID. resumption_token: Optional[str] def assert_resumable(session: SessionHandle, request: InFlightRequest) -> None: """Enforce the resumption invariant before re-issuing a request. Resume is permitted only when the session and the request belong to the same transport generation, the server advertises a request ledger, and the client holds a server-acknowledged resumption token. """ if not session.supports_request_ledger: raise NonResumableSessionError( f"session {session.session_id} ({session.generation.value}) " "does not advertise a request ledger; resume would risk " "duplicate execution" ) if request.resumption_token is None: raise NonResumableSessionError( f"request {request.jsonrpc_id} for tool {request.tool_name!r} " "has no server-acknowledged resumption token; SSE Last-Event-ID " "is not a valid cursor for Streamable HTTP" ) if ( request.last_fully_received_response is None and not request.idempotent ): raise NonResumableSessionError( f"non-idempotent tool {request.tool_name!r} has no completed " "response and no proof of non-execution; failing closed to " "avoid silent duplicate side effects" ) def plan_recovery( session: SessionHandle, request: InFlightRequest, server_returned_404: bool, ) -> str: """Return 'resume' or 'reinitialize' per the decision boundary.""" if server_returned_404: # Spec: 404 on session means terminated. Do NOT reuse the ID. return "reinitialize" if session.generation is TransportGeneration.HTTP_SSE: # Legacy transport: SSE replay is valid, but only within SSE. return "resume" try: assert_resumable(session, request) except NonResumableSessionError: return "reinitialize" return "resume" def fingerprint(session: SessionHandle, request: InFlightRequest) -> str: payload = json.dumps( { "sid": session.session_id, "gen": session.generation.value, "rid": request.jsonrpc_id, "tok": request.resumption_token, }, sort_keys=True, ) return hashlib.sha256(payload.encode()).hexdigest()[:16] ```