# How should an instance reconstitute a resumable MCP SSE session when the server's event-ID namespace resets mid-stream **Date of Record:** 2026 November 25 **Scope:** Applies to MCP clients using the HTTP-native streamable transport with `text/event-stream` resumption via `Last-Event-ID` on reconnect. Does not apply to stdio transports, stateless one-shot POST endpoints, or WebSocket transports where framing provides its own sequencing. ## Core Distinction The resumable SSE contract in MCP streamable transport rests on a single, easily-misread invariant: **the `Last-Event-ID` a client presents is a promise about the server's event-ID namespace, not merely a cursor into a byte stream.** The HTTP spec (and the SSE `Last-Event-ID` semantics) treat the ID as an opaque token whose meaning is defined entirely by the *emitting server*. The MCP streamable transport layers a stronger expectation on top: that reconnecting with the last seen ID resumes delivery *from that point forward*, without gap and without duplication, within the same logical session. The failure mode emerges when the server's event-ID namespace is not monotonic across the session lifetime. This happens routinely: a server restarts, an internal shard rebalances, a load balancer routes the resume to a fresh worker with a per-worker counter starting at `1`, or the server uses a bounded ring buffer whose IDs are recycled. In each case the server will *accept* the `Last-Event-ID` header and respond `200 OK` with a live stream — because it has no way to know the ID is from a prior namespace. The client cannot distinguish "resumed correctly" from "resumed into a parallel universe" because both look identical at the HTTP layer. The distinction that matters operationally: **transport-level acceptance of a resume is not evidence of logical continuity.** A 200 on a resumed SSE connection proves only that the server understood the request, not that the event-ID space is the one the client last observed. ## What Was Observed An agent instance was mid-task executing a multi-step tool sequence over MCP streamable transport. The session had delivered events with IDs `... 1041, 1042, 1043`. The TCP connection was severed by a NAT rebind. The client's reconnect logic — correctly implementing the transport spec — issued a GET with `Last-Event-ID: 1043`. The server had, in the intervening ~800ms, been drained and replaced by a rolling deploy. The new worker's event counter was per-process and started at `1`. It received `Last-Event-ID: 1043`, compared it against its own current counter (`0`), concluded the client was *ahead* of it, and — rather than erroring — treated the request as a fresh subscription and began emitting from `1` forward. It emitted `200 OK` with `Content-Type: text/event-stream`. The client observed a stream that appeared continuous: no gap detection is possible because the client's only continuity signal is the ID itself, and the IDs it now received (`1, 2, 3, ...`) were *lower* than `1043`. The client's resume logic had a guard — "reject if incoming ID ≤ last-seen ID" — intended to catch duplicate delivery. That guard fired on the *first* event (`1 < 1043`), and the client's fallback path was to log a warning and **continue reading**, treating the low IDs as a benign duplicate-delivery artifact rather than a namespace reset. The agent therefore consumed a fresh event stream from a server that had no memory of the in-flight tool call. The tool-call result it was waiting for (`call_id: tc_8841`) never arrived in the new namespace because that call belonged to the old worker's in-memory state. The agent's step-execution loop blocked on a future that would never resolve, until token-budget exhaustion terminated the task. The failure was silent: no transport error, no non-2xx, no protocol violation the client could detect from the wire. ## Condition of Validity The resumption invariant holds **only if** the server guarantees that event IDs are unique and monotonically ordered within a logical session, *and* that a resume request bearing an ID from a prior namespace is rejected with an explicit error rather than silently reinterpreted. These are two separate guarantees and MCP streamable transport implementations frequently satisfy neither: 1. **Namespace stability.** The ID space must survive worker restarts, or the resume must be routed to the worker that owns that namespace (e.g., via sticky routing keyed on session ID, or a shared monotonic sequence like a Redis `INCR` or a persisted per-session counter). A per-process counter violates this. 2. **Namespace-mismatch detection.** The server must be able to tell "this ID is from my namespace, resume it" apart from "this ID is not mine, reject the resume." A server that cannot make this distinction must return a distinguishable error (e.g., `409 Conflict` with a session-reset code, or a fresh `Mcp-Session-Id` in the response) rather than a `200` with a fresh stream. The invariant is **violated** — and the client must treat the session as unrecoverable — whenever a resumed stream's first event ID is not strictly greater than the `Last-Event-ID` presented, *or* whenever the server cannot attest that the ID belongs to its current namespace. The client-side guard "reject if incoming ID ≤ last-seen" is necessary but not sufficient: it must escalate to **session invalidation**, not to a warning-and-continue, because a lower ID is positive evidence of namespace reset, not evidence of benign duplication. ## Decision Boundary The operative decision is what the client does at the moment it observes a resumed stream whose first event ID violates monotonicity. Three candidate policies, with the boundary that separates them: - **Continue (wrong).** Treat low IDs as duplicate delivery and keep reading. This is the observed failure. It is only correct if the server guarantees at-most-once delivery with stable IDs *and* the client has independent state to detect the missing tool-call result. Neither held. - **Retry resume (also wrong, in the reset case).** Reconnect again with the same `Last-Event-ID`. If the namespace reset is persistent (new worker stays up), this loops forever; if it is transient (routing flips back), it may "succeed" but the client cannot know which. Retry is only valid when the server has signaled a *transient* rejection (e.g., `503` with `Retry-After`), not when it has returned a 200 with a mismatched ID. - **Invalidate and renegotiate (correct).** On any monotonicity violation of a resumed stream, the client must (a) close the stream, (b) discard the session's resumption cursor, and (c) re-run the MCP `initialize` handshake to obtain a fresh `Mcp-Session-Id` and a fresh event-ID namespace, then (d) re-drive any in-flight tool calls whose results were pending at the reset point. The boundary condition that mandates this is: *the client cannot prove the pending tool-call result will ever arrive in the new namespace, therefore it must assume it will not.* The boundary is sharp: **a resumed stream is either provably continuous (first ID > `Last-Event-ID` and server-attested namespace) or it is a new session.** There is no valid middle state where the client continues reading a stream it cannot prove is the continuation of the one it left. ## Operational Effect The consequence of getting this boundary wrong is not a transport error — it is a **silent liveness failure** in the agent's reasoning loop. The agent blocks on a tool-call future that will never resolve, consumes its token budget waiting, and terminates without having produced the tool result it needed. From the outside this looks like a timeout; from the inside it is a continuity violation that the transport layer reported as success. The architectural guardrail is a **namespace attestation** on resume: the server must include, in the resumed stream's first event (or in a response header), a token that identifies the event-ID namespace, and the client must compare it against the namespace token it recorded at `initialize`. If the tokens differ, the client invalidates the session before reading any events. This converts a silent liveness failure into an explicit, detectable session-reset event, which the agent's step loop can handle by re-driving the pending tool call against the fresh session. Absent server-side attestation, the client's fallback is the monotonicity check escalated to invalidation — strictly better than warning-and-continue, though it still cannot distinguish "server reset" from "server duplicated," so it must re-drive conservatively (idempotency keys on tool calls, or explicit re-query of tool state) rather than assume the result was lost or delivered. ```python class SessionNamespaceReset(RuntimeError): """Raised when a resumed MCP SSE stream's event-ID namespace does not match the session's recorded namespace.""" pass class ResumableSSEClient: def __init__(self, session_id: str, namespace_token: str, last_event_id: int): self.session_id = session_id self.namespace_token = namespace_token # recorded at initialize self.last_event_id = last_event_id self.pending_tool_calls: dict[str, object] = {} def resume(self, response_namespace_token: str, first_event_id: int) -> None: # Guard 1: server must attest the namespace it is emitting into. if response_namespace_token != self.namespace_token: raise SessionNamespaceReset( f"namespace token mismatch on resume: session={self.session_id} " f"expected={self.namespace_token!r} got={response_namespace_token!r}; " f"pending tool calls {list(self.pending_tool_calls)} cannot be resolved " f"in the new namespace and must be re-driven." ) # Guard 2: monotonicity. A first event id <= last seen is positive # evidence of namespace reset, not benign duplication. if first_event_id <= self.last_event_id: raise SessionNamespaceReset( f"non-monotonic resume: last_event_id={self.last_event_id} " f"first_event_id={first_event_id}; treating as namespace reset." ) self.last_event_id = first_event_id def invalidate_and_reinitialize(self) -> None: # Caller must re-run MCP initialize to obtain a fresh session + namespace, # then re-drive every call in pending_tool_calls with idempotency keys. self.pending_tool_calls.clear() self.namespace_token = "" self.last_event_id = 0 ``` The operational lesson: **a 200 on a resumed SSE stream is a transport fact, not a continuity fact.** The instance must require the server to attest the event-ID namespace on resume, and must treat any monotonicity violation as a session reset requiring renegotiation and re-drive — never as a warning to log and continue past.