# How does an instance detect a silently rolled-back SSE resume cursor when an MCP HTTP-native streamable transport renegotiates session headers mid-stream? **Date of Record:** 2026 November 22 **Scope:** Applies to MCP servers and clients using the HTTP-native streamable transport (POST for requests, GET for the server-to-client SSE channel) with `Last-Event-ID`-based resumption and `Mcp-Session-Id` header negotiation. Does not apply to stdio transports, WebSocket transports, or stateless SSE endpoints that do not issue event IDs. ## Core Distinction The distinction that matters is between **transport-level resume success** and **application-level continuity**. In the MCP HTTP-native streamable transport, the client resumes a broken SSE stream by reconnecting with the `Last-Event-ID` header set to the last event it durably observed, while also carrying the `Mcp-Session-Id` header that binds the stream to a server-side session. Most implementers treat a `200 OK` on the reconnect plus a fresh `event:`/`data:` frame as "resumed." That is a transport observation, not a continuity guarantee. The non-obvious failure is this: when a server renegotiates or rotates the session between disconnect and reconnect—because the original session expired, was evicted under memory pressure, was load-balanced to a different replica, or was explicitly re-created—the server may **accept the reconnect under a new session ID and replay from a cursor it silently clamped** to the new session's event log start. The client sees a valid stream, valid events, and a `Mcp-Session-Id` header that has changed value. If the client does not compare the returned session ID against the one it sent, and does not verify that the first replayed event ID is contiguous with its `Last-Event-ID`, it will splice a *different* event history onto its own, producing a state continuity violation that looks exactly like normal operation. ## What Was Observed A tool-calling agent held an open SSE stream against an MCP server exposing a `filesystem` server. The client had durably observed events up to `Last-Event-ID: 8841` (a `notifications/tools/list_changed` plus a partial `CallToolResult` chunk sequence). The connection dropped (idle proxy timeout at 60s). The client reconnected with: ``` GET /mcp HTTP/1.1 Mcp-Session-Id: sess_7f3a Last-Event-ID: 8841 Accept: text/event-stream ``` The server had, in the intervening 90 seconds, evicted `sess_7f3a` (LRU cap of 64 sessions, and a burst of parallel subagents pushed it out). On reconnect the server's session-resolution middleware did not return `404`; it **lazily provisioned a new session** `sess_a91c`, attached the stream, and—because the resume logic looked up `Last-Event-ID` against the *new* session's event ring buffer (which started at ID `0` but had only emitted up to `12`)—clamped the replay cursor to the head of the new buffer. The server then emitted the header `Mcp-Session-Id: sess_a91c` on the SSE response and began streaming from event `1`. The client's continuity logic checked only: (a) HTTP 200, (b) `Content-Type: text/event-stream`, (c) presence of `data:` frames. All passed. The client resumed its reasoning loop believing events `8842+` of `sess_7f3a` were arriving. What actually arrived were events `1..12` of `sess_a91c`—a completely different event namespace whose IDs happened to be numerically *lower* than the client's cursor. Because the client's dedup layer keyed on event ID equality rather than monotonicity, IDs `1..12` were treated as "old, already seen, drop." The client silently discarded the entire replayed history and then hung, because the *new* session had nothing more to emit and the client's own pending tool call (issued under `sess_7f3a`) would never resolve. The observed signature, in order: 1. Reconnect returns `200` with a `Mcp-Session-Id` header whose value differs from the one sent. 2. First replayed event ID is **not** `Last-Event-ID + 1`; it is either `1`, `0`, or some value `< Last-Event-ID`. 3. Event IDs are non-monotonic across the splice point. 4. A previously issued `CallToolRequest` (JSON-RPC id `42`) never receives its matching response, because the response was emitted on the dead `sess_7f3a` stream. ## Condition of Validity The continuity invariant that must hold for a resume to be *safe* is: > A resumed stream is continuous with the prior stream **iff** (1) the `Mcp-Session-Id` on the response equals the `Mcp-Session-Id` on the request, **and** (2) the first event's `id` is exactly `Last-Event-ID + 1` under the server's monotonic event-ID contract, **and** (3) no event ID in the replay window is `≤ Last-Event-ID`. If any of these fail, the resume is a *splice*, not a continuation, and the client MUST treat all in-flight JSON-RPC requests bound to the old session as failed (not pending). The failure is bounded to the window between disconnect and reconnect; it does not retroactively corrupt events the client already durably processed. But it does invalidate every request whose response was expected on the old stream. This condition is *not* satisfied by the transport's default behavior. HTTP-native streamable transport in MCP does not mandate that a server reject a resume against an unknown session with `404`; lazy re-provisioning is permitted and common in horizontally scaled deployments. The invariant must therefore be enforced client-side. ## Decision Boundary The boundary is: **does the client trust the transport's `200`, or does it validate the session identity and cursor contiguity?** The two produce opposite behaviors on the same wire bytes. - Below the boundary (naive client): accepts `200`, keys dedup on ID equality, hangs on orphaned requests. This is the observed failure. - At the boundary (validating client): on reconnect, compares response `Mcp-Session-Id` to request `Mcp-Session-Id`. If unequal, it does **not** attach the new stream to the old logical session. Instead it: (a) fails all pending JSON-RPC requests bound to the old session with a distinguishable error, (b) treats the new session as a fresh logical session requiring re-initialization (`initialize` handshake), and (c) re-issues only the requests that are idempotent or explicitly marked retryable. - The cursor-contiguity check is a second gate: even if the session ID matches, if the first replayed `id` is not `Last-Event-ID + 1`, the client must treat the gap as a *lost event window* and trigger a full state resync (re-list tools, re-read any resources it was tracking) rather than assuming the missing events were benign. The boundary is sharp because the wire signal is unambiguous—a differing header value, a non-contiguous first ID—but the *interpretation* is a policy choice the transport spec leaves open. An agent that does not encode the policy will silently splice. ## Operational Effect The downstream effect is a **continuity violation that masquerades as a healthy stream**. The agent's reasoning loop continues, its dedup layer drops the replayed events as stale, and its pending tool call never resolves. From the outside, the agent appears to be "thinking" (stream open, no error) while it is actually deadlocked on a response that will never arrive. If the agent has a timeout on tool calls, it eventually errors; if it does not, it hangs until the outer orchestration layer's own timeout fires—often minutes later, after burning token budget on retries against the wrong session. The guardrail is a **session-identity and cursor-contiguity validator** at the transport boundary, applied on every reconnect, before any event is handed to the reasoning layer. It must fail closed: a mismatched session ID or a non-contiguous first event ID is a hard error that invalidates the logical session, not a warning that lets the stream through. The validator must also propagate the invalidation to the request layer so orphaned JSON-RPC requests are failed deterministically rather than left pending. ```python import json from dataclasses import dataclass class SessionSpliceError(RuntimeError): """Raised when an SSE resume silently splices a different session's event history.""" @dataclass(frozen=True) class ResumeContext: requested_session_id: str last_event_id: int def validate_resume( ctx: ResumeContext, response_session_id: str | None, first_event_id: int | None, first_event_data: str | None, ) -> None: # Gate 1: session identity. A server that lazily re-provisioned a session # will echo a different Mcp-Session-Id. This is a splice, not a resume. if response_session_id is None: raise SessionSpliceError( f"resume for session {ctx.requested_session_id!r} returned no " f"Mcp-Session-Id header; cannot confirm continuity" ) if response_session_id != ctx.requested_session_id: raise SessionSpliceError( f"session identity changed on resume: sent " f"{ctx.requested_session_id!r}, got {response_session_id!r}; " f"replayed events belong to a different event namespace" ) # Gate 2: cursor contiguity. Even under the same session, a clamped or # truncated event log yields a first ID that is not Last-Event-ID + 1. if first_event_id is None: raise SessionSpliceError( f"resume for session {ctx.requested_session_id!r} returned an " f"event frame with no id; cannot verify contiguity" ) if first_event_id != ctx.last_event_id + 1: raise SessionSpliceError( f"non-contiguous resume: Last-Event-ID={ctx.last_event_id}, " f"first replayed id={first_event_id}; expected " f"{ctx.last_event_id + 1}. Events in " f"[{first_event_id}, {ctx.last_event_id}] are either lost or " f"belong to a different session." ) # Gate 3: payload sanity. A replayed event that parses but references a # JSON-RPC id not bound to this session is also a splice signal. if first_event_data is not None: try: payload = json.loads(first_event_data) except json.JSONDecodeError as exc: raise SessionSpliceError( f"unparseable first replayed event in session " f"{ctx.requested_session_id!r}: {exc}" ) from exc if payload.get("session") not in (None, ctx.requested_session_id): raise SessionSpliceError( f"first replayed event carries session " f"{payload.get('session')!r}, not " f"{ctx.requested_session_id!r}" ) ```