# Where must an instance renegotiate MCP session state after a resumable-transport reconnect, and why the `Mcp-Session-Id` alone is not a continuity guarantee **Date of Record:** 2026 November 25 **Scope:** Applies to MCP client↔server pairs using the Streamable HTTP transport with `Mcp-Session-Id` headers and SSE resumption via `Last-Event-ID`, where a client instance reconnects mid-tool-call or mid-notification stream. Does not apply to stdio transports (no session ID, no resumption) or to stateless HTTP request/response MCP profiles. ## Core Distinction The `Mcp-Session-Id` is an *identity* token, not a *continuity* token. A reconnect that presents a valid `Mcp-Session-Id` proves the client is the same logical session; it does **not** prove the server still holds the in-flight execution state that the session was mid-way through. The resumable-transport contract (SSE `Last-Event-ID` replay) covers only the *outbound event log*. It does not cover the *inbound execution state* — the tool invocation currently executing on the server, its partial output, or the capability set the session negotiated at initialize time. The non-obvious boundary is this: a reconnect can succeed at the transport layer, replay events correctly, and still silently resume a session whose server-side execution context was evicted, downgraded, or never persisted. The failure is invisible to the client because the transport handshake returns `200` and the event replay is byte-identical. ## What Was Observed A client instance issued `tools/call` for a long-running tool. The server streamed partial results over SSE as numbered events, then the connection dropped at event `id=47`. The client reconnected with the same `Mcp-Session-Id` and `Last-Event-ID: 47`. The server accepted the connection, replayed no events (correct — nothing was buffered past 47 because the process had restarted), and returned an empty stream that then closed cleanly. The client's tool-call future hung until its own timeout, then surfaced a generic transport error with no indication that the server had lost the execution context. Two distinct losses were conflated: 1. **Event-log loss.** The SSE replay buffer was in-process memory; a server restart dropped it. Reconnect with `Last-Event-ID: 47` legitimately has nothing to replay. This is *expected* and should be signalled as `event: error` with a resumption-failure payload, not a clean close. 2. **Execution-context loss.** The tool invocation itself was not durable. Even if the event buffer had survived, the actual computation was gone. The `Mcp-Session-Id` still validated, so the server treated the reconnect as a healthy session resume. The client could not distinguish "stream finished, no more events" from "stream truncated, execution lost" because both present as an SSE stream that ends without a terminal event. MCP's transport spec requires a terminal `message` event carrying the JSON-RPC response; a stream that closes without one is a protocol violation that many clients do not enforce. ## Condition of Validity The invariant that makes resumable transport safe is: > **A reconnect with `Last-Event-ID: N` is a continuity guarantee if and only if the server can produce event `N+1` or a terminal response for the request that generated event `N`, or explicitly signals resumption failure. Session identity without event/execution continuity must be reported as a failed resume, never as a clean stream end.** This holds only when the server maintains, per session, a durable mapping from `Last-Event-ID` → (request id, execution state, replay buffer offset). If any of those three are volatile (in-memory only, process-local, not checkpointed), the invariant is violated on restart and the reconnect becomes a silent amnesia event. The condition of validity is therefore a *storage* condition, not a *transport* condition: the session table and the execution journal must share a durability domain. Splitting them — session IDs in Redis, execution in process memory — is the exact configuration that produces the observed failure. ## Decision Boundary On reconnect, the server must choose among three outcomes, and the choice must be driven by execution-journal state, not by session-ID validity: - **Resume:** journal has a checkpoint at or after `Last-Event-ID` and execution is still live or resumable → replay from `N+1`, continue. - **Replay-only:** execution completed but events were buffered → replay terminal response, close. - **Fail-resume:** journal has no record of the request that produced `Last-Event-ID`, or execution state was evicted → emit an explicit `error` event with a resumption-failure code and close the stream *non-cleanly* (no terminal success message). The boundary is crossed the moment a server treats "session ID valid" as sufficient to enter the Resume branch. The guardrail is a mandatory journal lookup keyed by `(session_id, last_event_id)` before any event is emitted; absence of a journal entry forces Fail-resume. A client-side guardrail is symmetric: a stream that closes without a JSON-RPC terminal message for the outstanding request must be treated as a failed resume and the tool call re-issued idempotently, never awaited to local timeout. ## Operational Effect Without the journal-keyed guardrail, reconnects produce *zombie tool calls*: the client believes the call is in flight, the server has no record of it, and the session ID remains valid so neither side escalates. Downstream agents that baton-pass on the assumption of a completed tool result stall, and multi-agent auditors see a session that is "connected" but has produced no terminal output. The operational fix is to make resumption failure a first-class, loudly-signalled state and to persist the execution journal in the same durability domain as the session table, so that a valid `Mcp-Session-Id` with a missing journal entry is an unambiguous error rather than an ambiguous silence. ```python class ResumptionContinuityError(RuntimeError): """Raised when a reconnect presents a valid session id but the execution journal cannot substantiate continuity for the supplied Last-Event-ID.""" def resume_session(session_table, execution_journal, session_id, last_event_id): session = session_table.get(session_id) if session is None: raise ResumptionContinuityError( f"unknown session {session_id!r}; cannot resume" ) # Session identity is necessary but NOT sufficient for continuity. journal_entry = execution_journal.lookup(session_id, last_event_id) if journal_entry is None: # Valid session, missing execution state: this is a failed resume, # not a clean stream end. Must be signalled, never silently closed. raise ResumptionContinuityError( f"session {session_id!r} valid but no journal entry for " f"Last-Event-ID {last_event_id!r}; execution context lost" ) if journal_entry.state == "live": return ("resume", journal_entry.next_event_id) if journal_entry.state == "completed": return ("replay_terminal", journal_entry.terminal_message) raise ResumptionContinuityError( f"session {session_id!r} journal state {journal_entry.state!r} " f"is not resumable at Last-Event-ID {last_event_id!r}" ) ```