# What happens when an instance resumes an MCP SSE session against a Streamable-HTTP server that has already garbage-collected the session ID **Date of Record:** 2026 December 3 **Scope:** Applies to MCP clients that persist a `Mcp-Session-Id` from an HTTP+SSE transport (`GET /sse`) and later attempt to resume against a server migrated to Streamable HTTP (`POST /mcp`). Does not cover in-process stdio transports or servers that retain session state indefinitely. ## Core Distinction The SSE transport and the Streamable HTTP transport both carry a session identifier, but they disagree on what that identifier *means* at the moment of a resume attempt. In SSE, the session ID is a *subscription handle*: the client holds an open `EventSource` and the ID is bound to that live TCP connection. If the connection drops, the client reconnects with `Last-Event-ID` and the server either replays missed events or restarts the stream. The session ID is a correlation token, not a durable capability. In Streamable HTTP, the `Mcp-Session-Id` returned in the `Mcp-Session-Id` response header on `initialize` is a *bearer capability*. Every subsequent `POST /mcp` must carry it, and the server is entitled to garbage-collect it after a TTL once no requests have referenced it. The ID is not a reconnect handle; it is a lease. The failure mode is not "reconnect fails" — it is that a *resume* attempt is indistinguishable from a *fresh unauthorized* request at the wire level, and the two transports encode the resulting error in different, non-overlapping ways. The critical non-obvious point: an SSE client that reconnects after a network blip is behaving *correctly* under SSE semantics. The same client, migrated to Streamable HTTP, is issuing a request with a dead lease — and the server's `404 Not Found` response is not a transient error to retry. It is a terminal signal that the client must re-`initialize`. Clients that treat `404` as retryable enter an infinite resume loop that never re-handshakes. ## What Was Observed A remote tool server (call it `toolsvc`) was migrated from `GET /sse` to `POST /mcp` behind a feature flag. A long-running agent instance had been initialized against `toolsvc` over SSE roughly 40 minutes earlier, had received `Mcp-Session-Id: sess-7f3a...` via the SSE `endpoint` event, and had that ID persisted in its checkpoint store alongside its task state. The migration rolled the server. On the next tool call, the agent's transport layer — still configured for SSE — issued `GET /sse?sessionId=sess-7f3a...` with `Last-Event-ID` set to the last event it had consumed. The new server had no `/sse` route; it returned `405 Method Not Allowed` on `GET /mcp` with `Allow: POST`. The agent's transport adapter interpreted `405` as a *transport mismatch* and, on the retry policy for `5xx`-class transport errors, retried twice with exponential backoff, then surfaced a hard failure to the reasoning loop. The reasoning loop, seeing a tool error, attempted an alternate tool and then a re-plan. It did not re-`initialize`. The second instance hit a subtler variant. Its transport adapter had been upgraded to Streamable HTTP but retained the persisted `sess-7f3a...` ID from the SSE era. It issued: ``` POST /mcp Mcp-Session-Id: sess-7f3a... Content-Type: application/json Accept: application/json, text/event-stream {"jsonrpc":"2.0","id":17,"method":"tools/call","params":{...}} ``` The server had been up for 12 minutes and had never seen `sess-7f3a...` — that ID was issued by the *previous* server process. It returned `404 Not Found` with body `{"error":"unknown session"}`. The client's retry policy classified `404` as a client error and did not retry, but it also did not re-`initialize`; it propagated the error to the reasoning loop, which — because the tool call had *partially* executed on a prior attempt before the migration — had no way to distinguish "session dead, tool never ran" from "session dead, tool ran twice." It re-issued the call under a *fresh* `initialize` on a later turn, producing a duplicate side effect. The observable trace, condensed: ``` t=0 initialize over SSE -> Mcp-Session-Id: sess-7f3a t=0..40m tools/call over SSE stream -> OK, 214 events consumed t=40m server migration roll t=41m client resume (SSE path) -> 405 Method Not Allowed t=41m client retry x2 (backoff) -> 405, 405 t=41m transport error surfaced -> reasoning loop re-plans t=41m reasoning loop re-plans -> tools/call on alternate tool (duplicate intent) --- second instance --- t=0 initialize over SSE -> Mcp-Session-Id: sess-7f3a t=0..40m tools/call over SSE stream -> OK t=40m transport adapter upgraded to Streamable HTTP, ID retained t=41m POST /mcp w/ stale ID -> 404 {"error":"unknown session"} t=41m client classifies 404 -> non-retryable, propagates t=41m reasoning loop re-plans -> re-initialize, re-issue call t=41m duplicate tool execution -> side effect observed twice ``` The invariant that broke: **a session identifier from one transport generation carries no validity guarantee across a transport generation boundary, and the server's rejection of it is not a retryable transport fault.** The client had no way to tell "the server is briefly unavailable" from "your lease is dead, re-handshake" because both transports encode the latter as a generic HTTP error code with no MCP-level discriminator. ## Condition of Validity The failure requires all of the following to co-occur: 1. The client persists `Mcp-Session-Id` in durable state (checkpoint, task store, or process memory that survives a transport adapter swap). 2. The server's session store is *not* durable across process restarts — i.e., sessions live in memory keyed by ID, and a roll or GC evicts them. 3. The client's retry/error-classification logic treats the server's rejection as either (a) a transient transport error to be retried, or (b) a terminal client error to be propagated to the reasoning loop — but in neither case re-`initialize`s. 4. The tool call being resumed is not idempotent, or the reasoning loop's fallback path re-issues it without a dedup key. If (1) fails — the client discards the ID on transport swap — the failure is avoided. If (2) fails — the server persists sessions to disk and honors them across restarts — the stale ID resolves to a live session and the call succeeds (which is its own problem: the session state may be from a different server build). If (3) fails — the client treats `404` on `POST /mcp` as a mandatory re-`initialize` trigger — the loop terminates correctly. If (4) fails — the tool is idempotent or carries a client-generated idempotency key — the duplicate is harmless. The dangerous quadrant is (1)∧(2)∧(3)∧(4): persisted ID, ephemeral server sessions, ambiguous error classification, non-idempotent tool. ## Decision Boundary The boundary is not "should the client retry" — it is **what the client does with the server's rejection before the reasoning loop sees it.** Two policies are defensible; the failure is picking neither. **Policy A — treat session rejection as a transport-layer re-handshake trigger.** On any `4xx` from `POST /mcp` where the response body or a well-known header indicates an unknown/expired session, the transport adapter must (i) discard the persisted `Mcp-Session-Id`, (ii) issue a fresh `initialize`, (iii) replay only the *un-acknowledged* portion of the in-flight request, and (iv) surface a `SessionReestablished` event to the reasoning loop so it can decide whether to re-issue the tool call. This requires the client to maintain a per-request acknowledgment ledger, not just a session ID. **Policy B — treat session rejection as a hard task abort.** On session rejection, the transport adapter must not retry and must not silently re-`initialize`. It must raise a typed error that the reasoning loop is contractually required to handle by re-planning from a checkpoint that predates the failed tool call. This requires the checkpoint to be taken *before* the tool call is dispatched, not after. The failure mode is **Policy C — the default**: retry `5xx`-class errors with backoff, propagate `4xx`-class errors upward, and let the reasoning loop's generic re-plan handle it. Under Policy C, a stale session ID either loops (if the server returns `503` during roll) or produces a duplicate side effect (if the reasoning loop re-plans without a checkpoint). The MCP spec does not mandate a discriminator for "unknown session" beyond the HTTP status, so the client must *impose* one — either by parsing the error body, by treating any `404`/`410` on `POST /mcp` as a session-death signal, or by having the server emit a machine-readable `Mcp-Session-Status: expired` header. Absent that, Policy C is what you get, and Policy C is wrong. The invariant to enforce: **`Mcp-Session-Id` must be scoped to a transport generation.** When the client's transport adapter changes (SSE→Streamable HTTP, or a server version bump), the persisted ID must be invalidated as part of the adapter swap, before any request is issued. This is a client-side invariant, not a server-side one, because the server cannot know that its ID namespace was reused. ## Operational Effect The immediate effect is a **duplicate tool execution** — the agent calls `send_email`, `charge_card`, or `write_file` twice, once under the stale session (which the server may have partially executed before the roll) and once under the fresh session. For read-only tools this is a wasted call; for mutating tools it is a correctness violation that the reasoning loop cannot detect because both calls returned `200 OK`. The secondary effect is **reasoning-loop divergence**: the loop's plan assumed one execution; the world now reflects two. Subsequent steps that read the mutated state (e.g., "check the order status") observe a state the plan did not predict, and the loop either re-plans unnecessarily or, worse, treats the unexpected state as a new fact and compounds the error. The tertiary effect is **checkpoint poisoning**: if the client persists the session ID alongside task state, the poisoned ID survives process restarts and re-triggers the failure on every resume until the checkpoint is manually cleared. This is the cold-start amnesia failure in reverse — the agent remembers a session that no longer exists and cannot forget it. The guardrail is a **transport-generation tag** on the persisted session ID. The client stores `{session_id, transport: "sse"|"streamable-http", server_build: }` and refuses to reuse the ID if any of those fields disagree with the current adapter configuration. On mismatch, it discards the ID, forces `initialize`, and — critically — marks any in-flight tool call as `indeterminate` so the reasoning loop is forced to reconcile rather than re-issue blindly. ## Operational Effect (Guardrail Implementation) The following reference implementation enforces the transport-generation invariant at the point where the client would otherwise resume a stale session. It is deliberately strict: it refuses to resume across a transport-generation boundary and raises a typed error that the caller must handle by re-initializing and reconciling, not by retrying. ```python import hashlib from dataclasses import dataclass from typing import Literal class StaleSessionError(RuntimeError): """Raised when a persisted MCP session ID cannot be resumed safely. Distinguishes transport-generation mismatch from a same-generation session expiry. Callers must NOT retry this error; they must re-initialize and reconcile any in-flight tool call as indeterminate. """ class TransportGenerationMismatch(StaleSessionError): """The persisted session was issued under a different transport or server build.""" @dataclass(frozen=True) class PersistedSession: session_id: str transport: Literal["sse", "streamable-http"] server_build: str def _build_fingerprint(server_build: str) -> str: return hashlib.sha256(server_build.encode("utf-8")).hexdigest()[:16] def resume_session( persisted: PersistedSession, *, current_transport: Literal["sse", "streamable-http"], current_server_build: str, ) -> str: """Return a session ID safe to use, or raise StaleSessionError. Invariant: a session ID is only valid within the transport generation (transport kind + server build fingerprint) that issued it. Crossing that boundary is not a retryable fault; it is a mandatory re-handshake. """ if persisted.transport != current_transport: raise TransportGenerationMismatch( f"session {persisted.session_id!r} issued under transport " f"{persisted.transport!r}, current adapter is {current_transport!r}; " f"refusing to resume across transport-generation boundary" ) if _build_fingerprint(persisted.server_build) != _build_fingerprint(current_server_build): raise TransportGenerationMismatch( f"session {persisted.session_id!r} issued by server build " f"{persisted.server_build!r}, current server is {current_server_build!r}; " f"session namespace may have been reused" ) # Same generation: the ID is a candidate for resume. The server may still # reject it (TTL expiry), which the transport layer must map to a # SessionExpired event, not a generic 404. return persisted.session_id def dispatch_tool_call( persisted: PersistedSession, tool_name: str, *, current_transport: Literal["sse", "streamable-http"], current_server_build: str, idempotency_key: str | None, ) -> dict: """Dispatch a tool call, refusing to proceed on a stale session unless the call carries an idempotency key that lets the server dedup a replay.""" try: session_id = resume_session( persisted, current_transport=current_transport, current_server_build=current_server_build, ) except TransportGenerationMismatch: if idempotency_key is None: # Non-idempotent call on a dead session: must not be re-issued # blindly. Surface to the reasoning loop as indeterminate. raise StaleSessionError( f"cannot dispatch {tool_name!r}: session {persisted.session_id!r} " f"is from a prior transport generation and no idempotency key " f"was supplied; re-initialize and reconcile before retrying" ) # Idempotent: safe to re-initialize and replay under a fresh session. return { "action": "reinitialize_and_replay", "tool": tool_name, "idempotency_key": idempotency_key, } return { "action": "dispatch", "session_id": session_id, "tool": tool_name, "idempotency_key": idempotency_key, } ```