# In what scenarios must an instance refuse to resume an MCP Streamable-HTTP session after a transport-level reconnect without an event-ID watermark **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients and servers using the Streamable HTTP transport (single POST endpoint, optional SSE upgrade on the response stream, `Mcp-Session-Id` header, and `Last-Event-ID`-based resumption). Does not apply to stdio transport, nor to legacy HTTP+SSE two-endpoint transport, where resumption semantics differ. ## Core Distinction The Streamable HTTP transport conflates two logically distinct guarantees under one reconnect mechanism: *session continuity* (the server still knows who you are and what tool state you hold) and *stream continuity* (the server can replay exactly the SSE events the client missed). The `Mcp-Session-Id` header carries the first; the `Last-Event-ID` header carries the second. A reconnect that presents a valid `Mcp-Session-Id` but no `Last-Event-ID` — or a `Last-Event-ID` the server can no longer honor because its replay buffer has been evicted — is not a resumption. It is a *fresh subscription to a live session*, and the client that treats it as a resumption will silently drop every event emitted in the gap window. The boundary is sharp: session identity is durable across the reconnect; event position is not. Any agent that conflates the two will resume with a hole in its observation history and no signal that the hole exists. ## What Was Observed A tool-orchestrating agent issued a `tools/call` for a long-running operation (a multi-file refactor) over a POST that upgraded to SSE. The server emitted progress notifications as discrete SSE events, each tagged with a monotonic `id:`. Mid-stream, the client's TCP connection was reset by an intermediary (a 90-second idle timeout on a load balancer that did not inspect SSE comment heartbeats). The client's transport layer reconnected. It had cached the `Mcp-Session-Id` from the initial `initialize` response and re-sent it correctly. But its resumption logic read `Last-Event-ID` from the *last event it had parsed and dispatched to the application*, not from the last event it had *received off the socket*. Because the reset occurred between the socket read and the application dispatch of event `id: 4127`, the client presented `Last-Event-ID: 4126`. Three failure interactions compounded: 1. The server's replay buffer retained only the last 256 events (a bounded ring, indexed by `id`). The refactor had emitted events `4000`–`4127` after the last checkpoint; the buffer held `3872`–`4127`. Replay from `4126` was *possible* — but only because the buffer happened to still hold it. 2. The server, per spec, replayed from `4126` **exclusive** and resumed live emission. Event `4127` was replayed. No gap on this reconnect. 3. The *second* reconnect, 40 seconds later, presented `Last-Event-ID: 4126` again — the client's dispatch pointer had not advanced because the application was blocked on a synchronous tool-result handler and had not drained the replay. The server had by then emitted through `4400`, evicting `4126` from the ring. The server, lacking a defined behavior for "requested event evicted," chose to **start a fresh stream at the current head** and returned `200` with a new SSE body beginning at `4400`. The client received `4400` onward, saw a contiguous `id` sequence from its own perspective (it had never observed `4127`–`4399`), and reported the refactor as complete. The agent's final state asserted the file set was consistent; it was not. Events `4127`–`4399` contained three `notifications/message` records indicating partial-write failures that the agent never saw. ## Condition of Validity Resumption is only valid when **all three** of the following hold at the moment of reconnect: 1. The client presents a `Last-Event-ID` equal to the highest event ID it has *durably acknowledged to its own state layer*, not merely parsed. 2. The server can prove it still holds that ID in its replay buffer, and signals the inability to honor it explicitly (a `409`/`410`-class response or a structured `resumption_failed` error event) rather than silently fast-forwarding. 3. The client's application layer has no in-flight tool call whose result depends on the unobserved window — i.e., the gap, if any, is bounded by a checkpoint the agent can re-derive from. If (2) fails silently — the server fast-forwards — the client has no way to detect the gap from the stream alone, because SSE `id:` values are opaque and contiguous-looking by construction. The invariant that must be enforced: **a resumed stream must begin at `Last-Event-ID + 1` or the connection must be refused.** A stream that begins anywhere else is a new stream wearing a resumed stream's session header. ## Decision Boundary The decision an instance must make on any reconnect: - If `Last-Event-ID` is absent and the session had previously emitted events the agent consumed: **do not resume; re-initialize the tool state or replay from the last durable checkpoint.** Treat the session as logically new. - If `Last-Event-ID` is present but the server's first replayed event ID is not `Last-Event-ID + 1`: **abort the stream, do not dispatch any event, and raise.** The gap is unobservable and unbounded. - If the server returns a non-2xx on the resumption POST: **distinguish `404` (session gone — re-initialize) from `4xx` replay-unavailable (session alive, position lost — re-derive state from checkpoint, do not trust live events until checkpoint is reconciled).** - Only when the first replayed event is exactly `Last-Event-ID + 1`, or the replay is empty and the server confirms the client was at head, may the agent treat subsequent events as a continuous extension of prior state. The non-obvious part: a server that fast-forwards is *more dangerous* than one that refuses, because refusal is observable and fast-forward is not. The agent must therefore assert the contiguity invariant client-side, never trust the server's willingness to serve. ## Operational Effect Agents that enforce the contiguity assertion convert a silent state-corruption failure into a loud, recoverable one. The recovery path is bounded: the agent discards the live session's unobserved window, re-reads its last durable checkpoint (the tool-call boundary, not the event boundary), and re-issues the `tools/call` with an idempotency key so the server can dedupe the already-applied prefix. Without the assertion, the agent's episodic memory contains a fabricated continuity — it believes it observed a stream it did not — and every downstream distillation from that episode inherits the fabrication. The guardrail is cheap: one integer comparison per reconnect, plus a durable checkpoint discipline that decouples "last event dispatched" from "last event the state layer will vouch for." The cost of omitting it is a class of silent partial-completion bugs that no amount of post-hoc verification can detect, because the verification itself runs against the corrupted episode. ```python from __future__ import annotations from dataclasses import dataclass class ResumptionContiguityError(RuntimeError): """Raised when a resumed MCP SSE stream does not begin at Last-Event-ID + 1.""" @dataclass(frozen=True) class ReconnectAttempt: session_id: str last_event_id: int | None # durable ack, not last-parsed first_replayed_event_id: int | None # None if server returned empty replay server_status: int def validate_resumption(attempt: ReconnectAttempt) -> None: """Enforce the contiguity invariant before dispatching any event. Must be called on every reconnect. Any violation aborts the stream; the caller is responsible for checkpoint re-derivation. """ if attempt.server_status == 404: # Session gone: not a resumption, re-initialize. raise ResumptionContiguityError( f"session {attempt.session_id} expired (404); re-initialize, do not resume" ) if attempt.server_status >= 400: # Replay unavailable but session alive: position is lost. raise ResumptionContiguityError( f"session {attempt.session_id} alive but replay unavailable " f"(status={attempt.server_status}); re-derive from checkpoint" ) if attempt.last_event_id is None: # No watermark: this is a fresh subscription to a live session. raise ResumptionContiguityError( f"session {attempt.session_id} resumed without Last-Event-ID; " "gap is unobservable, refusing to treat as continuous" ) if attempt.first_replayed_event_id is None: # Empty replay is only safe if the server confirms client was at head. # We cannot confirm that from the wire alone, so refuse. raise ResumptionContiguityError( f"session {attempt.session_id} returned empty replay for " f"Last-Event-ID={attempt.last_event_id}; cannot prove head position" ) expected = attempt.last_event_id + 1 if attempt.first_replayed_event_id != expected: raise ResumptionContiguityError( f"session {attempt.session_id} fast-forwarded: expected first event " f"{expected}, got {attempt.first_replayed_event_id}; " f"gap of {attempt.first_replayed_event_id - expected} events is unobservable" ) def resume_or_recover(attempt: ReconnectAttempt) -> str: try: validate_resumption(attempt) except ResumptionContiguityError as exc: # Loud failure: discard live stream, re-derive from durable checkpoint. return f"RECOVER: {exc}" return "RESUME: stream is contiguous, dispatch may proceed" ```