# How does an instance detect SSE-to-Streamable-HTTP resumption divergence when an MCP session's event ID space resets mid-stream? **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients resuming a server-sent-events (SSE) or Streamable-HTTP session via `Last-Event-ID` after a transport drop, particularly during or after a server-side migration from the legacy HTTP+SSE transport to Streamable HTTP. Does not apply to stdio transports (no resumption semantics) or to sessions where the server has explicitly declared the stream non-resumable. ## Core Distinction The failure is not "the stream dropped." Drops are expected and recoverable. The failure is **event-ID space discontinuity**: the client's `Last-Event-ID` refers to a position in an event namespace that the server has silently replaced. In the legacy HTTP+SSE transport, event IDs were often monotonically increasing integers scoped to a single long-lived `GET /sse` connection. Streamable HTTP introduces per-stream resumability where the server MAY issue IDs from a different generator (UUIDs, per-stream counters, or a re-initialized counter after a pod restart or migration cutover). The client cannot distinguish "I am resuming correctly" from "I am resuming into a fresh ID space that will replay the wrong events or silently skip the gap," because both look like a successful `200 OK` with an event stream. The distinction that matters operationally: **a resumption is only valid if the server can prove continuity of the event-ID space, not merely accept the header.** Acceptance is not continuity. ## What Was Observed A client connected to an MCP server over legacy SSE, received events with IDs `... 4097, 4098, 4099`, and the TCP connection dropped. The server operator had, between the drop and the reconnect, completed a cutover to Streamable HTTP on the same endpoint path with a load balancer routing to a new backend whose event store was seeded fresh. On reconnect the client issued `GET /mcp` with `Last-Event-ID: 4099`. The new backend—implementing Streamable HTTP resumability via an event store keyed on opaque IDs—received `4099`, found no matching entry, and made the spec-permitted choice to **start a new stream from the current head** and return `200 OK` with a fresh `id: 1` event. No error, no `404`, no `400`. From the client's perspective the resume succeeded. From the protocol's perspective the client had just lost every event between 4099 and the new head, including a `notifications/tools/list_changed` and a `sampling/createMessage` request that the server had emitted during the gap. The agent continued executing against a stale tool catalog and never saw the sampling request, which the server had already timed out and treated as declined. The tell was not in the HTTP response. It was in the first event ID after reconnect: `1`. A monotonic-ID client that tracked its last-seen ID could have detected the regression. A client that treated IDs as opaque strings—which the spec encourages—could not, unless it also tracked a server-side epoch. ## Condition of Validity Resumption via `Last-Event-ID` is valid only under the conjunction of three conditions, none of which the transport layer enforces: 1. **ID-space identity.** The server that answers the resume must be the same logical event producer, or must have replicated the event store, such that the ID space is continuous across the cutover. Streamable HTTP does not require this; it requires only that the server *may* replay events after the given ID. 2. **Gap detection.** The client must be able to detect when the server has not replayed the gap—either because the server signals a discontinuity (it doesn't, in the spec) or because the client observes an ID that is provably not a successor of its last-seen ID under the server's declared ID scheme. 3. **Replay completeness.** Any events the server does replay must be delivered before the client acts on post-resume state. Streamable HTTP permits the server to interleave replayed events with live events on the resumed stream; a client that processes events as they arrive without buffering until the replay boundary has no way to order them. The legacy SSE transport made condition 1 accidentally true in most deployments because the event store was the connection. Streamable HTTP makes it accidentally false whenever the event store is decoupled from the connection—which is the entire point of the migration. ## Decision Boundary The boundary is this: **treat a resume as successful only if the first post-resume event ID is consistent with the pre-drop ID under a scheme the client has independently established, or if the server has returned an explicit resumption-scope identifier (an epoch, a stream incarnation, or a `resumptionToken`) that matches the pre-drop value.** In practice, an MCP client should implement one of: - **Epoch pinning.** On `initialize`, capture any server-provided session/stream incarnation identifier (session ID plus a server-start timestamp, or a dedicated header). On resume, require the same incarnation. If the server has rotated, the client must not send `Last-Event-ID`; it must re-initialize and treat all server state as lost. - **Monotonic-ID verification with fallback.** If the server's IDs are integers (legacy SSE behavior), require `first_resumed_id > last_seen_id` and, if there is a gap, require that the server replay every ID in the gap or return an error. If the first resumed ID is `≤ last_seen_id`, declare ID-space reset and re-initialize. - **Opaque-ID with explicit gap acknowledgment.** If IDs are opaque, the client cannot verify continuity and must not assume it. It should send `Last-Event-ID` only when it can tolerate silent loss, and must otherwise re-initialize on every reconnect. The boundary decision: **silent, gap-tolerant resumption is acceptable only for idempotent notification streams (e.g., `notifications/*` where a `list_changed` can be re-derived by re-listing). It is never acceptable for request-bearing streams (`sampling/createMessage`, `elicitation/create`) where a missed event is an unanswered request.** For the latter, the client must re-initialize rather than resume. ## Operational Effect The concrete effect on an agent instance is a **silent state divergence between the client's model of server state and the server's actual state**, bounded in time by the next state-changing notification. In the observed case, the divergence persisted for the remainder of the session: the agent invoked a tool that had been removed during the gap, received a `MethodNotFound` error from the server, and—because the agent's error-handling loop treated `MethodNotFound` as a transient tool error rather than a signal of catalog divergence—retried twice before the token budget forced a halt. The server had been correct throughout; the client's resumption logic had lied to it. The guardrail is a **resumption-scope check at the transport boundary, before any event is dispatched to the agent's reasoning loop.** The check must fail closed: on any ambiguity about ID-space continuity, the client discards the stream, re-initializes the session, and re-derives state from scratch. The cost of re-initialization (one `initialize` round-trip plus a `tools/list`) is bounded and small; the cost of a silent gap is an agent acting on a stale world model with no signal that it is doing so. The invariant to encode: **`Last-Event-ID` is a claim about the server's event store, not a claim about the client's position in it. The client must verify the claim or abstain from making it.** ```python from __future__ import annotations from dataclasses import dataclass from typing import Optional class ResumptionScopeError(RuntimeError): """Raised when a resume attempt cannot be proven continuous with the pre-drop stream.""" @dataclass(frozen=True) class StreamIncarnation: session_id: str server_epoch: str # e.g. server start time or migration generation id_scheme: str # "monotonic_int" | "opaque" @dataclass(frozen=True) class ResumeAttempt: pre_drop_incarnation: StreamIncarnation pre_drop_last_id: str post_resume_incarnation: StreamIncarnation post_resume_first_id: str carries_requests: bool # True if pre-drop stream could carry sampling/elicitation def verify_resume(attempt: ResumeAttempt) -> None: """Fail closed unless ID-space continuity is provable. Raises ResumptionScopeError if the client must re-initialize instead of sending Last-Event-ID, or if it must discard a resume response. """ pre = attempt.pre_drop_incarnation post = attempt.post_resume_incarnation # 1. Incarnation must match. A rotated epoch means the event store is # not the same producer; Last-Event-ID is meaningless against it. if pre.session_id != post.session_id: raise ResumptionScopeError( f"session id changed across resume: {pre.session_id!r} -> {post.session_id!r}; " "re-initialize, do not resume" ) if pre.server_epoch != post.server_epoch: raise ResumptionScopeError( f"server epoch rotated ({pre.server_epoch!r} -> {post.server_epoch!r}); " "event-ID space is not continuous; re-initialize" ) if pre.id_scheme != post.id_scheme: raise ResumptionScopeError( f"ID scheme changed across resume ({pre.id_scheme!r} -> {post.id_scheme!r}); " "cannot verify continuity" ) # 2. For opaque IDs, continuity is unverifiable. Refuse to resume any # stream that could carry unanswered requests. if post.id_scheme == "opaque": if attempt.carries_requests: raise ResumptionScopeError( "opaque event IDs: continuity unverifiable and stream may carry " "sampling/elicitation requests; re-initialize rather than risk silent loss" ) return # gap-tolerant notification stream: acceptable # 3. For monotonic integer IDs, require strict forward progress and, if # there is a gap, require that the server replayed the gap. try: last = int(attempt.pre_drop_last_id) first = int(attempt.post_resume_first_id) except ValueError as exc: raise ResumptionScopeError( f"declared monotonic_int scheme but IDs are not integers: " f"{attempt.pre_drop_last_id!r}, {attempt.post_resume_first_id!r}" ) from exc if first <= last: raise ResumptionScopeError( f"event-ID regression on resume: last seen {last}, first resumed {first}; " "ID space was reset by the server; re-initialize" ) if first > last + 1 and attempt.carries_requests: raise ResumptionScopeError( f"unreplayed gap on request-bearing stream: {last} -> {first}; " "server did not replay events in the gap; re-initialize" ) # first == last + 1, or gap on a notification-only stream: acceptable. ```