# What structural signals indicate SSE resumption divergence in MCP streamable-HTTP transports: the `Last-Event-ID` / session-token split-brain **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers exposing the streamable-HTTP transport with resumable Server-Sent Events fallback, where a client may reconnect using a `Last-Event-ID` cursor plus an `Mcp-Session-Id` header. Does not apply to pure stdio transports or to stateless HTTP servers that do not issue session identifiers. ## Core Distinction The failure mode is not "the SSE stream dropped." That is a routine, expected event. The distinction that matters operationally is between **cursor continuity** (the `Last-Event-ID` the client replays) and **session continuity** (the `Mcp-Session-Id` the server uses to look up server-side state). These are two independent keys into two independent state stores, and the MCP streamable-HTTP spec lets a client present a *valid cursor* against an *invalidated session* — or a *valid session* with a *stale cursor* — without any protocol-level error at the transport layer. The stream resumes, HTTP returns `200`, events flow, and the agent silently diverges from the server's authoritative event log. The non-obvious invariant is this: **a successful SSE resume (`200 OK` with an event stream) is not evidence that the agent's view of the session is consistent with the server's.** The transport layer will happily honor a cursor from a previous session incarnation if the event-ID namespace is monotonic across session lifetimes — which it frequently is, because implementers reuse a global event counter. That is the split-brain. ## What Was Observed A tool-calling agent maintained an MCP session against a streamable-HTTP server. The server was redeployed mid-task; the new instance had an empty session store but preserved a monotonically increasing global event counter (persisted in a shared Redis key) to keep log ordering stable across restarts. The agent's SSE connection dropped during the redeploy. The agent's reconnect logic did what the spec permits: it re-issued `GET /mcp` with `Last-Event-ID: 4187` and `Mcp-Session-Id: sess_9f2a...`. Trace of what followed: 1. Server received the reconnect. Session lookup for `sess_9f2a...` returned `null` (post-restart, store empty). 2. Per a common-but-wrong implementation, the server treated "unknown session" as "new session" rather than rejecting, minted `sess_c1d4...`, and set it in the response header. 3. Server evaluated `Last-Event-ID: 4187` against its *global* counter, which was now at `4201` after replaying buffered events. It found `4187 < 4201`, concluded the cursor was "behind," and replayed events `4188..4201` from the shared log. 4. Events `4188..4201` belonged to *other* sessions — including a different agent's tool-result payloads and one `notifications/tools/list_changed` event. 5. The agent accepted the new session ID (it had no policy to reject a session-ID change on resume), ingested the foreign events into its context, and continued its task with a tool registry that had silently changed and a context window now containing another tenant's tool results. No error was raised at any layer. HTTP `200`. Valid SSE framing. Valid JSON-RPC messages. The divergence was only detectable by comparing the session-ID the client *sent* against the session-ID the server *returned* — a comparison the client never made. A second, subtler variant: the session store *did* survive (sticky routing held), but the event buffer had been trimmed to a fixed depth (last 500 events). The client's cursor `Last-Event-ID: 1203` was 800 events behind the buffer floor. The server, unable to replay, silently started the stream at the buffer head (`1704`) without signaling the gap. The agent resumed mid-stream with a hole in its event history and no `gap` marker. Tool-call/result pairing broke: it had issued a `tools/call` whose result lived in the trimmed range, so it waited forever for a response that had already been delivered and discarded. ## Condition of Validity The resume-with-cursor mechanism is only sound under a conjunction of conditions, and each is independently violable: - **Session-ID stability:** the server MUST reject a resume whose `Mcp-Session-Id` is unknown, returning `404` (session terminated) rather than minting a new session. If it mints, cursor and session are decoupled and the client cannot detect the swap except by header comparison. - **Event-ID namespacing:** event IDs MUST be scoped to the session, or the server MUST validate that a replayed event belongs to the resuming session. A global monotonic counter shared across sessions violates this and is the root enabler of cross-session replay. - **Buffer-floor signaling:** when the requested `Last-Event-ID` precedes the retained buffer, the server MUST emit an explicit gap notification (or close with a resumable-error code) rather than silently advancing the cursor. Silent advance converts a detectable loss into an undetectable one. - **Client-side header assertion:** the client MUST compare the `Mcp-Session-Id` in the resume response against the one it sent and abort on mismatch. Without this, the client is blind to server-side session re-minting. The mechanism is *invalid* — do not trust resume — whenever any of these four is unverified against the specific server implementation. It is *valid* only when all four hold and the client actively asserts the session-ID equality. ## Decision Boundary The boundary is: **does the client treat the resume response as authoritative-continuation or as candidate-continuation?** - If the server returned the *same* `Mcp-Session-Id` the client sent, and the first replayed event ID equals `Last-Event-ID + 1` (contiguous), treat as authoritative-continuation: proceed. - If the server returned a *different* session ID, the client MUST treat the stream as a fresh session, discard any in-flight tool-call expectations tied to the old session, and re-issue capability negotiation (`initialize` / `tools/list`) before any further `tools/call`. Continuing to use the old tool registry against a new session is the exact divergence above. - If the first replayed event ID is *greater* than `Last-Event-ID + 1`, a gap exists. The client MUST NOT resume silently; it must re-fetch authoritative state (re-`tools/list`, re-query any pending tool results by request ID) rather than assume the missing range was benign. - If the server returned `404`, the session is dead; the client must re-initialize, not resume. The dangerous default — "resume succeeded, keep going" — collapses all four cases into one and is precisely what produces the split-brain. ## Operational Effect Downstream of a silent resume divergence, the agent exhibits three characteristic symptoms that look like reasoning failures but are state-continuity failures: 1. **Phantom tool waits:** the agent blocks on a `tools/call` result that was delivered in the trimmed/gapped range. The model's reasoning is fine; its event ledger has a hole. It will often "recover" by hallucinating a plausible result or by re-issuing the call, causing duplicate side effects. 2. **Registry drift:** after a cross-session replay, the agent's cached `tools/list` no longer matches the server's actual tool set (a `list_changed` notification was consumed from another session or lost in a gap). Subsequent calls fail schema validation or, worse, hit a renamed tool with old arguments. 3. **Context contamination:** replayed foreign events enter the context window, consuming token budget and injecting tool results the agent attributes to its own task. In multi-tenant servers this is a data-isolation breach, not merely a correctness bug. The guardrail that bounds all three is a **resume assertion gate**: a single check at the reconnect boundary that validates session-ID equality and cursor contiguity before any event is admitted to the agent's state. It must run before the first replayed event is processed, because once a foreign or gapped event is in context, no downstream check can distinguish it from legitimate history. ```python import json from dataclasses import dataclass class ResumeDivergenceError(RuntimeError): """Raised when an SSE resume would admit events that break session/cursor continuity.""" pass @dataclass class ResumeResponse: sent_session_id: str returned_session_id: str last_event_id: int # cursor the client sent first_replayed_event_id: int | None # None if no events replayed http_status: int def assert_resume_continuity(resp: ResumeResponse) -> None: """ Gate every MCP streamable-HTTP SSE resume through this assertion before admitting any replayed event into agent state. """ if resp.http_status == 404: # Session terminated server-side: must re-initialize, never resume. raise ResumeDivergenceError( f"session {resp.sent_session_id} terminated (404); re-initialize required" ) if resp.http_status != 200: raise ResumeDivergenceError( f"unexpected resume status {resp.http_status}" ) # Invariant 1: server must not re-mint a session on resume. if resp.returned_session_id != resp.sent_session_id: raise ResumeDivergenceError( "session-ID swap on resume: sent " f"{resp.sent_session_id!r} but server returned " f"{resp.returned_session_id!r}; treating as fresh session, " "discarding in-flight tool-call expectations and re-negotiating" ) # Invariant 2: replayed stream must be contiguous with the cursor. if resp.first_replayed_event_id is not None: expected = resp.last_event_id + 1 if resp.first_replayed_event_id != expected: raise ResumeDivergenceError( f"cursor gap: expected first event {expected}, " f"got {resp.first_replayed_event_id}; " "buffer floor exceeded or cross-session replay — " "must re-fetch authoritative state (tools/list, pending results)" ) # If no events replayed, contiguity is vacuously satisfied. def handle_resume(resp: ResumeResponse, agent_state: dict) -> None: try: assert_resume_continuity(resp) except ResumeDivergenceError as e: # Fail closed: do not admit events; force re-initialize path. agent_state["needs_reinit"] = True agent_state["divergence_reason"] = str(e) raise agent_state["resume_ok"] = True ```