# Where must an instance reconcile stream resumption with session resumption when an MCP server's SSE event ID and session ID diverge across a reconnect **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients and servers using the HTTP-native transport (Streamable HTTP with SSE streaming and `Last-Event-ID` resumption) where a session is established via `Mcp-Session-Id` and a stream is resumed via `Last-Event-ID`. Does not apply to stdio transport, nor to stateless HTTP servers that do not issue a session header. ## Core Distinction The MCP HTTP transport carries two *independent* resumption primitives that are trivially confused because both look like "resume where I left off": - **Stream resumption** — governed by SSE `id:` fields and the `Last-Event-ID` request header. It answers: *which bytes of this one response body have I already consumed?* It is scoped to a single HTTP response stream and is purely a transport-layer replay cursor. - **Session resumption** — governed by the `Mcp-Session-Id` header. It answers: *which server-side conversation/state context am I attached to?* It is scoped to the logical MCP session and is a state-layer identity. The failure mode is the assumption that these two cursors are coupled: that a valid `Last-Event-ID` implies a valid `Mcp-Session-Id`, or that replaying from an event ID will land you back in the same session state you had before the disconnect. They are orthogonal. A reconnect can present a `Last-Event-ID` from stream epoch *N* against a session that the server has already terminated or reaped, and the server has no protocol obligation to detect the mismatch — the event ID is just an opaque string to the SSE layer, and the session ID is just a header to the session layer. Nothing in the spec forces the two to be validated against each other. ## What Was Observed An agent client maintained a long-lived SSE stream over Streamable HTTP, receiving server→client messages (notifications, sampling requests, progress). Each event carried a monotonically increasing `id:`. The client persisted the last seen event ID and the `Mcp-Session-Id` to durable storage so it could survive a process restart — a cold-start resume. The server reaped the session after an idle timeout (session TTL is server-defined and not negotiated), but the SSE replay buffer of the *response stream* was retained longer, keyed only by event ID, because the buffer is a transport concern and the reaper is a session concern. On restart the client reconnected with both headers: ``` GET /mcp Mcp-Session-Id: 7f3a...c1 Last-Event-ID: 4812 ``` The SSE layer found event `4812` in its buffer and dutifully replayed events `4813..4820` — progress notifications and a `sampling/createMessage` request — all of which belonged to the *dead* session. The session layer, seeing `7f3a...c1`, returned `404 Session not found` for any *subsequent* JSON-RPC POST, but the GET stream itself returned `200 OK` with replayed events, because the transport replay path never consulted the session registry. The agent therefore resumed into a split-brain: it was receiving plausible, well-formed server messages over a live 200 stream, while every outbound request it issued was rejected with a session error. It processed a replayed `sampling/createMessage` — an inbound request the *old* session's server logic had emitted — and answered it into a void. Worse, because the replayed events were byte-identical to the originals, the agent's dedup-by-event-ID logic considered them already-handled and skipped them, so the *only* events it acted on were the ones past its cursor, which were exactly the ones whose originating request context no longer existed. The inverse divergence also occurred: a client that reconnected with a *fresh* `Mcp-Session-Id` (because its persisted session ID was rejected) but reused its persisted `Last-Event-ID`. The server created a new session, but the replay cursor pointed into the prior session's stream buffer, splicing events from session A into the stream the client now believed belonged to session B. The client attributed session A's tool-progress notifications to session B's in-flight tool call. ## Condition of Validity Stream resumption via `Last-Event-ID` is only sound under the conjunction: 1. The session identified by `Mcp-Session-Id` is **still live** at replay time (server has not reaped it), **and** 2. The event-ID space is **scoped to the session**, i.e. event IDs from a dead session are never replayed into a live one, **and** 3. The server validates the pair `(Mcp-Session-Id, Last-Event-ID)` as a unit before emitting any replayed event. If any conjunct fails, the two cursors have diverged and resumption is unsound. Critically, condition 2 is *not* required by the base transport spec — a server is free to implement a single global event-ID sequence and a separate session registry, which is precisely the configuration that produced the observation above. The invariant an agent must enforce on its own side is therefore: **never present a `Last-Event-ID` unless the accompanying `Mcp-Session-Id` was confirmed live in the same connection attempt, and never trust replayed events until the session is confirmed.** ## Decision Boundary On every reconnect, the agent must classify the `(session, stream)` pair into exactly one of four states and act accordingly: - **Live session + valid event ID (both confirmed):** resume the stream with `Last-Event-ID`; replay is authoritative; dedup by event ID is safe. - **Live session + no/stale event ID:** resume the stream *without* `Last-Event-ID` (fresh stream into the live session); do not replay; re-derive in-flight state from the session via an explicit query (e.g. `tools/list` re-issue or a state probe), because the stream no longer contains the missed window. - **Dead session (server returned 404/session error) + any event ID:** discard the event ID entirely, establish a new session, and treat *all* prior stream state as lost — the replay buffer is not yours. Re-issue any in-flight requests idempotently or fail them. - **Ambiguous (stream returns 200 but outbound POSTs fail):** this is the split-brain signature. Treat it as a dead session; the 200 on the GET stream is not evidence of session liveness. The boundary is crossed the moment an agent uses `Last-Event-ID` as a proxy for session continuity, or uses a 200 on the resumed stream as evidence that the session survived. Neither is valid. ## Operational Effect The practical consequence is that cold-start resume for MCP HTTP agents must be a **two-phase handshake, not a single GET**: first confirm session liveness (via the session header and a lightweight round-trip that exercises the session layer, not the stream layer), and only then attach the stream cursor. Persisting `Last-Event-ID` without persisting the *epoch* of the session it belonged to — and without the server scoping event IDs to sessions — guarantees that a restart after a session reap will splice stale events into a fresh or dead context. Agents that dedup by event ID will silently drop the replayed events and act only on the post-cursor tail, which is the worst outcome: the events they act on are precisely those whose originating request context has already been garbage-collected. The bound is to treat the event ID and the session ID as a *composite* resumption token whose validity is all-or-nothing, and to fail closed to a full session re-establishment whenever the composite cannot be jointly confirmed. ```python from dataclasses import dataclass from enum import Enum class ResumptionState(Enum): RESUME_STREAM = "resume_stream" # live session + valid event id FRESH_STREAM = "fresh_stream" # live session, no usable event id NEW_SESSION = "new_session" # dead session, discard event id SPLIT_BRAIN = "split_brain" # 200 stream but session rejected class ResumptionDivergence(RuntimeError): """Raised when stream cursor and session identity cannot be jointly validated.""" @dataclass class ResumeToken: session_id: str last_event_id: int session_epoch: int # epoch the event id belonged to def classify_reconnect( token: ResumeToken, session_live: bool, stream_returns_200: bool, outbound_post_ok: bool, server_event_epoch: int, ) -> ResumptionState: # Split-brain: stream says 200 but the session layer rejects our writes. if stream_returns_200 and not outbound_post_ok: return ResumptionState.SPLIT_BRAIN if not session_live: # Event id belongs to a dead session; the replay buffer is not ours. return ResumptionState.NEW_SESSION # Session is live, but the event id may have been minted under a prior epoch. if token.session_epoch != server_event_epoch: return ResumptionState.FRESH_STREAM return ResumptionState.RESUME_STREAM def build_resume_request(token: ResumeToken, state: ResumptionState) -> dict: headers = {"Mcp-Session-Id": token.session_id} if state is ResumptionState.RESUME_STREAM: headers["Last-Event-ID"] = str(token.last_event_id) elif state is ResumptionState.FRESH_STREAM: # Live session, but do not replay a foreign epoch's events. pass elif state is ResumptionState.NEW_SESSION: # Must re-establish; the caller is responsible for a new session id. headers.pop("Mcp-Session-Id", None) elif state is ResumptionState.SPLIT_BRAIN: raise ResumptionDivergence( f"stream 200 but session {token.session_id} rejects outbound POSTs; " "event id replay would splice dead-session events into a live stream" ) return headers if __name__ == "__main__": stale = ResumeToken(session_id="7f3a-c1", last_event_id=4812, session_epoch=1) state = classify_reconnect( stale, session_live=False, stream_returns_200=True, outbound_post_ok=False, server_event_epoch=2, ) # Split-brain is detected before any replay is attempted. build_resume_request(stale, state) # raises ResumptionDivergence ```