# What happens when an instance resumes an MCP stream after a transport drop and the server has already advanced its JSON-RPC cursor **Date of Record:** 2026 November 21 **Scope:** Applies to MCP servers/clients using HTTP-native streaming transports (SSE-style or chunked long-lived response bodies) where the client resubscribes via `Last-Event-ID` or an equivalent resumption token, and where the server maintains a per-session event cursor. Does not apply to stdio transports, nor to stateless request/response MCP deployments where every call is independently addressable. ## Core Distinction The failure is not "the connection dropped." The failure is that **stream resumption and session re-establishment are two different contracts that share one identifier namespace**, and the MCP HTTP transport spec lets a client conflate them. A resumption token (`Last-Event-ID`) is a *position in a durable event log*. A session ID (`Mcp-Session-Id`) is a *handle to server-side execution state*. When a client reconnects, it must present both, and the server must decide which of the two is authoritative when they disagree. The non-obvious boundary is this: **if the server has garbage-collected or compacted the event log past the client's cursor, a well-formed resumption request silently becomes a fresh session** — the server accepts the request, returns `200`, and begins streaming from "now," because there is no event at or after the requested cursor to replay. The client sees a healthy stream and believes it resumed. It did not. It lost every event between its last-seen ID and the server's current head, and — critically — it has no protocol-level signal that this happened. ## What Was Observed A tool-calling agent (client) was mid-execution on a long-running `tools/call` against an MCP server that streamed progress notifications and, eventually, the final result over an HTTP SSE body. The client tracked `Last-Event-ID` per the spec and persisted it to its checkpoint store after each event, so that a crash-resume could reattach. The transport dropped (a load-balancer idle timeout at 60s, well under the server's 300s event retention window — this detail matters). The client reconnected within ~2s, sending: ``` GET /mcp HTTP/1.1 Mcp-Session-Id: sess_7f3a... Last-Event-ID: evt_00412 Accept: text/event-stream ``` The server's session was still alive. But the server had, between the drop and the reconnect, executed a **compaction pass**: it collapsed the progress-notification stream (events `evt_00413`–`evt_00489`, mostly redundant `progress` frames) into a single `evt_00490` snapshot event, and *deleted the intermediate events from the replay log* to bound memory. The session's execution state was intact — the tool was still running, the final result had not yet been emitted. But `evt_00412` no longer existed and no event with a lower-or-equal ID remained. The server's resumption handler did what most implementations do: it looked up `Last-Event-ID` in the replay buffer, found nothing, and **fell through to "start streaming live events."** It did not error. It did not send a `resync` control frame. It returned `200` with an SSE body whose first event was `evt_00490` — the compaction snapshot — followed by live events. From the server's perspective, this was correct: it delivered the current state. From the client's perspective, it had requested a *replay from position 412* and received a *snapshot at position 490* with no marker distinguishing the two. The agent's state machine consumed `evt_00490` as if it were the next event after `evt_00412`. The snapshot's payload was a `progress` aggregate (`progress: 0.94`) rather than the per-step `partial_result` frames the agent's parser expected. The agent's progress handler, written defensively, ignored unknown shapes — so it did not crash. It simply **never observed the intermediate partial results** that its own planning loop used to decide whether to abort the tool call early. It continued waiting. The tool ran to completion (~40s later), returned a final result that the agent's plan had already been invalidated against by the missing intermediates, and the agent committed a downstream write based on a partial-result path it had silently skipped. The observable signature, post-hoc: the agent's event log showed a gap `evt_00412 → evt_00490` with no `resync` frame, no error, and a `200` status. Every layer reported success. ## Condition of Validity The invariant that must hold for safe resumption is: > **A resumed stream must be provably contiguous with the prior stream, or explicitly marked as discontinuous.** "Provably contiguous" means the server can produce an event whose ID is the immediate successor of `Last-Event-ID`, *or* it can produce a signed/structured `resync` frame stating "I cannot replay from your cursor; here is my current head and a state snapshot; treat all state between your cursor and my head as unknown." "Explicitly marked discontinuous" means the client is told, in-band, that it must re-derive state rather than assume continuity. This fails whenever the following three conditions co-occur: 1. **The server prunes or compacts its replay log** (memory bound, retention TTL, or dedup) — so the requested cursor becomes unreachable. 2. **The server's fallback for an unreachable cursor is "stream from head" rather than "emit resync/error"** — the common, spec-permitted behavior. 3. **The client treats any `200` + SSE body as a successful resumption** — i.e., it gates on transport success, not on cursor continuity. Remove any one and the failure is bounded. Remove (1): cursor always replayable. Remove (2): client gets an explicit discontinuity signal and can re-derive. Remove (3): client detects the ID gap and refuses to proceed. The condition of validity is therefore narrow: **resumption is safe only when the client independently verifies cursor continuity (successor-ID check or presence of an explicit resync frame) rather than trusting the transport status code.** The transport status code is a statement about the *connection*, not about the *event log*. ## Decision Boundary The decision boundary is *what the client does when the first event ID after reconnect is not the successor of its last-seen ID.* There are three defensible policies, and the wrong one is the default: - **Abort-and-restart (safe, expensive):** treat the gap as a lost session, discard in-flight plan state, re-issue the `tools/call` idempotently (requires the server to support idempotency keys on tool calls — most do not). Correct but can double-execute side-effecting tools. - **Resync-and-reconcile (safe, requires server cooperation):** on detecting a gap, request an explicit state snapshot (`resources/read` on the session's state resource, or a `resync` control frame), re-derive the plan from the snapshot, and continue. This is the intended design but requires the server to expose a snapshot endpoint and the client to have a re-derivation path. Most agent frameworks do not. - **Assume-continuity (unsafe, default):** consume whatever arrives as if contiguous. This is what the observed agent did, and it is what happens whenever the client's SSE parser is "just parse frames" without a cursor-continuity check. The boundary that must be enforced architecturally: **the client's resumption handler must compare `first_event_after_reconnect.id` against `expected_successor(last_seen_id)` and raise on mismatch before dispatching any event to the agent's state machine.** This is a one-line invariant with outsized consequences, because the agent's planner is *not* robust to silently missing intermediate observations — its early-abort heuristics, its partial-result accumulation, and its budget accounting all assume a contiguous event sequence. A secondary boundary: the server must not conflate "session alive" with "stream resumable." A live session with a compacted log is a live session that cannot honor a resumption. The server should return `409 Conflict` (or a `resync` SSE frame) when `Last-Event-ID` is unreachable, not `200`. The MCP spec's silence on this is the root cause; implementations fill the silence with the permissive behavior. ## Operational Effect In production, this manifests as **silent partial-observation** rather than a crash: the agent completes, reports success, and the corruption surfaces only as a downstream inconsistency (a write based on a plan that skipped a step, a budget that under-counts tokens because intermediate progress frames were never billed, a verification step that passed because it never saw the intermediate that would have failed it). It is invisible to transport-level monitoring (all `200`s), invisible to error-rate dashboards (no errors), and visible only in event-log gap analysis — which nobody runs until an incident. Mitigations, in order of cost: 1. **Client-side cursor-continuity assertion** (cheap, mandatory): reject non-successor first events unless a `resync` frame precedes them. This converts silent corruption into a loud, recoverable error. 2. **Server-side unreachable-cursor signal** (cheap, requires server change): return a structured discontinuity marker instead of falling through to head-streaming. 3. **Durable, non-compacting replay log for the session lifetime** (expensive): eliminates the trigger but does not eliminate the class — retention TTLs and crash-loss still produce unreachable cursors. 4. **Idempotent tool calls with resumption-safe replay** (expensive, correct): allows abort-and-restart without double side effects. The lesson for an agent operating in this environment: **never trust a `200` on reconnect as proof of continuity; always verify the event-ID successor relationship, and treat any gap as a state-loss event requiring re-derivation, not a transport hiccup to be ridden out.** ```python class StreamResumptionDiscontinuity(RuntimeError): """Raised when a resumed MCP stream's first event is not the successor of the client's last-seen event ID, and no explicit resync frame preceded it. Indicates silent event-log loss (compaction, TTL, or cursor unreachability) that the transport status code did not signal.""" pass def verify_resumption_continuity( last_seen_event_id: str, first_event_after_reconnect: dict, resync_frame_seen: bool, ) -> None: """ Enforce the contiguity invariant on MCP HTTP stream resumption. last_seen_event_id: the client's persisted cursor (Last-Event-ID). first_event_after_reconnect: the first SSE event parsed post-reconnect. resync_frame_seen: whether an explicit discontinuity marker preceded it. Raises StreamResumptionDiscontinuity if continuity cannot be proven. """ if resync_frame_seen: # Server explicitly declared discontinuity; client must re-derive # state from the snapshot rather than assume contiguity. return incoming_id = first_event_after_reconnect.get("id") if incoming_id is None: raise StreamResumptionDiscontinuity( f"Resumed stream delivered an event with no ID after cursor " f"{last_seen_event_id!r}; continuity unprovable." ) expected = _successor(last_seen_event_id) if incoming_id != expected: raise StreamResumptionDiscontinuity( f"Resumption gap detected: last_seen={last_seen_event_id!r}, " f"expected_successor={expected!r}, received={incoming_id!r}. " f"Server event log was likely compacted or pruned past the " f"client cursor; intermediate events are lost. Re-derive agent " f"state from a snapshot before dispatching further events." ) def _successor(event_id: str) -> str: # Event IDs are opaque per spec; this assumes the common # monotonic-integer-with-prefix convention (e.g. "evt_00412"). prefix, _, num = event_id.rpartition("_") if not num.isdigit(): # Cannot compute a successor for opaque IDs; require resync. raise StreamResumptionDiscontinuity( f"Event ID {event_id!r} is not successor-computable; " f"client must require an explicit resync frame to resume." ) return f"{prefix}_{int(num) + 1:0{len(num)}d}" ```