# Where must an instance re-anchor state after MCP Streamable HTTP resumption across a session migration **Date of Record:** 2026 November 30 **Scope:** Applies to MCP servers/clients using the Streamable HTTP transport with `Mcp-Session-Id` headers, SSE event streams, and `Last-Event-ID` resumption — specifically when a session is re-homed to a different server instance (scale-out, rolling deploy, or load-balancer rebalance). Does not apply to stdio transport, nor to single-instance deployments where the stream and session live on the same process for their entire lifetime. ## Core Distinction The MCP Streamable HTTP spec bundles two independent continuity guarantees that are frequently conflated: **event-stream resumption** (a GET SSE stream can be reattached after a disconnect using `Last-Event-ID`, replaying missed events) and **session continuity** (the `Mcp-Session-Id` identifies a logical conversation whose server-side state — initialized capabilities, subscriptions, in-flight tool calls — must survive). On a single instance these guarantees collapse into one because the event log and the session state share memory. Across a migration they diverge: a client can successfully *resume the stream* on instance B (`200 OK`, events replay from the log) while the *session state* it depends on was never transferred, because the event log was replicated but the session store was not. The resumption succeeds; the session is hollow. The boundary condition is that stream resumption is treated as evidence of session recovery when it is only evidence of log recovery. ## What Was Observed A three-replica MCP deployment fronted by a round-robin LB. Client opens `POST /mcp` with `initialize`, receives `Mcp-Session-Id: s-7f2a`. Server A pins the session and opens an SSE stream; client consumes `id: 41` (a `tools/call` progress event) and goes idle. A rolling deploy drains server A. The client's SSE connection drops with a TCP reset at event `id: 41`. Client reconnects via `GET /mcp` with `Mcp-Session-Id: s-7f2a` and `Last-Event-ID: 41`; the LB routes to server B. Server B's shared event log (Redis stream) contains events up to `id: 47`, so B returns `200 OK` and replays `42..47`, including the terminal `result` for the tool call. The client believes the call completed and the session is intact. The failure surface: server B's *session store* — the in-memory map of `session_id → {negotiated protocol version, client capabilities, active subscriptions, pending server→client requests (sampling/roots elicitation), and the reverse-index of outstanding request IDs}` — was never replicated. It is process-local on A. On B, `s-7f2a` is unknown. B replays the log (a stateless read) but any *subsequent* client→server request on `s-7f2a` fails `404 Session not found`, and any server→client request that A had in flight (an elicitation awaiting user input at event 44) is silently orphaned — the client never receives it, and A's continuation handler was destroyed with the process. The client observes a session that "works" for reads but 404s on writes, and a tool call whose side effects (a file write) completed on A but whose elicitation gate never resolved, leaving a half-applied mutation. A second observed trace: the protocol version negotiated on A was `2025-03-26`; B's session store, had it existed, would default to `2025-06-18`. Because the store was absent, B did not reject the mismatched `MCP-Protocol-Version` header the client sent — it accepted the resume because resume path does not validate the session's negotiated version, only the event log's `Last-Event-ID` monotonicity. The version skew was masked until the next `tools/call`, which used a schema shape (`structuredContent`) the client could not parse under its negotiated version. ## Condition of Validity Resumption via `Last-Event-ID` is a valid recovery signal **only if** the following invariant holds: *the event log's high-water mark and the session store's high-water mark are transactionally co-committed, or the session store is itself reconstructable from the event log.* In the deployment above, neither held — the log was a separate Redis stream written by an async sidecar, the session store was process-local. The invariant that must be enforced: **`Last-Event-ID` resumption is admissible only when `session_store.version(session_id) >= event_log.last_replayed_id`, and the session store is addressable on the resuming instance.** If the session store is absent or its version trails the replayed event ID, the resume must be downgraded to a session re-establishment (fresh `initialize`), not a silent continuation. This invariant is *not* stated by the transport spec, which describes resumption as a stream-level concern and leaves session storage to the implementation. The gap is the spec's silence on the cross-instance case. ## Decision Boundary The server must decide, at the moment of a `GET /mcp` with both `Mcp-Session-Id` and `Last-Event-ID`, between three outcomes — and the choice is governed by a single check, not by whether the stream replays: 1. **Resume** (session store present on this instance, version ≥ replayed ID): replay events, continue. Safe. 2. **Re-establish** (session store absent, but event log has the events): do *not* replay as if continuing. Return `404` on the session (forcing client `initialize`) or, if the client opts in via a capability flag, replay the log but mark the session `re-initialized` and require the client to re-send its capability set before the next `tools/call`. The log replay is a *courtesy read*, not a session continuation. 3. **Refuse** (event log's last ID < `Last-Event-ID`, i.e., the client claims to have seen events the server never durably recorded — possible after a log truncation or a cross-region failover): return `409 Conflict` or a resumption error; do not fabricate continuity. The boundary is the *conjunction* of session-store presence and version monotonicity. A server that keys the decision on stream replay success alone (the common bug) will take branch 1 in the failure trace above and mask a hollow session. ## Operational Effect Downstream, the hollow-session state produces three concrete agent-layer failures: (a) **orphaned server→client requests** — an elicitation or sampling request issued by A before drain is never re-issued by B, so the client's agent loop waits on a future that will never resolve, and the tool call's side effect is half-applied; (b) **capability drift** — the client's negotiated capabilities (e.g., `sampling: {}`) are lost, so B's server-initiated requests are rejected by the client as unexpected, or B refuses to issue them, silently degrading the agent's tool surface; (c) **protocol-version skew** — a resumed stream under a stale negotiated version delivers event payloads shaped for a newer schema, and the client's parser either drops events or misinterprets `structuredContent`, compounding across the remaining stream. The architectural guardrail is to make the session store a first-class replicated object with a monotonic version, co-committed with the event log's append (or derived from it), and to gate `Last-Event-ID` resumption on that version — treating stream replay as necessary but never sufficient evidence of session continuity. ```python class HollowSessionResumeError(RuntimeError): """Raised when an MCP Streamable HTTP resume replays events but the session store on the resuming instance cannot satisfy the session version invariant. Signals that the caller must downgrade to session re-establishment, not silent continuation.""" def admit_resume( session_id: str, last_event_id: int, session_store: dict, # session_id -> {"version": int, "protocol": str, ...} event_log_last_id: int, ) -> dict: """Gate a GET /mcp resume on the co-commitment invariant. Admissible iff: - the session exists on THIS instance, and - session_store[session_id]["version"] >= last_event_id, and - the event log actually holds the events the client claims to have seen. """ if last_event_id > event_log_last_id: # Client claims events the server never durably recorded # (log truncation, cross-region failover, or a forged Last-Event-ID). raise HollowSessionResumeError( f"Last-Event-ID {last_event_id} exceeds durable log high-water " f"mark {event_log_last_id}; refusing to fabricate continuity." ) session = session_store.get(session_id) if session is None: # The exact failure trace: event log has the events, session store # does not. Replaying here would mask a hollow session. raise HollowSessionResumeError( f"Session {session_id!r} absent on resuming instance; " f"event log holds ids up to {event_log_last_id} but session " f"state was not migrated. Downgrade to re-establishment." ) if session["version"] < last_event_id: raise HollowSessionResumeError( f"Session {session_id!r} store version {session['version']} " f"trails replayed Last-Event-ID {last_event_id}; session state " f"is stale relative to the event log." ) return session def handle_get_resume(req) -> None: try: session = admit_resume( session_id=req.headers["Mcp-Session-Id"], last_event_id=int(req.headers["Last-Event-ID"]), session_store=req.app.state.session_store, event_log_last_id=req.app.state.event_log.last_id(), ) except HollowSessionResumeError as exc: # Force the client back to initialize() rather than replaying # events under a session this instance cannot honor. req.respond(status=404, body={"error": "session_not_found", "detail": str(exc)}) return if req.headers.get("MCP-Protocol-Version") != session["protocol"]: raise HollowSessionResumeError( f"Protocol skew on resume: client sent " f"{req.headers.get('MCP-Protocol-Version')!r}, session negotiated " f"{session['protocol']!r}." ) req.stream.replay_from(req.headers["Last-Event-ID"]) ```