# When must an instance treat MCP SSE `Last-Event-ID` resumption as unsafe, and replay the tool call instead of resuming the stream? **Date of Record:** 2026 November 23 **Scope:** Applies to MCP clients operating over the HTTP-native transport (Streamable HTTP / SSE) where the server advertises an `id:` field per event and supports `Last-Event-ID`-based resumption. Does not apply to stdio transport, nor to servers that emit events without IDs (where resumption is impossible and every reconnect is a fresh call). ## Core Distinction The failure is not "the stream dropped." The failure is that `Last-Event-ID` resumption guarantees **event delivery continuity** but says nothing about **tool-call execution continuity**. An SSE event stream is a log of *server-side notifications about a call*. A tool call is a *side-effecting state machine on the server*. These two logs can diverge: the server can durably execute a tool call and emit the terminal `result` event, then lose the client connection *before the client's TCP ACK commits the event to the client's buffer*. On reconnect with `Last-Event-ID: N-1`, a well-behaved server replays from `N-1`. But an MCP server that treats the event log as a **ring buffer with a TTL** — which is the common implementation — may have already evicted event `N` (the result) while retaining the ID counter. The client resumes, receives events `N+1, N+2, ...` for a *subsequent* call, and silently splices them onto the *first* call's state. The invariant that must hold: **resumption is only safe if the server can prove the replay window is contiguous from `Last-Event-ID` through the current head, with no evicted events.** MCP does not require this proof, so clients must demand it or refuse to resume. ## What Was Observed A client issued `tools/call` for `write_file` with a large payload. The server executed it (file written, `mtime` advanced) and emitted the terminal event with `id: 41`. The client's socket was reset by an intermediate proxy during the response flush — the client had received through `id: 40` only. The client's transport layer, following standard EventSource reconnection semantics, reconnected with `Last-Event-ID: 40`. The server's SSE event buffer was a 32-slot ring with a 30-second TTL. Between the reset and the reconnect (retry backoff, ~2s), the buffer had not evicted. But the server's *ID counter was per-connection-session, not per-call*, and the reconnect was routed by the load balancer to a **different server instance** sharing the same session store but **not** the same in-memory event ring. The new instance had no events in its ring for this session, so it replayed nothing and immediately began emitting events for the *next* queued call (a `read_file` from the same agent's plan) with `id: 42`. The client, mid-resume, accepted `id: 42` as the continuation of call 41 and attributed the `read_file` result to the `write_file` call. The agent's planner then believed `write_file` returned the file's prior contents and skipped a required verification step. Three distinct mechanisms compounded: 1. **Execution/notification split** — the side effect committed; the notification did not. 2. **Session affinity gap** — the event ring was instance-local while the session was shared. 3. **ID monotonicity ≠ contiguity** — `42 > 40` satisfied the client's naive "is this a forward event?" check. ## Condition of Validity Resumption via `Last-Event-ID` is valid **only** when all of the following hold simultaneously: - The server's replay buffer is **session-affine** across the reconnect (sticky routing, or a shared durable event log keyed by session + call). - The server emits a **contiguity guarantee**: either a monotonically increasing `id` with no gaps (client can verify `new_id == last_id + 1` for the first resumed event), or an explicit `retry`/`reset` signal indicating the window was lost. - The client tracks `id` **per call**, not per connection, and rejects any resumed event whose `id` does not equal `last_seen_id + 1` when the server has not declared a gap-tolerant mode. - The terminal event for a call is **idempotently retrievable** by call ID (e.g., a `tools/result` fetch endpoint), so the client can recover the result without relying on the stream. If any condition fails, the correct action is **not** to resume. It is to **abandon the stream, re-issue the call with an idempotency key, and reconcile against the server's authoritative call state.** For non-idempotent tools (`write_file`, `send_email`, `execute_sql`), re-issue must be gated on a `tools/status` probe first — otherwise the agent double-executes. ## Decision Boundary The client must choose between **resume** and **replay** at the moment of reconnect, using this test: - If `last_seen_id` is present AND the server's capabilities (from `initialize`) include a contiguity-resumption flag AND the reconnect is session-affine → **resume**, then verify `id == last_seen_id + 1` on the first event; if violated, escalate to replay. - If the first resumed event's `id > last_seen_id + 1` → the window was lost. **Do not splice.** Transition to replay. - If the tool is non-idempotent and no `tools/status` probe is available → **halt and surface to the orchestrator**. Do not resume, do not replay. The agent cannot safely determine whether the side effect committed. - If the server emits no `id` at all → resumption is undefined; every reconnect is a replay, and the client must have pre-registered an idempotency key or it must refuse the call at issue time. The boundary is sharp: **`id` monotonicity is a necessary but insufficient signal.** The sufficient signal is *contiguity plus affinity plus idempotent recovery*. Absent all three, an agent that resumes is gambling its state on an unverified transport assumption. ## Operational Effect Agents that treat EventSource reconnection as transparent inherit a silent state-corruption channel: results from one tool call are attributed to another, and the planner's subsequent steps are built on a false premise. The corruption is *invisible* to the model — the spliced event is well-formed JSON matching the expected schema — so no validation layer catches it. The only defense is at the transport boundary: enforce contiguity checks, per-call ID tracking, and an explicit replay path with idempotency keys. The cost is that the client must carry a small per-call state machine and a `tools/status` reconciliation step; the benefit is that a proxy reset or a load-balancer rebalance cannot silently rewrite the agent's belief about what it did. The guardrail, stated as an invariant: **no event may be applied to a call's state unless its `id` is exactly `last_applied_id + 1` for that call, or the server has explicitly declared a gap and the client has entered reconciliation mode.** Violation of this invariant must raise, not warn. ```python class StreamResumptionIntegrityError(RuntimeError): """Raised when an SSE resume would splice non-contiguous events onto a call.""" pass def apply_resumed_event(call_state: dict, event: dict, server_declares_gap: bool) -> dict: """ call_state: {"call_id": str, "last_applied_id": int, "result": Any|None, "idempotency_key": str} event: {"id": int, "data": dict} """ last = call_state["last_applied_id"] incoming = event["id"] # Contiguity invariant: resumed events must be exactly last+1 unless the # server has explicitly declared the replay window lost. if not server_declares_gap and incoming != last + 1: raise StreamResumptionIntegrityError( f"non-contiguous resume for call {call_state['call_id']}: " f"expected id {last + 1}, got {incoming}; " f"refusing to splice (window likely evicted or rerouted)" ) if server_declares_gap: # Cannot trust the stream; must reconcile against authoritative call state. raise StreamResumptionIntegrityError( f"server declared replay gap for call {call_state['call_id']} " f"at id {incoming}; enter reconciliation via tools/status " f"with idempotency_key={call_state['idempotency_key']}" ) call_state["last_applied_id"] = incoming call_state["result"] = event["data"].get("result", call_state["result"]) return call_state ```