# Under what conditions must an instance refuse MCP stream resumption when the Last-Event-ID cursor has been reaped by the server's replay window **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients operating over the HTTP-native transport with Server-Sent Events streaming and `Last-Event-ID`-based resumption (SSE reconnect semantics). Does not apply to stdio transport, to stateless request/response MCP servers, or to servers that advertise no event replay capability. ## Core Distinction There are two superficially similar reconnection scenarios in MCP HTTP-native streaming, and they demand opposite client behaviors: 1. **Transient disconnect with a live replay window.** The TCP/HTTP connection drops; the server retains the event buffer keyed by the last emitted `id`; the client reconnects with `Last-Event-ID` and resumes from the exact byte/event boundary. The correct action is *resume*. 2. **Disconnect where the requested cursor has been reaped.** The client reconnects with a `Last-Event-ID` that the server has already evicted from its bounded replay buffer. The server, per the SSE spec's resumption guidance, may either (a) silently start a fresh stream from the current head, or (b) honor the connection but deliver events that do not continue the prior sequence. The non-obvious boundary: **a successful HTTP 200 with an open event stream is not proof of continuity.** The failure mode is that the transport *succeeds* while the logical session *silently forks*. The client believes it resumed; the server delivered a fresh head. Any agent that treats "stream re-opened" as "state preserved" will corrupt its session. ## What Was Observed A tool-calling agent maintained an MCP session against an HTTP-native server emitting tool-progress and partial-result events. Each event carried an `id`. During a long-running `search` tool call, the client's network path flapped for ~40 seconds. The server's replay buffer was bounded to the last 256 events *and* a 30-second TTL — both evicted the client's cursor before reconnect. On reconnect the client sent `Last-Event-ID: 1841`. The server accepted the connection and returned `200 OK` with `text/event-stream`. It then emitted events beginning at `id: 1902` — the current head — because 1841 through 1901 had been reaped. No error, no `400`, no explicit gap signal. The client's resumption handler assumed monotonic continuation: it validated only that the stream opened and that subsequent event `id`s were *greater than* the last seen. `1902 > 1841`, so the guard passed. The agent resumed its reasoning loop with the last-known partial tool result from event 1841 and appended event 1902's payload — which was a *different* tool invocation's progress chunk (the server had multiplexed a second concurrent call into the same stream). The agent fused two unrelated tool call trajectories into one, produced a hallucinated final answer that cited a result never returned for that call, and committed it to episodic memory. The trace: ``` client.last_event_id = 1841 server.buffer.head = 1902 (1841..1901 reaped, TTL + count) --> reconnect: Last-Event-ID: 1841 <-- 200 OK text/event-stream <-- id: 1902 event: progress data: {"call":"B","pct":40} client guard: 1902 > 1841 => PASS (WRONG) client appends 1902 to trajectory of call "A" ``` The defect is not in the transport. It is in the client's continuity invariant: **`id` monotonicity is necessary but not sufficient for session continuity.** The gap `1841 → 1902` is exactly the signal that must *fail* the guard, and the naive "greater than" check discards it. ## Condition of Validity Resumption is valid **iff** the client can prove the first event received after reconnect is the immediate successor of its last-seen event, or that the server explicitly attests to gap-free continuation. Concretely, resumption is safe only when at least one holds: - **Contiguous successor:** the first post-reconnect event `id` is the expected successor under the server's id scheme (`last_seen + 1` for integer ids), *and* the server's id scheme is declared contiguous. If ids are opaque strings or non-contiguous, this test is unavailable and a different attestation is required. - **Explicit resume acknowledgement:** the server emits a resume-control event (e.g., `event: resume` with `data: {"from": 1841, "contiguous": true}`) before any payload event. Absent this, the client has no proof. - **Snapshot re-baseline:** the server offers a `resume_token`/state digest the client can compare against its own pre-disconnect digest; a mismatch forces a clean re-initialization rather than a resume. If none hold, the invariant that must be enforced is: **treat the reconnect as a new session, discard in-flight partial state, and re-issue the tool call idempotently.** The client must *refuse* to splice. ## Decision Boundary The boundary is the gap-detection predicate, and it must be strict: - If `first_id_after_reconnect == expected_successor(last_seen_id)` **and** the id scheme is declared contiguous → resume, splice is legal. - If `first_id_after_reconnect > expected_successor(last_seen_id)` → **gap detected** → do not splice; escalate to re-baseline. - If `first_id_after_reconnect <= last_seen_id` → server reset the stream (new head behind old cursor) → **do not splice**; treat as forked session. - If the server cannot declare its id scheme as contiguous → the contiguity test is undefined → **default to refuse-and-rebaseline**. The critical rule: **a gap is a failure, not a warning.** The client must not "resume past" a gap and continue appending, because the missing events may contain tool-call boundaries, cancellation signals, or terminal results. Appending across a gap is the mechanism that produces trajectory fusion. ## Operational Effect When the client enforces the strict predicate: 1. On gap, the agent aborts the in-flight reasoning step, marks the tool call `indeterminate`, and re-invokes it with an idempotency key so the server can deduplicate. 2. The partial result from before the gap is quarantined, not committed to episodic memory — it is a *lower bound*, not a fact. 3. The session's continuity flag is set to `rebaselined`, and downstream verification (auditor agents, replay checks) is told the trajectory contains a discontinuity so it does not treat the post-gap events as causally downstream of the pre-gap ones. When the client does *not* enforce it, the observed effect is trajectory fusion: two logical tool-call streams merged into one, a fabricated result, and — because the fabricated result was written to semantic memory — a persistent contamination that outlives the session and poisons later retrievals. The blast radius of a single missed gap is unbounded in time. The invariant to carry forward: **the transport layer's success is orthogonal to the session layer's continuity; only an explicit contiguity proof bridges them, and its absence is a refusal condition, not a retry condition.** ```python from dataclasses import dataclass from typing import Optional class ResumptionContinuityError(RuntimeError): """Raised when a resumed MCP SSE stream cannot prove gap-free continuation.""" @dataclass class ResumeState: last_seen_id: int id_scheme_contiguous: bool server_attested_resume: bool = False def validate_resumption(state: ResumeState, first_id_after_reconnect: int) -> None: """ Enforce the continuity invariant before allowing the client to splice post-reconnect events onto the pre-disconnect trajectory. Raises ResumptionContinuityError if continuity cannot be proven. """ if state.server_attested_resume: return # explicit resume-control event satisfies the invariant if not state.id_scheme_contiguous: # Without a declared contiguous id scheme, contiguity is undefined. raise ResumptionContinuityError( f"cannot prove continuity: id scheme not declared contiguous " f"(last_seen={state.last_seen_id}, first_after={first_id_after_reconnect})" ) expected = state.last_seen_id + 1 if first_id_after_reconnect == expected: return # contiguous successor: splice is legal if first_id_after_reconnect > expected: raise ResumptionContinuityError( f"gap detected: cursor reaped; expected {expected}, " f"server resumed at {first_id_after_reconnect}. " f"Refuse splice; re-baseline and re-issue tool call idempotently." ) # first_id_after_reconnect <= last_seen_id raise ResumptionContinuityError( f"stream reset behind cursor: last_seen={state.last_seen_id}, " f"first_after={first_id_after_reconnect}. Treat as forked session." ) def resume_stream(state: ResumeState, first_id_after_reconnect: int) -> str: try: validate_resumption(state, first_id_after_reconnect) return "resumed" except ResumptionContinuityError: # Escalate: quarantine partial state, mark call indeterminate, re-baseline. return "rebaselined" ```