# What structural signals indicate an MCP resumable-SSE checkpoint has silently diverged from the server's event log **Date of Record:** 2026 December 2 **Scope:** Applies to MCP servers exposing the HTTP-native streaming transport with `Last-Event-ID` resumption over Server-Sent Events, where a client agent reconnects mid-session after a dropped connection. Does not cover stdio transport, non-resumable SSE, or sessions where the server never emits event IDs. ## Core Distinction A resumable SSE stream has two independent notions of "where the client is": the *client's* `Last-Event-ID` cursor (what the agent believes it has consumed) and the *server's* per-session event log (what was actually emitted). Resumption is correct only when these two agree on a total order. The failure mode is not "the connection dropped" — that is expected and recoverable. The failure is **cursor divergence**: the client reconnects with a `Last-Event-ID` that the server can no longer map to a position in its retained log, and the server *does not error* — it silently replays from the nearest retained event, or from the head, or drops the resume entirely and starts fresh. The stream looks healthy (HTTP 200, `text/event-stream`, heartbeats flowing), yet the agent's reconstructed tool-call state is now missing a contiguous slice of events. The non-obvious part: MCP does not mandate a specific behavior when `Last-Event-ID` falls outside the retained window. The spec requires the server to *support* resumption, but the log retention policy, the replay boundary, and the response to an unresolvable cursor are server-defined. So a well-behaved client cannot assume that "reconnect succeeded" means "no events were lost." That assumption is the bug. ## What Was Observed A tool-calling agent streams a long `tools/call` sequence over SSE. Each server event carries an `id:` field (monotonic per session) and a `data:` JSON-RPC payload. Mid-sequence, the TCP connection is severed by an intermediary (typically a load balancer idle timeout at 60s while the agent is blocked on a slow tool). The agent reconnects with `Last-Event-ID: 4417`. Three distinct server behaviors were observed across deployed MCP servers, all returning HTTP 200: 1. **Bounded-log replay with silent gap.** The server retained only the last 256 events. `4417` had aged out. The server replayed from `4520` (its oldest retained) without signaling the gap. The agent received events `4520…` and treated them as contiguous with `4417`. Tool-call results that arrived in `4418–4519` — including a `tools/call` result the agent was awaiting — were never delivered. The agent's pending-call table held an entry that would never resolve. 2. **Resume-to-head.** The server, unable to satisfy the cursor, replayed only events emitted *after* reconnection. Same silent gap, different mechanism. 3. **Session re-key.** The server had evicted the session on disconnect (common when sessions are keyed to connection lifetime). It issued a new `Mcp-Session-Id` and began a fresh event stream at `id: 1`. The agent, still holding `4417`, now received events numbered *below* its cursor. A naive client applies a monotonicity check (`id > last_seen`) and **discards every subsequent event as a duplicate**, permanently wedging the agent. The tell in all three cases is structural, not exceptional: no error status, no `retry:` hint change, no distinct event type. The stream is indistinguishable from a clean resume at the transport layer. The divergence is only detectable by cross-checking the cursor against the server's declared log semantics — which the server rarely declares. ## Condition of Validity The invariant that makes resumption safe is: > **For a session `S`, the server's retained event log must be a contiguous suffix of the full emitted sequence, and any `Last-Event-ID` outside that suffix must produce an explicit, machine-readable gap signal rather than a silent replay.** This holds only when all of the following are true: - The server advertises its retention bound (e.g., via a capability field or a `retention` parameter in the session-init response), so the client can compute whether its cursor is still resolvable. - Event IDs are **strictly monotonic and session-scoped**, and the server never reuses an ID range across a session re-key. - The client validates on reconnect that the first replayed `id` is exactly `Last-Event-ID + 1` (or, if the server replays the last-seen event inclusively, that it equals `Last-Event-ID`). Any other first-ID is a divergence signal. - Session identity is decoupled from connection identity, so a dropped connection does not silently re-key the session. Where any of these is absent, the client is operating on an *unverified* resume and must treat the reconnected stream as potentially lossy. ## Decision Boundary The boundary is: **does the client trust the cursor, or verify it?** - *Trusting:* on reconnect, accept whatever the server replays and continue. Correct only when retention is unbounded or the client's cursor is provably within the retained window. In practice, never provably true for long-running sessions. - *Verifying:* on reconnect, compare the first replayed event ID against the expected successor of `Last-Event-ID`. If it does not match, the client must (a) not merge the replayed events into its pending-call table, (b) mark the affected tool calls as indeterminate, and (c) either re-issue the calls idempotently or fail the task with a resumable checkpoint. The decision is not "reconnect or not" — reconnecting is cheap and correct. The decision is "after reconnect, do I treat the gap as empty?" The default must be *no*. A gap is a gap until proven empty, and it is proven empty only by an ID-contiguity check, not by a 200 status. A second boundary governs session re-key: if the server returns a *different* `Mcp-Session-Id` on reconnect, the client must invalidate all pending-call state for the old session before consuming the new stream. Failing to do so is what produces the monotonicity-discard wedge — the client's cursor belongs to a dead session, and comparing it against the new session's IDs is comparing across two different total orders. ## Operational Effect The practical consequence is that an agent's pending-call table and the server's event log can desynchronize without any component reporting an error. The agent blocks on a `tools/call` result that was emitted during the gap and will never be replayed; the task hangs until an outer timeout, which the agent misattributes to tool latency rather than to a lost event. In the session-re-key case, the agent discards live events as stale and produces a result computed from a truncated history — a silent correctness failure, not a liveness one, which is worse. The guardrail is a **resume validator** that runs on every reconnect: it enforces ID contiguity, detects session re-key, and refuses to advance the cursor past an unverified gap. The code below implements that validator as the enforcement point. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Optional class ResumeDivergenceError(RuntimeError): """Raised when a resumable SSE reconnect cannot be proven contiguous with the client's Last-Event-ID cursor.""" @dataclass class ResumeCursor: session_id: str last_event_id: int pending_calls: dict[str, str] = field(default_factory=dict) @dataclass class ReconnectFrame: session_id: str first_event_id: Optional[int] # None if stream opened but no event yet retention_floor: Optional[int] # oldest retained id, if server advertises it def validate_resume(cursor: ResumeCursor, frame: ReconnectFrame) -> None: """Enforce the resume invariant before any replayed event is consumed. Three checks, each corresponding to an observed silent-divergence mode: 1. session re-key -> cursor belongs to a dead total order 2. cursor aged out -> gap between last_event_id and retention_floor 3. non-contiguous -> first replayed id != last_event_id + 1 """ if frame.session_id != cursor.session_id: raise ResumeDivergenceError( f"session re-keyed: cursor session {cursor.session_id!r} " f"!= reconnect session {frame.session_id!r}; " f"pending calls {list(cursor.pending_calls)} are indeterminate" ) if frame.retention_floor is not None and cursor.last_event_id < frame.retention_floor - 1: raise ResumeDivergenceError( f"cursor {cursor.last_event_id} aged out of retained log " f"(floor {frame.retention_floor}); events " f"{cursor.last_event_id + 1}..{frame.retention_floor - 1} are lost" ) if frame.first_event_id is None: # Stream opened but server emitted nothing yet. Acceptable only if the # server is idle; do NOT advance the cursor. return expected = cursor.last_event_id + 1 if frame.first_event_id != expected: raise ResumeDivergenceError( f"non-contiguous resume: expected first id {expected}, " f"got {frame.first_event_id}; refusing to merge replayed events" ) def apply_resume(cursor: ResumeCursor, frame: ReconnectFrame) -> ResumeCursor: """Validate, then advance. On divergence, quarantine pending calls instead of silently continuing.""" try: validate_resume(cursor, frame) except ResumeDivergenceError: # Do not drop state: mark every pending call as indeterminate so the # caller can re-issue idempotently or fail the task at a checkpoint. for call_id in cursor.pending_calls: cursor.pending_calls[call_id] = "indeterminate" raise if frame.first_event_id is not None: cursor.last_event_id = frame.first_event_id return cursor ```