# In what scenarios must an instance treat MCP SSE resumption as a state-reconstruction problem rather than a byte-replay problem **Date of Record:** 2026 November 22 **Scope:** Applies to MCP clients that reconnect to a server-side SSE stream (per the HTTP+SSE transport) after a transport drop and attempt to resume via `Last-Event-ID`, when the server multiplexes tool-call results, sampling requests, and progress notifications on a single per-session stream. Does not apply to stateless request/response MCP transports (e.g., streamable HTTP without session resumption) or to streams where the server guarantees idempotent, replayable event bodies. ## Core Distinction The failure here is not "the connection dropped." Connections drop constantly and the reconnect logic is trivial. The failure is the conflation of two different recovery semantics that the `Last-Event-ID` header invites you to treat as identical: - **Byte-replay semantics:** the server retains events `N+1..M` and re-emits them verbatim on reconnect. The client's job is to dedupe by event ID and continue. This is what SSE resumption *looks* like it promises. - **State-reconstruction semantics:** the events `N+1..M` were *effects* of server-side work whose authoritative state has since advanced (tool results were consumed, sampling requests were answered or timed out, progress counters moved). Re-emitting them verbatim does not restore the client to a coherent point in the session; it replays decisions against a world that no longer exists. An MCP instance crosses the boundary into the second regime the moment its session carries *server-initiated* requests (`sampling/createMessage`, `roots/list_changed`, elicitation) or *stateful tool invocations* whose results are only meaningful in the order and context they were first delivered. In that regime, a naive `Last-Event-ID` resume is not a resume — it is a fork, and the client silently takes the wrong branch. ## What Was Observed A client session issued `tools/call` for a long-running `repo.index` tool. The server streamed progress notifications (`notifications/progress` with a monotonic `progressToken`) interleaved with a `sampling/createMessage` request that the server needed the client to answer before it could finish indexing. The transport dropped at event ID `e4471`, immediately after the server emitted the sampling request but before the client's response was flushed back over the POST channel. On reconnect the client sent `Last-Event-ID: e4471`. The server, whose session state had a 30-second sampling timeout, had already: 1. Timed out the sampling request and recorded a fallback decision (index with default chunking). 2. Advanced the `progressToken` counter past the point the client last saw. 3. Emitted `e4472..e4479` containing the *fallback* result and a `notifications/progress` sequence starting at `progress=0.62` — a value the client had never observed, because the events that would have carried `0.0..0.61` were emitted while the client was disconnected but *before* the server's resume buffer snapshot. The server re-emitted `e4472..e4479` on reconnect. The client, applying byte-replay logic, saw a `sampling/createMessage` it had already answered (it had, in fact, never successfully sent the answer), re-answered it with a *different* model selection, and the server — now in fallback mode — treated the late answer as a new request against an already-completed tool call, producing a duplicate `tools/call` result with a mismatched `progressToken`. The agent's planner received two `repo.index` results for one call ID, one of which reflected a chunking strategy it had explicitly rejected. The observable signature is not a crash. It is a *plausible* duplicate result whose provenance the client cannot distinguish from a legitimate retry, arriving with a progress counter that does not monotonically continue from the client's last-seen value. ## Condition of Validity Byte-replay resumption is valid **only** when all three hold: 1. **Event bodies are pure functions of their ID.** Re-emitting `eN` yields the same semantic payload regardless of when it is emitted. Progress notifications with absolute counters violate this; they are cumulative. 2. **No server-initiated request is outstanding at the drop point.** If the server is awaiting a client response (`sampling`, elicitation), the drop converts an in-flight request into an orphan, and replay re-surfaces it as if it were fresh. 3. **The server's resume buffer is a suffix of the emitted sequence with no gaps.** Many implementations snapshot the buffer at a *later* point than the client's `Last-Event-ID`, silently dropping the intervening events and re-emitting only from the snapshot — a gap the client cannot detect because event IDs are opaque. When any of these fails — and in any session carrying sampling or stateful tools, at least (1) and (2) fail — the client must treat resumption as reconstruction: it must re-derive session state from an authoritative source (a `session/state` query, a re-issued idempotent tool call with a dedupe key, or a full session re-initialization) rather than trusting the replayed event stream. ## Decision Boundary The instance must switch from replay to reconstruction when **either**: - The replayed stream contains an event whose `progressToken` or sequence field does not strictly continue from the client's last-observed value (gap or regression), **or** - The replayed stream contains a server-initiated request (`sampling/createMessage`, elicitation) whose ID the client has already recorded as *sent* in its outbound ledger — meaning the server re-emitted a request the client believes it answered, and the two ledgers disagree. The first is detectable purely from the stream. The second requires the client to maintain an **outbound request ledger keyed by server-issued request ID**, which most MCP clients do not, and which is the actual invariant this failure exposes: *the client must be able to distinguish "server re-sent a request I answered" from "server sent a new request," and event IDs alone cannot make that distinction.* Below this boundary — pure notification streams, stateless tools, no outstanding server requests — replay is correct and cheaper. Above it, replay is a correctness bug that produces plausible-but-wrong state, which is worse than a hard failure because the planner will act on it. ## Operational Effect The practical consequence is that a resumed session can carry a **forked decision history**: the server's fallback branch and the client's replayed branch both execute, and the merge point is a duplicate tool result. Downstream agents that dedupe by `tools/call` ID will keep the first result and discard the second — but the *first* result may be the fallback the client never consented to, because the client's answer arrived after the server's timeout. The agent's memory now contains a completed task whose parameters it did not choose. The guardrail is not "retry harder." It is: on resume, if the outbound ledger and the replayed stream disagree about any server-initiated request, the client must **abandon the resumed session and re-initialize**, re-issuing in-flight tool calls with idempotency keys so the server can dedupe against its own completed work. The session ID must be treated as non-transferable across a reconstruction boundary; a resumed session that fails the ledger check is a *new* session that happens to share an ID, and the ID must be rotated to prevent the server from matching new requests against stale state. ```python class SessionResumeForkError(RuntimeError): """Raised when a resumed SSE stream's replayed events contradict the client's outbound ledger.""" pass def resume_session(client, session_id: str, last_event_id: str): stream = client.open_sse(session_id, last_event_id=last_event_id) last_progress = client.ledger.last_observed_progress(session_id) for event in stream: # Invariant 1: progress counters must strictly continue. if event.type == "notifications/progress": if event.progress_token <= last_progress: raise SessionResumeForkError( f"progress regression on resume: saw {event.progress_token} " f"after {last_progress} (session {session_id})" ) last_progress = event.progress_token # Invariant 2: server-initiated requests must not be replayed # against a client that already recorded an outbound answer. if event.type in ("sampling/createMessage", "elicitation/create"): if client.ledger.has_outbound(session_id, event.request_id): raise SessionResumeForkError( f"server re-emitted request {event.request_id} that client " f"already answered; replay/reconstruction boundary crossed" ) return stream ```