# When must an instance resume an MCP HTTP-native SSE stream versus reinitialize the session **Date of Record:** 2026 November 14 **Scope:** Applies to MCP servers and clients using the HTTP-native transport (Streamable HTTP) where a server-initiated SSE channel carries notifications and server-to-client requests, and where the client may present a `Last-Event-ID` on reconnection. Does not apply to the legacy HTTP+SSE transport with a separate `/sse` and `/messages` endpoint pair, nor to stdio transports where there is no reconnection surface. ## Core Distinction There are two superficially similar recovery actions after an SSE stream drops, and they are not interchangeable: 1. **Stream resumption**: the client reopens the stream (typically `GET` on the MCP endpoint with `Accept: text/event-stream`) and presents `Last-Event-ID`. The server replays events after that ID on the *same logical stream*, and the session state (protocol version, negotiated capabilities, in-flight server requests, subscription set) is preserved. 2. **Session reinitialization**: the client treats the session as dead, discards its `Mcp-Session-Id`, and performs a fresh `initialize` handshake, re-negotiating capabilities and re-establishing subscriptions. The non-obvious boundary is this: **the presence of a valid `Mcp-Session-Id` is not sufficient to justify resumption, and the absence of a `Last-Event-ID` is not sufficient to justify reinitialization.** Resumption is valid only when the server can *prove* it still holds the resumable stream state for that session *and* that the event-ID namespace the client presents belongs to a stream the server has not retired. Otherwise the correct action is reinitialization — and a server that "helpfully" resumes against a stale or reused stream ID will silently drop notifications, because the replay cursor points into a sequence the server no longer maintains. ## What Was Observed A client maintained a long-lived `GET` SSE stream on an MCP HTTP-native endpoint. The server ran behind a load balancer with a 60s idle timeout and multiple backend replicas, with session affinity keyed on `Mcp-Session-Id` but *not* on the stream instance. On a rolling deploy, the replica holding the stream was drained. The client's connection reset, it reconnected to a different replica, and presented `Last-Event-ID: 4471` along with a still-valid `Mcp-Session-Id`. The new replica accepted the session ID (affinity cookie routed it there) and accepted the event ID — but its stream registry had been populated from a shared store that persisted only the *latest* event ID per session, not the event bodies. It responded `200 OK` with an empty replay and continued live streaming from the current head. The client interpreted the empty replay as "no missed events" and proceeded. Between the drain and the new replica's head, 14 notifications (including two `notifications/tools/list_changed` and one server-initiated `sampling/createMessage` request) were permanently lost. No error was surfaced at any layer. A second, distinct failure was observed in the opposite direction: a client that had *no* `Last-Event-ID` (first connection after a client-side process restart but with a persisted `Mcp-Session-Id`) reconnected, and the server rejected the GET with `400 Bad Request` because it required a resume cursor for any session it considered "established." The client then reinitialized, which was correct — but only by accident, because the server's error was interpreted as "session invalid" rather than "stream cursor missing." ## Condition of Validity Resumption is valid if and only if all of the following hold: - The server retains the *event log* (not merely the last ID) for the session's current stream, within its retention window. - The presented `Last-Event-ID` is a member of that log's ID space and is not ahead of the server's head (a cursor ahead of head indicates ID reuse across stream generations and must be rejected). - The session's negotiated state (capabilities, subscriptions, outstanding server requests) is still live on the serving replica or reconstructible from shared state. - The stream generation is unchanged: if the server retired the stream (e.g., on replica drain, on capability change, on explicit stream close), the event-ID namespace must be invalidated so that stale cursors cannot match. If any condition fails, the server must respond in a way that is *unambiguously* a reinitialization signal — `404 Not Found` for an unknown/retired session, or a distinct error for an invalid cursor — and must not return `200` with an empty or partial replay. The client, symmetrically, must treat a `200` with no replay as authoritative only when it presented a cursor the server acknowledged; an empty replay to a cursor the server cannot place is a protocol violation, not a "nothing missed" signal. ## Decision Boundary The decision is not "session ID valid → resume." It is a two-axis test: - **Stream identity**: does the server still own the stream generation the cursor refers to? - **Cursor placement**: is the cursor within the retained log for that generation? | Stream generation live | Cursor in retained log | Correct action | |---|---|---| | yes | yes | resume with replay from cursor | | yes | no (too old / evicted) | reinitialize; do not silently skip | | yes | cursor ahead of head | reinitialize; treat as ID reuse | | no (retired) | any | reinitialize; invalidate cursor namespace | | unknown session | any | reinitialize; `404` | The failure mode to guard against is the (yes, no) cell being answered with `200` and an empty body. That is the boundary where correctness is lost without any signal. ## Operational Effect When this boundary is respected, a rolling deploy or transient disconnect costs at most a bounded replay, and notification loss is converted into an explicit reinitialization with a fresh capability negotiation. When it is violated, the system exhibits *silent divergence*: the client believes it is subscribed and current, the server believes it replayed, and the gap is invisible until a downstream action depends on a missed `list_changed` or a dropped server-initiated request. The observable symptom is not an error but a stale tool list or a hung `sampling/createMessage` that the client never saw. Instrumentation should therefore count `resume_accepted_empty_replay` and `resume_cursor_unplaceable` separately; the first should be near zero, and any nonzero value is a correctness bug, not a performance metric. ```python class McpStreamResumeError(RuntimeError): """Raised when an SSE resume request cannot be honored safely.""" def __init__(self, session_id: str, last_event_id: str | None, reason: str): self.session_id = session_id self.last_event_id = last_event_id self.reason = reason super().__init__( f"cannot resume session={session_id!r} cursor={last_event_id!r}: {reason}" ) def decide_resume_action( session_id: str, last_event_id: str | None, *, session_live: bool, stream_generation_live: bool, retained_log_ids: set[str], head_event_id: str | None, ) -> str: # Unknown or retired session: never resume. if not session_live: raise McpStreamResumeError(session_id, last_event_id, "session unknown or retired") # Stream generation retired (drain, capability change, explicit close): # the cursor namespace is invalid; force reinitialization. if not stream_generation_live: raise McpStreamResumeError( session_id, last_event_id, "stream generation retired; cursor namespace invalid" ) # No cursor presented: this is a fresh stream, not a resume. if last_event_id is None: return "open_fresh_stream" # Cursor ahead of head implies ID reuse across generations: reject. if head_event_id is not None and _is_ahead(last_event_id, head_event_id): raise McpStreamResumeError( session_id, last_event_id, "cursor ahead of head; probable event-ID reuse" ) # Cursor not in retained log: cannot replay without loss. if last_event_id not in retained_log_ids: raise McpStreamResumeError( session_id, last_event_id, "cursor evicted from retained event log" ) return "resume_with_replay" def _is_ahead(cursor: str, head: str) -> bool: try: return int(cursor) > int(head) except ValueError: return False def handle_resume_request(session_id: str, last_event_id: str | None, server_state) -> int: try: action = decide_resume_action( session_id, last_event_id, session_live=server_state.session_live(session_id), stream_generation_live=server_state.stream_generation_live(session_id), retained_log_ids=server_state.retained_log_ids(session_id), head_event_id=server_state.head_event_id(session_id), ) except McpStreamResumeError as exc: # Force the client toward reinitialization; never answer with 200 + empty replay. server_state.metrics.increment("resume_rejected", reason=exc.reason) return 404 if "session unknown" in exc.reason else 409 if action == "resume_with_replay": server_state.metrics.increment("resume_with_replay") return 200 server_state.metrics.increment("open_fresh_stream") return 200 ```