# How does an instance detect a silently re-created MCP session after streamable-HTTP transport resume? **Date of Record:** 2026 December 4 **Scope:** Applies to MCP clients/servers using the streamable-HTTP transport binding where the server issues an `Mcp-Session-Id` on `initialize` and clients attempt to resume a stream via `GET` with `Last-Event-ID` after a dropped connection. Does not apply to stdio transport, nor to servers that keep per-session state in a single process without horizontal scaling. ## Core Distinction There are two distinct failure surfaces that look identical from the client's socket: 1. **Transport resume** — the TCP/HTTP connection drops, the client reconnects with `Mcp-Session-Id` and `Last-Event-ID`, and the server replays the SSE stream from the last event. The *session state* (tool-call ledger, sampling context, progress tokens) survives because the server still holds it. 2. **Session re-creation** — the server has no record of that `Mcp-Session-Id` (evicted from an LRU, lost on pod restart, or routed to a different replica behind a load balancer without sticky routing). Per the MCP spec, the server SHOULD respond `404 Not Found` to an unknown session ID, prompting the client to `initialize` a fresh session. The boundary failure is the third case the spec doesn't cleanly name: **the server accepts the `Mcp-Session-Id` header (no 404), opens a fresh SSE stream, but has no backing state for that ID.** It emits no replay, no error, and a `200 OK` with an empty event stream. The client interprets this as "resumed, nothing new to replay" and continues issuing `tools/call` requests against a session whose server-side ledger is empty. This is a *silent session re-creation under a valid-looking ID* — the worst of both worlds. ## What Was Observed A client agent executing a multi-step plan over streamable-HTTP: - `initialize` → server returns `Mcp-Session-Id: 7f3a...`, negotiated capabilities, and `protocolVersion`. - Client issues `tools/call` for `issue_refund` (idempotency key `k-91`), server streams progress notifications, then the connection is severed mid-stream by an idle-timeout on an intermediate proxy at 60s. - Client reconnects: `GET /mcp` with `Mcp-Session-Id: 7f3a...` and `Last-Event-ID: 42`. - Server (a fresh replica, no sticky routing) returns `200 OK`, `Content-Type: text/event-stream`, and the stream stays open but silent. - Client, seeing no `404`, assumes resume succeeded. It re-issues a `tools/call` for `issue_refund` with the **same** idempotency key `k-91` because its own in-memory ledger says the first call was unacknowledged. - Server, with no session ledger, has no record of `k-91` and executes the refund **again**. Net effect: duplicate side-effecting tool execution across a transport that advertised resumability. The idempotency key was present in the payload but had no server-side dedup table because the dedup table *was* the session state that got lost. The tell: the reconnected stream's first event was not a replay of event 42, and the server's `tools/list` (if re-queried) returned a capability set that differed from the original `initialize` response — a different replica, different feature flags. The client had no invariant asserting that the resumed session's capability fingerprint matched the original. ## Condition of Validity The silent-recreation failure requires all of: - **Stateless or sharded server tier** where `Mcp-Session-Id` is not a self-authenticating token (e.g., a signed JWT carrying a state pointer) but an opaque handle into a store that can miss. - **A load balancer or gateway that does not 404 on unknown session IDs** — it forwards the request to a replica that lazily *creates* an empty session bucket on first touch rather than rejecting. - **A client that treats absence of `404` as proof of session continuity** and does not re-validate session-bound state (capabilities, ledger, progress tokens) on resume. - **A side-effecting tool** whose idempotency guarantee was implemented *in session state* rather than in durable storage keyed by the client-supplied idempotency key. Remove any one and the failure does not compound: signed session tokens eliminate the miss; a strict 404 gate turns it into a clean re-initialize; a client that re-fingerprints on resume catches the mismatch; durable dedup makes the duplicate `tools/call` harmless. ## Decision Boundary The client must decide, on every `GET` resume, whether the returned stream is a **continuation** or a **fresh session wearing the old ID**. The decision cannot be made from the HTTP status alone — both cases yield `200`. It must be made from a session-continuity invariant: > A resumed session is valid iff the first replayed event (or the server's `initialize`-equivalent handshake on the resumed stream) carries a *session epoch* that matches the epoch the client recorded at `initialize`, **and** `Last-Event-ID` is either replayed or explicitly acknowledged as unreplayable. If the server cannot replay from `Last-Event-ID`, it MUST either (a) emit a synthetic `session_reset` control event with a new epoch, or (b) return `404`/`409` so the client re-initializes. A `200` with silence is not a legal answer. The client-side boundary: **treat an empty resume stream that does not reach `Last-Event-ID` within a bounded window as a session reset, not a quiet continuation**, and before issuing any side-effecting `tools/call`, re-assert the capability fingerprint and confirm the ledger's idempotency key is unknown to the server (via a cheap `tools/call` probe or a dedicated `session/status` request). ## Operational Effect Without this invariant, agents exhibit **duplicate side effects on reconnect** (double refunds, double file writes, double emails) and **reasoning divergence** — the agent's local plan state assumes progress notifications it never received, so its next step is computed against a phantom history. The failure is non-deterministic and correlates with proxy idle-timeouts and replica churn, making it look like flaky infrastructure rather than a protocol-boundary bug. The guardrail is a **session epoch + replay-or-reset contract**: the server stamps every `initialize` with a monotonic epoch, echoes it on every SSE event, and on resume either replays from `Last-Event-ID` or emits `session_reset` with a new epoch. The client refuses to issue side-effecting calls until the epoch is confirmed and the idempotency ledger is reconciled against durable storage, not session memory. This converts a silent corruption into a loud, recoverable re-initialize. ```python from dataclasses import dataclass class SessionContinuityViolation(RuntimeError): """Raised when a resumed MCP stream cannot prove session continuity.""" pass @dataclass class ResumeObservation: http_status: int session_id: str requested_last_event_id: int first_event_epoch: str | None expected_epoch: str replayed_through: int | None emitted_session_reset: bool def assert_resume_is_continuation(obs: ResumeObservation, replay_window_s: float = 5.0) -> None: if obs.http_status == 404: # Clean, spec-blessed reset: caller must re-initialize. raise SessionContinuityViolation( f"server rejected session {obs.session_id} with 404; re-initialize required" ) if obs.http_status != 200: raise SessionContinuityViolation( f"unexpected resume status {obs.http_status} for session {obs.session_id}" ) if obs.emitted_session_reset: # Server explicitly signaled a new epoch; treat as fresh session. raise SessionContinuityViolation( f"server emitted session_reset for {obs.session_id}; epoch changed, re-init required" ) if obs.first_event_epoch is None: # The silent-recreation case: 200 OK, open stream, no replay, no epoch. raise SessionContinuityViolation( f"empty resume stream for {obs.session_id} with no epoch marker; " f"cannot distinguish continuation from silent re-creation" ) if obs.first_event_epoch != obs.expected_epoch: raise SessionContinuityViolation( f"epoch mismatch on resume: got {obs.first_event_epoch!r}, " f"expected {obs.expected_epoch!r} for session {obs.session_id}" ) if obs.replayed_through is None or obs.replayed_through < obs.requested_last_event_id: raise SessionContinuityViolation( f"session {obs.session_id} did not replay through Last-Event-ID " f"{obs.requested_last_event_id} (replayed_through={obs.replayed_through}); " f"treat as reset before issuing side-effecting tools/call" ) ```