# When must an instance treat an MCP `text/event-stream` reconnect as a *new* session rather than a resumption **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients/servers speaking the HTTP-native transport with SSE streaming and `Last-Event-ID` resumption, where the server advertises resumability via event IDs. Does not apply to stdio transport, nor to stateless request/response MCP deployments where no event log is maintained. ## Core Distinction The failure is not "the stream dropped." Streams drop constantly and that is a normal, recoverable condition. The boundary is between two superficially identical reconnect events: 1. **Resumption** — the client reconnects with `Last-Event-ID: N`, the server still holds the per-session event log, and replays events `N+1…` before resuming live. Session identity (`Mcp-Session-Id`) is preserved; tool-call state, pending sampling requests, and subscription cursors remain coherent. 2. **Silent re-instantiation** — the client reconnects with `Last-Event-ID: N`, but the server's event log for that session has been evicted (TTL expiry, pod restart, scale-to-zero, load-balancer landing on a different replica). The server does **not** 404. It accepts the connection, mints a fresh event log, and starts emitting from a new sequence. The client sees a 200 and a live stream and concludes resumption succeeded. The non-obvious invariant: **a 200 on `GET /mcp` with a valid `Last-Event-ID` does not imply the events between `N` and the new head were delivered.** SSE resumption has no mandatory gap signal. The transport layer cannot distinguish "nothing happened while you were away" from "everything between seq 41 and seq 9003 was lost," because both look like an idle reconnect followed by the next event. ## What Was Observed An agent driving a long-running `browser.navigate` + `fs.write` tool sequence over MCP HTTP transport. Trace: - Session `sess-7f2a`, event log at seq 4112 when the client's TCP connection is severed by a NAT rebind (~90s idle). - Client reconnects: `GET /mcp` with `Mcp-Session-Id: sess-7f2a`, `Last-Event-ID: 4112`. - Server replica that held `sess-7f2a` was terminated 40s earlier by a rolling update. The new replica's session store is empty for that key. - Server returns `200 OK`, `Content-Type: text/event-stream`, and — critically — a fresh `id: 1` on its first event, a `notifications/progress` for a tool call the agent had already completed and reported to the user. - Client library treated the connection as healthy. No gap detection: the client's resume logic only checks that the socket opened, not that the first received `id` is `> 4112`. - The agent, seeing a `progress` notification for a tool call it believed finished, re-issued the corresponding `tools/call`. The server executed it a second time. The `fs.write` appended a duplicate record; the agent's internal episode log now disagreed with the server's by one tool invocation. The failure was not the dropped stream. It was the **duplicate execution produced by a resumption that was actually a re-instantiation**, plus the absence of any signal that the gap existed. ## Condition of Validity The `Last-Event-ID` resumption contract is only sound under a conjunction that is rarely enforced end-to-end: - The server **retains** the event log for the session for at least `max(client_reconnect_window, server_idle_timeout)`, and retention is keyed by session, not by replica. - The server, on receiving a `Last-Event-ID` it cannot satisfy (log evicted, seq out of range, unknown session), **must reject** with a distinguishable error — e.g. `404` or a `409`/`410` with a machine-readable `session_expired` code — rather than silently minting a new log. - The client **validates** that the first event ID received after reconnect is strictly greater than the `Last-Event-ID` it sent, or that the server explicitly signals "no gap" (e.g. a `resumed: true` control event carrying the server's current head seq). - Event IDs are **monotonic and session-scoped**, not per-connection. A per-connection counter (restarting at 1) makes gap detection impossible and is the single most common root cause. If any conjunct fails, resumption degrades to silent re-instantiation and the client has no way to know. ## Decision Boundary An instance must treat a reconnect as a **new session** (discard in-flight tool-call assumptions, re-fetch server state, re-establish subscriptions, and reconcile its episode log against the server) when any of the following hold: - The first event ID after reconnect is `≤` the `Last-Event-ID` sent (counter reset detected). - The server's response lacks an explicit resumption acknowledgement and the first event is not a replay of a known-pending operation. - The session ID in the response differs from the one sent, or a new session was minted without the client requesting it. - A reconnect occurs after a server-side idle/scale event that the client can infer (e.g. > the server's advertised `session_ttl`), even if the socket opens cleanly. Conversely, an instance may treat it as **resumption** only when it can *prove* continuity: monotonic event IDs with a confirmed head, or an explicit `resumed` control frame. Absent proof, the safe default is re-instantiation with reconciliation — never silent continuation. ## Operational Effect The practical consequence is that **at-most-once tool execution cannot be assumed across a reconnect**. Agents that carry a "tool call in flight" belief across a stream interruption will double-execute side-effecting tools whenever the server silently re-instantiated. The guardrail is a two-part discipline: (1) the client must implement gap detection on event-ID monotonicity and treat any violation as session loss, and (2) side-effecting tool calls must carry an idempotency key derived from the agent's episode log so that a re-instantiation-induced replay is deduplicated server-side. Without both, resumable SSE is a correctness hazard disguised as a reliability feature: it makes the connection look continuous precisely when the state behind it is not. ```python class ResumptionGapError(RuntimeError): """Raised when an SSE reconnect cannot be proven continuous.""" pass class StreamResumeGuard: """Validates that an MCP HTTP SSE reconnect is a true resumption, not a silent session re-instantiation.""" def __init__(self, session_id: str, last_event_id: int): self.session_id = session_id self.last_event_id = last_event_id self.awaiting_first_event = True def on_reconnect_response(self, resp_session_id: str, status: int) -> None: if status != 200: # Server explicitly refused resumption; safe to re-instantiate. raise ResumptionGapError( f"server refused resume for {self.session_id}: status={status}" ) if resp_session_id != self.session_id: # Server minted a new session without being asked. raise ResumptionGapError( f"session identity changed on resume: " f"sent={self.session_id} got={resp_session_id}" ) def on_first_event(self, event_id: int) -> None: if not self.awaiting_first_event: return self.awaiting_first_event = False if event_id <= self.last_event_id: # Counter reset or replay window lost: this is a new event log, # not a continuation. Must re-instantiate and reconcile. raise ResumptionGapError( f"event id regressed on resume: sent Last-Event-ID=" f"{self.last_event_id} got first id={event_id}; " f"treating as new session and reconciling state" ) if event_id != self.last_event_id + 1: # Monotonic but with a gap the client cannot fill. raise ResumptionGapError( f"unfillable event gap: expected {self.last_event_id + 1}, " f"got {event_id}; {event_id - self.last_event_id - 1} events lost" ) # Continuity proven: safe to continue as the same session. ```