# What structural signals indicate a resumable MCP stream is actually unrecoverable: silent event-ID discontinuity across HTTP-native transport reconnects **Date of Record:** 2026 November 16 **Scope:** Applies to MCP servers and clients using the HTTP-native transport (POST for requests, optionally GET for the SSE stream, `Last-Event-ID` for resumption). Does not apply to stdio transport, nor to servers that do not emit `id:` fields on SSE events, nor to stateless request/response-only deployments. ## Core Distinction The HTTP-native MCP transport advertises session resumption via the SSE `Last-Event-ID` mechanism: the client reconnects to the stream endpoint, presents the last event ID it observed, and the server replays events emitted after that point. The critical distinction is between **transport-level reconnection success** and **logical stream continuity**. A reconnect can complete with HTTP 200, a valid `text/event-stream` content type, and a flowing byte stream, while the *event-ID sequence itself* has a discontinuity that makes replay semantically wrong or silently lossy. The invariant that matters is not "the connection is up." It is: *the set of events replayed after `Last-Event-ID = X` must be exactly the events that would have been delivered on the original stream after X, in the same order, with the same IDs, and the server must still hold the state those events reference.* Resumption is a claim about a log, not about a socket. ## What Was Observed Three structural signals, individually benign, collectively indicate that a resumed stream is unrecoverable and must be treated as a fresh session rather than a continuation: 1. **Event-ID monotonicity break at the resume boundary.** The client's last-seen ID is `X`. The first replayed event carries an ID `Y` where `Y <= X` or where `Y` is not the immediate successor under the server's ID scheme (e.g., `X = 41`, first replayed = `43`). A gap means the server's replay buffer was truncated, rotated, or partitioned and the events in `(X, 43)` are gone. A regression (`Y <= X`) means the server has reset its ID counter — typically after a restart, a replica failover, or a session migration — and the "replay" is actually a new stream wearing the old session's clothes. 2. **Session identity drift behind a stable session header.** The `Mcp-Session-Id` header returned on the resume request is identical to the original, but a secondary signal (a server-issued `retry:` value, a `server-instance` or `x-mcp-replica` hint if present, or the shape of the first replayed event) shows the session is now served by a different backend that never held the original in-memory event log. The session ID is a *routing key*, not a *durability guarantee*. Identical ID + different backend = empty or synthetic replay. 3. **Replay that terminates without a terminal marker.** The replayed stream closes (server ends the SSE response) without emitting the event the client is actually waiting for — the tool result, the `notifications/message`, the completion — and without any error event. The server has "successfully" replayed everything it still has, which is a strict subset of what the client needs. The absence of an error is the failure: there is no protocol-level signal that replay was incomplete. Any one of these alone warrants suspicion. Two or more together, especially (1) plus (3), mean the resumed stream is a different logical stream and continuing to treat it as the same session will corrupt agent state. ## Condition of Validity Resumption via `Last-Event-ID` is only valid when **all** of the following hold: - The server's event IDs are strictly monotonic and the first replayed ID is the exact successor of `Last-Event-ID` in the server's ordering, with no observable gap. - The server retains the event log for the entire session lifetime and across any replica change; the `Mcp-Session-Id` maps to a durable log, not to a process-local buffer. - The replayed stream either contains the terminal event the client is awaiting or emits an explicit error/close reason indicating truncation. - The client has not itself discarded state that the replayed events reference (e.g., a pending request whose `id` no longer maps to a live handler). If the server cannot guarantee log retention across reconnects — common with in-memory buffers, short TTLs, or horizontally scaled replicas without sticky routing — then resumption is *best-effort replay*, not *continuation*, and the client must be prepared to re-derive state rather than trust the stream. ## Decision Boundary The operational rule: **treat a resumed stream as a continuation only if the first replayed event ID is the exact successor of `Last-Event-ID` and the stream reaches the awaited terminal event without a gap; otherwise, abandon the session and re-initialize.** Do not: - Retry the resume with the same `Last-Event-ID` hoping for a better result — if the buffer was truncated, retrying returns the same truncated replay. - Treat HTTP 200 + valid SSE as proof of continuity. - Assume a stable `Mcp-Session-Id` implies a stable log. - Silently drop the gap and process events after it — this yields an agent acting on a state history with holes. Do: - Track the highest contiguous event ID seen, not merely the last one. - On a detected gap or ID regression, issue a fresh `initialize` and re-establish tool/resource state. - Surface the discontinuity to the orchestration layer as a distinct condition, not a generic reconnect. ## Operational Effect When the boundary is respected, an agent that detects an ID gap or a terminal-less replay re-initializes and re-issues in-flight requests, accepting duplicate work as the cost of correctness. When it is violated, the agent proceeds on a partially replayed history: it may believe a tool call completed when its result event was in the truncated window, or act on a `notifications/message` sequence with missing intermediate states. The failure is silent — no exception is raised by the transport — and manifests later as inconsistent tool arguments, duplicated side effects, or reasoning over a state that never existed. The structural signals (ID gap, identity drift, terminal-less replay) are the only early warning the protocol gives you. ```python class StreamResumptionError(RuntimeError): """Raised when a resumed MCP HTTP-native stream is not a valid continuation.""" pass def validate_resumption( last_event_id: int, first_replayed_id: int | None, replayed_event_ids: list[int], awaited_terminal_seen: bool, same_backend: bool, ) -> None: """ Enforce the resumption invariant for an SSE reconnect carrying Last-Event-ID. Raises StreamResumptionError if the resumed stream cannot be trusted as a continuation of the original logical stream. """ if not same_backend: raise StreamResumptionError( "session id stable but backend changed; event log not durable across replicas" ) if first_replayed_id is None: raise StreamResumptionError( f"resume with Last-Event-ID={last_event_id} produced no replayed events" ) if first_replayed_id <= last_event_id: raise StreamResumptionError( f"event-ID regression: last seen {last_event_id}, replay started at " f"{first_replayed_id}; server log was reset, not resumed" ) if first_replayed_id != last_event_id + 1: raise StreamResumptionError( f"event-ID gap: expected successor {last_event_id + 1}, got " f"{first_replayed_id}; events in between are lost" ) for prev, cur in zip(replayed_event_ids, replayed_event_ids[1:]): if cur != prev + 1: raise StreamResumptionError( f"non-contiguous replay: {prev} -> {cur}; buffer truncated mid-stream" ) if not awaited_terminal_seen: raise StreamResumptionError( "replayed stream closed without the awaited terminal event and without " "an error signal; replay is a strict subset of required events" ) ```