# When must an instance refuse to replay an SSE event ID after an MCP session resume, and why the answer is not "always replay the last event" **Date of Record:** 2026 December 2 **Scope:** Applies to MCP servers/clients using the HTTP-native transport where a `GET` request upgrades to a Server-Sent Events stream carrying an `id:` field per event, and where a client reconnects with `Last-Event-ID` to resume a session. Does not apply to stdio transports, WebSocket transports, or SSE streams that do not emit per-event IDs (i.e., where resumption is structurally impossible and the client must re-initialize). ## Core Distinction The distinction that matters is between **event-ID monotonicity** and **event-ID causality**. SSE resumption semantics as specified (and as naively implemented) assume that a client presenting `Last-Event-ID: N` has processed every event with id ≤ N, and therefore the server may safely replay events N+1, N+2, … from its buffer. This assumption holds for pure event streams (logs, telemetry) where the ID is a cursor into an append-only sequence. It does **not** hold for MCP streams, because MCP events are not merely delivered — they are *acted upon* by the client, and the client's actions (tool calls, sampling requests, elicitations) mutate server-side session state that the event IDs do not encode. The event ID is a position in the delivery sequence; the session state is a function of the *effects* of delivered events, not their positions. A resume that replays events whose effects were already applied produces double-application; a resume that skips events whose effects were *not* applied produces silent state divergence. The boundary condition is the case where the server cannot distinguish these two from the `Last-Event-ID` header alone. ## What Was Observed An MCP server exposing a `run_analysis` tool was configured with the HTTP-native transport, SSE upgrade on `GET /mcp`, and a per-session ring buffer of 512 events keyed by a monotonic `id`. A client agent initiated a session, received `initialize` response, sent `notifications/initialized`, then issued a `tools/call` for `run_analysis`. The server emitted a stream of progress events (`id: 41` through `id: 58`), each carrying a `progressToken` and a partial-result payload. At event `id: 52`, the client's TCP connection was severed by an intermediary proxy idle-timeout (the client was blocked on a downstream model call for ~95 s and sent no keepalive). The client reconnected and sent `GET /mcp` with `Last-Event-ID: 52`. The server, correctly per the SSE spec, replayed events `53` through `58` from its ring buffer. But the client had **already received and partially processed** events 53–55 before the socket died — its application-level handler had written the partial results from 53 and 54 into its working context and had dispatched a nested `sampling/createMessage` request to the server in response to event 55. The server had received that sampling request and enqueued a response as event `56`. On replay, the client re-processed event 55 and dispatched the sampling request **a second time**. The server, which had no deduplication key on sampling requests, enqueued a second response. The client's context now contained two divergent sampled completions for the same progress step, and its final synthesis of `run_analysis` was computed over a doubled and inconsistent partial-result set. No error was raised at any layer: the transport was healthy, the SSE frames were well-formed, the session was "resumed," and the tool call returned a plausible but wrong answer. A second observed variant: a client that had *not* processed event 52 (it died mid-write of the frame) reconnected with `Last-Event-ID: 51` because its last *committed* cursor was 51. The server replayed 52–58. This was correct. The failure was not in the replay logic — it was that the client had no way to communicate "I received 52 but did not commit its effects," and the server had no way to ask. ## Condition of Validity `Last-Event-ID: N` is a sound resume cursor **if and only if** every event with id ≤ N is idempotent with respect to client-side effects, or the client can prove to the server that all effects of events ≤ N were durably committed before the disconnect. Neither condition is checkable from the header alone. For MCP specifically, the following event classes violate the first condition and therefore require an explicit effect-commitment protocol rather than bare `Last-Event-ID` replay: - Events whose receipt triggers a client→server request (`sampling/createMessage`, `elicitation/create`, `roots/list` refresh). Replay re-triggers the request. - Events carrying partial tool results that the client folds into a running accumulator. Replay double-folds. - Events that advance a server-side state machine keyed by a client-supplied token (progress tokens, request IDs). Replay advances the machine twice. - Events whose payload is non-deterministic (LLM-generated sampling content). Replay yields a *different* payload under the same ID if the server regenerates rather than buffers — and if it buffers, the buffer is stale relative to server state. The invariant that must hold for safe resumption is: **the server must be able to map `Last-Event-ID` to a set of events whose effects are known-committed on the client, and must replay only events outside that set.** Since the header carries only a scalar, the server cannot satisfy this invariant without an out-of-band commitment channel. The correct architectural response is to treat `Last-Event-ID` as a *hint* and require a session-level `effects_committed_through` value supplied by the client in the resume request body (or a custom header), which the server validates against its own record of which events it has observed effects for (via the request IDs the client has already sent). ## Decision Boundary The boundary is drawn at whether the event stream is **effect-bearing** or **observation-only**. - **Observation-only** (server→client notifications with no client action triggered, e.g., `notifications/message` logging, pure progress percentages): bare `Last-Event-ID` replay is safe. Duplicate delivery is idempotent at the client because the client's only action is to render or discard. - **Effect-bearing** (any event that causes the client to emit a request, mutate an accumulator, or advance a state machine): bare `Last-Event-ID` replay is unsafe. The server must either (a) buffer and replay the *exact* prior payloads and require the client to dedupe by a stable event key, or (b) refuse to replay and force the client to re-initialize the session and re-issue the in-flight request with a fresh idempotency key. The decision rule an agent should apply on resume: 1. If the session's in-flight operation is effect-bearing and the client cannot prove commitment of all effects up to its resume cursor, **do not resume — re-initialize**. The cost of re-running the tool call is bounded; the cost of a silently doubled sampling request is an incorrect answer with no error signal. 2. If the server's ring buffer has evicted events between the client's committed cursor and the current head (buffer overflow during a long disconnect), **do not resume — re-initialize**. A gap in the replay sequence is indistinguishable from a gap in the client's processing, and the server cannot tell which. 3. Only when the stream segment being resumed is observation-only, or when the client supplies a verifiable `effects_committed_through` that the server can cross-check against its received-request log, may `Last-Event-ID` replay proceed. ## Operational Effect The practical consequence is that MCP sessions over HTTP-native transport are **not resumable by default** for any operation that involves client→server requests mid-stream. An agent that assumes SSE resumption semantics from the web-logging world will, under proxy timeouts and mid-stream disconnects, silently double-apply effects and produce wrong results with a healthy-looking transport trace. The guardrail is to treat `Last-Event-ID` as a lower bound on delivery, not a proof of effect commitment, and to gate resumption on an explicit, server-validated commitment cursor. When that cursor is absent or unverifiable, the correct action is a clean re-initialize with a new idempotency key on the in-flight request — never a blind replay. ```python class UnsafeResumeError(RuntimeError): """Raised when an MCP session resume would replay effect-bearing events whose client-side effects are not proven committed.""" pass EFFECT_BEARING_EVENT_TYPES = frozenset({ "sampling/createMessage", "elicitation/create", "roots/list", "progress/accumulate", }) def plan_resume( last_event_id: int, buffer_head_id: int, buffer_floor_id: int, events_since_cursor: list[dict], effects_committed_through: int | None, server_received_request_log: set[str], ) -> dict: """ Decide whether an MCP SSE resume may replay from last_event_id, or must force re-initialization. Returns {"action": "replay", "from": id} or {"action": "reinitialize"}. Raises UnsafeResumeError when the request is ambiguous and silent divergence would result. """ # Gap check: buffer has evicted events between cursor and floor. if last_event_id < buffer_floor_id - 1: # Cannot distinguish client-processing gap from server-eviction gap. return {"action": "reinitialize", "reason": "buffer_evicted_gap"} if last_event_id > buffer_head_id: raise UnsafeResumeError( f"Last-Event-ID {last_event_id} exceeds server head {buffer_head_id}; " "client cursor is not credible, refusing replay" ) effect_bearing = [ e for e in events_since_cursor if e.get("type") in EFFECT_BEARING_EVENT_TYPES ] if not effect_bearing: # Observation-only segment: bare replay is safe. return {"action": "replay", "from": last_event_id + 1} # Effect-bearing segment: require a verifiable commitment cursor. if effects_committed_through is None: raise UnsafeResumeError( "Effect-bearing events in resume window but client supplied no " "effects_committed_through cursor; replay would risk double-application" ) if effects_committed_through < last_event_id: # Client's committed effects lag its delivery cursor: it received # events whose effects it did not commit. Replaying them re-triggers # client->server requests. raise UnsafeResumeError( f"effects_committed_through={effects_committed_through} lags " f"Last-Event-ID={last_event_id}; replay would re-dispatch " f"{len(effect_bearing)} effect-bearing events" ) # Cross-check: every effect-bearing event up to the commitment cursor # must have a corresponding received request, or the client's claim is # unverifiable. for e in effect_bearing: if e["id"] <= effects_committed_through: key = e.get("request_key") if key is None or key not in server_received_request_log: raise UnsafeResumeError( f"event {e['id']} claims committed but server has no " f"record of its triggering request; commitment unverifiable" ) return {"action": "replay", "from": effects_committed_through + 1} ```