# How should an instance treat MCP Streamable-HTTP resumption as a replay problem rather than a reconnect problem **Date of Record:** 2026 December 3 **Scope:** Applies to MCP clients and servers using the Streamable HTTP transport (HTTP POST + SSE responses, `Mcp-Session-Id` header, `Last-Event-ID` resumption) where a long-running tool call emits progress events and the connection drops mid-call. Does not cover stdio transport, nor WebSocket-based MCP variants, nor resumption when the server has explicitly terminated the session with a 404 on the session header. ## Core Distinction Operators consistently conflate two different recovery operations that the Streamable HTTP spec keeps separate: **session re-establishment** (recovering the identity and server-side state bound to an `Mcp-Session-Id`) and **stream resumption** (recovering the ordered sequence of SSE events for a single in-flight request using `Last-Event-ID`). These have different failure modes, different idempotency properties, and different correctness invariants. The non-obvious boundary is this: a client can successfully re-establish a session and still silently corrupt its view of a tool result, because resumption is a *replay* operation over a server-side event buffer whose retention is independently bounded — and a re-established session does not imply the event buffer survived. The reconnection succeeds; the replay does not; the agent proceeds on a truncated or duplicated event stream. ## What Was Observed An agent issued a `tools/call` for a long-running operation (a code-index rebuild emitting `notifications/progress` events every few seconds, terminating in a single `tools/call` result event). The POST opened an SSE stream. At event id `47`, a load balancer recycled the connection (idle timeout on a hop that did not honor SSE keepalives). The client: 1. Detected the drop, read its last received event id (`47`), and re-issued the POST with `Last-Event-ID: 47` and the existing `Mcp-Session-Id`. 2. The server accepted the session header (session still alive, TTL 30 min) but the per-request event buffer had a separate retention policy: it kept only the **last 20 events** and, critically, a **per-request buffer keyed by request id that was garbage-collected when the original connection closed** on some replicas. 3. Because the request had landed on a different replica behind the LB, the buffer was empty. The server did not return an error. It returned `200 OK` with a fresh SSE stream that began at event id `48` — but that replica had **no record of the original request's progress counter**, so it restarted the progress sequence from the current global counter, emitting ids `48, 49, ...` that were *unrelated to* the original stream's `48, 49, ...`. The agent received a stream that looked continuous (monotonic ids, correct SSE framing, a terminal result event) but was a **stitched composite**: events `1–47` from replica A's original call, events `48–N` from replica B's *different* execution of a replayed request. The result event carried a completion payload from replica B's execution. The agent had no signal that two executions had occurred, and the tool was not idempotent — the rebuild ran twice, and the final reported artifact hash came from the second run while intermediate progress the agent had reasoned over came from the first. ## Condition of Validity The invariant that makes resumption safe is: **`Last-Event-ID` resumption is valid only if the server can prove it is replaying the same logical execution, not merely accepting the same session.** Concretely, resumption is sound only when all of the following hold: - The event id is scoped to a **(session, request) pair**, not a global or per-connection counter. A server that assigns ids from a process-global counter cannot distinguish "resume my stream" from "start a new stream that happens to have higher ids." - The event buffer is **retained beyond connection close** for at least the session TTL, and retention is **replica-independent** (shared store), or the LB is session-affine for the whole request lifetime. - The server, on receiving `Last-Event-ID` for a request it has no buffer for, returns an **explicit, distinguishable error** (e.g., `409` with a `resumption-unavailable` reason) rather than silently starting a new stream. The spec permits the server to reject resumption; it does not permit it to *fake* it. - The tool call itself is either idempotent under a **client-supplied idempotency key** carried in the original request params, or the server guarantees single-execution semantics across resumption. If any of these is false, the client's only safe move on a mid-stream drop is to **abandon the stream and re-issue the call with a fresh idempotency key after confirming the prior execution's terminal state out-of-band** — never to trust a resumed stream as a continuation of the same execution. ## Decision Boundary The boundary the agent must resolve before trusting a resumed stream: - **Did the server echo a resumption acknowledgment?** A correct server includes, on a resumed stream, either the replayed events from `Last-Event-ID + 1` (proving buffer presence) or an explicit error. A `200` whose first event id is `> Last-Event-ID + 1`, or whose first event id `<= Last-Event-ID` (duplicate), is a **resumption-integrity violation** and must be treated as a new execution. - **Is the terminal result's provenance consistent with the progress stream?** If progress events carry an execution/attempt identifier (they should), the terminal result must carry the *same* identifier. A mismatch means two executions; the agent must discard the composite and re-derive state. - **Is the tool idempotent or keyed?** If neither, a resumed stream that could have replayed the request is unsafe to consume as authoritative; the agent must reconcile against the tool's own durable state (artifact hash, row count, side-effect ledger) rather than the event stream. The decision rule: **trust a resumed stream only when (a) the server proved buffer presence via contiguous replay or explicit resumption error, and (b) the execution identifier on the terminal event matches the one on the pre-drop events.** Otherwise, treat the drop as a *lost execution boundary* and reconcile externally. ## Operational Effect When the boundary is respected, the failure is contained: the agent detects the integrity violation, discards the composite stream, queries the tool's durable state to determine whether the first execution completed, and either adopts that result or re-issues with a fresh idempotency key. Cost: one extra round-trip and a possible duplicate execution that the idempotency key collapses. When the boundary is ignored — the common case, because the stream *looks* fine — the agent proceeds on a stitched event history, reasons over progress from execution A, and commits a result from execution B. For non-idempotent tools (writes, deploys, index rebuilds, message sends) this is a silent double-execution; for reasoning agents it is worse, because the agent's chain-of-thought was conditioned on A's intermediate observations while its final action derives from B's terminal payload. The corruption is not in the transport and not in the model — it is in the seam between them, and it is invisible to both. The guardrail is architectural, not prompt-level: the client must treat `Last-Event-ID` resumption as an **untrusted replay claim** subject to a contiguity-and-provenance check, and the server must never emit a `200` stream for a `Last-Event-ID` it cannot honor. The agent layer must additionally carry an execution identifier through progress and terminal events so the seam is observable at all. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ResumptionIntegrityError(RuntimeError): """Raised when a resumed MCP SSE stream cannot be proven to continue the same execution.""" @dataclass class StreamEvent: event_id: int execution_id: str kind: str # "progress" | "result" payload: dict = field(default_factory=dict) @dataclass class ResumedStream: last_event_id_sent: int events: list[StreamEvent] server_acknowledged_resumption: bool def validate_resumed_stream( pre_drop_last_id: int, pre_drop_execution_id: str, resumed: ResumedStream, tool_idempotency_key: Optional[str], ) -> str: """ Decide whether a resumed stream may be consumed as a continuation of the original execution. Returns "trust" or "reconcile". Raises on hard integrity violations that must never be silently consumed. """ if not resumed.events: raise ResumptionIntegrityError( f"resumed stream for Last-Event-ID {pre_drop_last_id} carried no events; " "server accepted session but produced no replay — treat as new execution" ) first = resumed.events[0] expected_next = pre_drop_last_id + 1 # Contiguity check: a sound server either replays from expected_next or # explicitly refuses. A gap or a duplicate is a fabricated continuation. if first.event_id > expected_next: raise ResumptionIntegrityError( f"resumption gap: expected first event id {expected_next}, got {first.event_id}; " f"server did not replay buffered events for Last-Event-ID {pre_drop_last_id}" ) if first.event_id <= pre_drop_last_id: raise ResumptionIntegrityError( f"resumption duplicate: first event id {first.event_id} <= Last-Event-ID " f"{pre_drop_last_id}; server replayed already-consumed events" ) # Provenance check: every event must belong to the original execution. foreign = [e for e in resumed.events if e.execution_id != pre_drop_execution_id] if foreign: raise ResumptionIntegrityError( f"execution provenance mismatch: pre-drop execution {pre_drop_execution_id!r} " f"but resumed stream contains events from {sorted({e.execution_id for e in foreign})!r}; " "stream is a stitched composite of two executions" ) terminal = [e for e in resumed.events if e.kind == "result"] if terminal and terminal[-1].execution_id != pre_drop_execution_id: raise ResumptionIntegrityError( "terminal result belongs to a different execution than the progress stream" ) # Even with contiguous, provenance-clean replay, a non-idempotent tool # without a key may have re-executed server-side; reconcile externally. if not tool_idempotency_key and terminal: return "reconcile" return "trust" def apply_resumption( pre_drop_last_id: int, pre_drop_execution_id: str, resumed: ResumedStream, tool_idempotency_key: Optional[str], reconcile_fn, ) -> dict: verdict = validate_resumed_stream( pre_drop_last_id, pre_drop_execution_id, resumed, tool_idempotency_key ) if verdict == "reconcile": # Do not trust the stream's terminal payload; ask the tool's durable # state what actually happened, keyed by the pre-drop execution. return reconcile_fn(pre_drop_execution_id) return resumed.events[-1].payload ```