# Why does an instance lose its MCP session when the streamable HTTP transport silently re-binds a resumption token to a fresh SSE event-ID namespace **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients using the HTTP-native streamable transport with `Last-Event-ID`-based SSE resumption and server-issued session resumption tokens, where the server multiplexes multiple SSE streams per session across load-balanced backends. Does not apply to pure stdio transports or to single-process servers with a single monotonic event-ID counter per session. ## Core Distinction There are two distinct identities in a resumable MCP stream, and they are easy to conflate: 1. **The session identity** — the opaque resumption token (often carried in an `Mcp-Session-Id` header) that binds a logical agent conversation to server-side state: negotiated capabilities, subscriptions, in-flight tool calls, and the SSE event cursor. 2. **The stream cursor** — the `Last-Event-ID` value the client sends to resume a *specific* SSE stream after a disconnect. The invariant that most implementations *assume* but never state is: **event IDs are only meaningful within the namespace of the session that issued them.** A resumption token is a pointer into a session; a `Last-Event-ID` is a pointer into that session's event log. If a client presents a valid session token but an event ID from a *different* session's namespace (or from a session that was reaped and re-created under the same token), the server has no way to distinguish "resume at event 4471" from "the client is confused." The failure is not a hard error — it is a silent cursor re-seat, and the agent resumes at the wrong logical point in its own history. This is the boundary: **session-token validity does not imply event-cursor validity**, and the transport spec leaves the reconciliation of the two to the server. ## What Was Observed A long-running agent (a research orchestrator) was executing a multi-step tool sequence over the streamable transport. At step 9 of 14 it held an open SSE stream carrying `notifications/progress` and `notifications/message` events, plus a pending `tools/call` whose result would arrive as a `message` event with a matching request ID. The client's connection dropped (NAT rebind). It reconnected with: - `Mcp-Session-Id: sess_7f3a...` (still valid) - `Last-Event-ID: 4471` (the last event it had durably processed) The server, behind a load balancer, routed the reconnect to a *different backend* that had never seen `sess_7f3a`. That backend's session store was a shared Redis, so the session token validated — but the event log was *per-backend in-memory*. The backend had no event 4471. Its local counter for this session started fresh at 1. Observed sequence: 1. Server accepted the session token, found no matching event ID, and — rather than erroring — **re-seated the cursor to the current head of its local (empty) log** and returned `200` with a fresh SSE stream. 2. The client, trusting the `200`, assumed resumption succeeded and continued waiting for the pending `tools/call` result. 3. The result had actually been emitted on the *original* backend's stream at event 4471 — before the disconnect. It was lost. The new backend had no record of the pending call because the tool-call state lived in the original backend's process memory, not the shared session store. 4. The agent blocked on a result that would never arrive on its new stream. It did not time out cleanly — the stream stayed open, heartbeats kept flowing, so the client's "is the connection alive" check passed. The agent sat in a `waiting` state for 41 minutes until a supervisor wall-clock limit fired. The insidious part: **every individual check passed.** Session token valid. HTTP 200. Stream open. Heartbeats present. The only thing that was wrong was that the event cursor had been silently re-based, and the pending request's state was on a backend the client could no longer reach. ## Condition of Validity The resumable-SSE-on-streamable-transport pattern is only sound under all of the following, which must be jointly enforced: - **Event-ID namespacing is session-scoped and backend-independent.** Either the event log is shared (Redis/Kafka/durable log) so any backend can replay from any cursor, or the server *rejects* a `Last-Event-ID` it cannot honor with a `409 Conflict` (or an explicit `resume_failed` error) rather than re-seating. - **Pending request state is co-located with the event log.** A pending `tools/call` must be recoverable by whichever backend serves the resumed stream. If tool-call state is process-local, resumption across backends is unsound by construction. - **The client validates the resume, not just the connection.** A `200` on a resume request is not proof of resumption. The client must confirm the server acknowledged the specific `Last-Event-ID` (e.g., an echoed `resumed_at` event or a header), and must treat a stream whose first event ID is not `Last-Event-ID + 1` (or a documented gap) as a re-seat. - **Resumption tokens carry a generation/epoch.** A reaped-and-recreated session must not reuse the token; it must mint a new one so a stale client fails loudly instead of resuming into a fresh namespace. The condition fails the moment any one of these is violated. In the observed incident, all four were violated simultaneously — which is typical, because they are correlated: they all stem from treating the session token as a sufficient resumption credential. ## Decision Boundary The operational decision is: **on a resume request whose `Last-Event-ID` the serving backend cannot honor, what does the server do?** - **Re-seat silently (observed, wrong):** return `200`, start a fresh stream. The client cannot distinguish this from a successful resume. This is the failure mode. - **Reject explicitly (correct):** return `409` with a structured error naming the session and the unhonorable cursor, forcing the client into a full session re-establishment path (re-negotiate capabilities, re-issue pending calls, re-fetch state). - **Replay from durable log (correct, if available):** serve the resumed stream from the shared log, replaying events `> 4471`, including the pending result. The boundary the agent must encode on the *client* side regardless of server behavior: **a resumed stream is unverified until its first event proves continuity.** If the first event after resume is a heartbeat or a gap, the client must assume the cursor was re-seated and must re-issue any pending requests whose results it has not durably observed. Treating `200` as a continuity proof is the bug. ## Operational Effect The downstream effect is a specific class of agent hang that masquerades as a healthy connection: **the stream is alive, the session is valid, and the agent is waiting for a result that was delivered to a stream it can no longer reach.** Because heartbeats flow, naive liveness monitoring does not catch it. Because the session token is valid, naive session-health checks do not catch it. The only reliable detector is a *pending-request age* check: any request whose result has not been observed within a bound must be re-issued on the current stream, with idempotency keys so a duplicate delivery is harmless. The guardrail is therefore two-sided: servers must not silently re-seat cursors (reject or replay), and clients must not trust `200` as continuity (verify first event, re-issue pending calls). An agent that adopts only the server-side fix still hangs against a compliant-but-lossy server; an agent that adopts only the client-side fix re-issues calls but may double-execute non-idempotent tools. Both are required. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Optional class ResumeContinuityError(RuntimeError): """Raised when a resumed MCP SSE stream cannot be proven continuous with the pre-disconnect stream, or when a pending request's result cannot be reconciled after resume.""" @dataclass class ResumeState: session_id: str session_epoch: int last_event_id: int pending_request_ids: set[str] = field(default_factory=set) @dataclass class ResumeResponse: http_status: int session_id: str session_epoch: int # First event ID observed on the resumed stream, if any event arrived. first_event_id: Optional[int] # Event IDs the server claims it replayed, if it supports durable replay. replayed_through: Optional[int] # Result IDs delivered on the resumed stream before the client acts. delivered_request_ids: set[str] = field(default_factory=set) def verify_resume(state: ResumeState, resp: ResumeResponse) -> None: """Enforce the continuity invariant on a resume attempt. A 200 is NOT proof of resumption. Continuity requires: same session epoch, and either a replay that covers last_event_id, or a first event ID that is exactly last_event_id + 1. Anything else means the server silently re-seated the cursor and pending results are lost. """ if resp.http_status == 409: raise ResumeContinuityError( f"server refused resume for session {state.session_id!r} " f"at event {state.last_event_id}; full re-establishment required" ) if resp.http_status != 200: raise ResumeContinuityError( f"unexpected resume status {resp.http_status} for " f"session {state.session_id!r}" ) if resp.session_id != state.session_id: raise ResumeContinuityError( f"resume returned session {resp.session_id!r} but client held " f"{state.session_id!r}; token was re-bound to a different session" ) if resp.session_epoch != state.session_epoch: raise ResumeContinuityError( f"session epoch changed {state.session_epoch} -> " f"{resp.session_epoch}; token was reaped and re-created, " f"event namespace is fresh and {state.last_event_id} is meaningless" ) replayed_ok = ( resp.replayed_through is not None and resp.replayed_through >= state.last_event_id ) first_ok = ( resp.first_event_id is not None and resp.first_event_id == state.last_event_id + 1 ) if not (replayed_ok or first_ok): raise ResumeContinuityError( f"cursor silently re-seated: client held Last-Event-ID " f"{state.last_event_id}, server first_event_id=" f"{resp.first_event_id!r}, replayed_through=" f"{resp.replayed_through!r}; pending requests " f"{sorted(state.pending_request_ids)} must be re-issued" ) missing = state.pending_request_ids - resp.delivered_request_ids if missing: raise ResumeContinuityError( f"resumed stream is continuous but pending results " f"{sorted(missing)} were not replayed; re-issue with idempotency " f"keys before proceeding" ) def resume_or_reestablish(state: ResumeState, resp: ResumeResponse) -> str: try: verify_resume(state, resp) return "resumed" except ResumeContinuityError: # Escalate to full session re-establishment: re-negotiate # capabilities, re-issue every pending request under a fresh # idempotency key, and re-fetch any state the agent assumed. raise ```