# What happens when an instance resumes an MCP stream and the server's push queue has already been drained by a sibling reconnect **Date of Record:** 2026 November 20 **Scope:** Applies to MCP clients using the HTTP-native streaming transport (SSE-over-POST with `Last-Event-ID` resumption) where a server maintains a per-session event buffer and replay cursor. Does not apply to stdio transports, stateless one-shot request/response MCP servers, or transports that do not implement event-ID-based resumption. ## Core Distinction The failure is not "the stream dropped." Streams drop constantly and resumption is designed for exactly that. The failure is a **cursor-ownership split**: two client instances (or two reconnects from the same instance after a non-idempotent retry) attach to the same server-side session, and the server's replay buffer is a single-consumer queue indexed by a monotonic `Last-Event-ID`. Whichever connection presents a higher cursor first advances the server's *drain watermark*. The other connection's `Last-Event-ID` now points behind the watermark, and the server — correctly per its own contract — treats those events as already delivered and emits nothing. The resuming instance believes it has caught up. It has not. It has silently skipped every server-push notification between its last-seen ID and the watermark, and no error is raised because "no events to replay" and "you are up to date" are the same wire signal. This is the MCP analogue of the classic Kafka consumer-group rebalance offset skip, but with a twist unique to the agent layer: the "consumer" is an LLM instance whose next reasoning step depends on the *content* of the missed pushes (tool-result notifications, resource-updated events, sampling requests), and whose context window has no record that anything was missed. The instance resumes with an internally consistent but externally stale world model. ## What Was Observed A long-running agent session (call it `A`) drives a multi-tool workflow against a stateful MCP server. The server pushes asynchronous notifications: `notifications/tools/list_changed`, `notifications/resources/updated`, and progress notifications for long-running tool calls. Each push carries an `id:` field; the server keeps a bounded replay ring (say 512 events) and a `drain_watermark` per `Mcp-Session-Id`. Sequence: 1. `A` is at `Last-Event-ID: 4100`. A transient TCP reset drops the SSE stream. `A`'s transport layer schedules a reconnect with exponential backoff. 2. Before `A`'s backoff fires (t+1.2s), a **supervisor process** — or a second replica of the same agent behind a load balancer sharing the session ID — reconnects with `Last-Event-ID: 4100` and successfully drains events `4101..4127`, advancing `drain_watermark` to `4127`. 3. `A`'s backoff fires at t+3.0s. It reconnects with `Last-Event-ID: 4100`. 4. Server logic: `4100 < drain_watermark (4127)`, therefore "replay from max(Last-Event-ID, watermark)" → replay from `4128`. Server immediately sends the current tail and then live events. No `4101..4127` are re-sent. No gap signal is emitted. 5. `A`'s tool-call loop is now waiting on a progress notification for tool call `tc_88` whose terminal `notifications/progress` (event `4119`) was in the skipped range. `A` polls, times out per its own local budget, and either (a) re-issues the tool call — duplicating a non-idempotent side effect — or (b) marks the tool as failed and diverges its plan. 6. The `list_changed` at `4112` is also lost, so `A` continues invoking a tool schema the server has since replaced. The next call returns a validation error the model interprets as a transient fault, triggering a retry loop. The observable signature in logs is deceptively clean: `resume ok, cursor=4128, live=true`. There is no `gap_detected`, no `events_skipped`, no error frame. The instance's own transcript shows a successful reconnect. ## Condition of Validity The gap-skip is only possible when **all** of the following hold. If any fails, the server either replays correctly or the client detects the gap: - The server's replay buffer is indexed by a **single monotonic drain watermark per session**, not per-connection. (Per-connection cursors eliminate the failure but cost memory proportional to connection count.) - More than one connection can present a `Last-Event-ID` for the same `Mcp-Session-Id` — i.e., the session ID is not bound to a single transport epoch, or a supervisor/replica shares it. - The server treats `Last-Event-ID < watermark` as "nothing to replay" rather than emitting a `resume-gap` control frame or a `410 Gone`-style cursor-invalidated error. - The client does not independently track expected event-ID continuity (i.e., it does not assert `next_id == last_seen_id + 1`). In a correctly-implemented single-consumer MCP session, none of these hold and the failure is unreachable. The boundary is precisely the multi-attach case, which the MCP spec permits implicitly (session IDs are opaque and not required to be single-use) and which real deployments create via supervisors, warm standbys, and load-balancer retries. ## Decision Boundary The architectural choice is: **who owns the cursor, and what does a behind-watermark resume mean?** - **Option A — Server-authoritative watermark, silent skip (current default).** Cheap, bounded memory, but a behind-watermark resume is indistinguishable from a caught-up resume. Unsafe for agents whose plan depends on push content. - **Option B — Server-authoritative watermark, explicit gap signal.** On `Last-Event-ID < watermark`, server emits a control event `notifications/stream/resume_gap` with `{from, to}` before resuming live. Client must treat this as a **state-invalidation event**: discard cached tool schemas, re-query `tools/list`, re-fetch any resource whose `updated` notification fell in the gap, and re-derive in-flight tool-call status by polling `tools/call` status endpoints rather than waiting for progress pushes. This is the correct invariant: *a gap is a cache-invalidation broadcast, not a warning.* - **Option C — Per-connection cursors.** Eliminates the skip but makes the server a fan-out broker with per-connection buffers; only viable for small connection counts and short sessions. The invariant to enforce regardless of option: **a resuming client MUST NOT assume its world model is current after a successful reconnect unless the server has affirmatively confirmed cursor continuity.** "Reconnect succeeded" and "state is coherent" are orthogonal facts. The client-side guardrail is a continuity assertion: track `last_seen_id`, and on resume require either `replayed_from == last_seen_id + 1` or an explicit `resume_gap` frame; otherwise enter a **resync protocol** (re-list tools, re-read resources, poll in-flight calls) before resuming reasoning. ## Operational Effect Without the guardrail, the failure manifests as **silent plan divergence with duplicate side effects**. The instance does not crash; it produces a plausible but wrong continuation. The two dominant downstream effects: 1. **Non-idempotent tool re-execution.** Lost progress notifications cause the agent to conclude a tool call stalled and re-issue it. If the tool is a payment, a file write, or an external API mutation, the side effect doubles. This is the highest-severity consequence and is invisible to the agent's own transcript. 2. **Stale-schema invocation.** Lost `list_changed` notifications leave the agent calling tools with outdated argument schemas; the resulting validation errors are misread as transient and drive retry storms that consume token budget without progress. The remediation is not "retry harder" but **treating the resume gap as a mandatory state-invalidation trigger**. The code below encodes the client-side continuity invariant: it refuses to resume reasoning on a behind-watermark reconnect until a full resync has been performed, raising a specific error that the orchestrator must handle by draining the resync protocol before continuing. ```python class StreamResumeGapError(RuntimeError): """Raised when an MCP HTTP stream resumes behind the server drain watermark. A behind-watermark resume means the server will NOT replay events between last_seen_id and the watermark, and will emit no gap signal unless the server implements the resume_gap control frame. The client MUST NOT resume reasoning on this session until a full resync (tools/list, resources re-read, in-flight call status poll) has completed, because lost push notifications may include tool-schema changes and terminal progress events. """ def resume_stream( last_seen_id: int, server_watermark: int, *, gap_signal_received: bool, replayed_from: int | None, ) -> int: """Validate cursor continuity on reconnect and return the first live event id. Contract: - If the server sent an explicit resume_gap frame, the caller must run the resync protocol before consuming live events; we return the live cursor but the caller is responsible for invalidation. - If replayed_from is None (nothing to replay) AND last_seen_id is behind the watermark AND no gap signal was sent, this is the silent-skip case: raise, do not proceed. - If replayed_from == last_seen_id + 1, continuity holds; safe to proceed. """ if replayed_from is not None and replayed_from == last_seen_id + 1: # Clean continuity: no events were skipped. return replayed_from behind = last_seen_id < server_watermark skipped = server_watermark - last_seen_id if behind and not gap_signal_received: # The dangerous case: server drained events [last_seen_id+1 .. watermark] # to a sibling connection and will not replay them. No error frame. raise StreamResumeGapError( f"Silent resume gap: last_seen_id={last_seen_id} " f"< watermark={server_watermark}; {skipped} events unreplayed " f"and no resume_gap frame received. Refusing to resume reasoning; " f"run full resync (tools/list, resources re-read, in-flight poll)." ) if behind and gap_signal_received: # Server was honest about the gap. Caller must resync before reasoning. # We surface the live cursor but the caller is obligated to invalidate. return server_watermark + 1 # Not behind the watermark: either caught up or ahead (shouldn't happen; # treat as a protocol violation rather than guessing). if last_seen_id > server_watermark: raise StreamResumeGapError( f"Cursor ahead of server watermark: last_seen_id={last_seen_id} " f"> watermark={server_watermark}. Server state was reset or " f"session ID reused across epochs; abandon session and re-init." ) return last_seen_id + 1 ```