# When must an instance refuse to resume an MCP SSE stream after a Last-Event-ID gap rather than silently replaying from a stale cursor **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers exposing HTTP-native transport with `text/event-stream` streaming and `Last-Event-ID`-based session resumption (Streamable HTTP transport, single or multi-client). Does not apply to stdio transport, WebSocket-only variants, or stateless one-shot request/response MCP endpoints where no event cursor is persisted. ## Core Distinction The distinction that matters is between **resumption as a cursor seek** and **resumption as a continuity proof**. Most MCP HTTP implementations treat `Last-Event-ID` as a seek hint: the client reconnects with the last ID it saw, the server looks up its event log, and if the ID is present it replays everything after it. This is correct only when the server can prove that no event between the client's acknowledged cursor and the current head was *dropped from the log*. It cannot make that proof under backpressure, because backpressure is precisely the condition under which the server discards events to protect its own memory — and the discard is invisible to the cursor. The non-obvious boundary: **a server that has applied backpressure eviction to its event ring buffer must not honor a `Last-Event-ID` that predates the oldest retained event, even if that ID is still technically resolvable via a secondary index.** The failure is not "ID not found." The failure is "ID found, but the contiguous range `(Last-Event-ID, head]` is no longer fully materialized." Resuming in that case produces a silently truncated tool-call stream — the agent believes it has the full transcript of a `tools/call` result and proceeds on a partial JSON-RPC frame. ## What Was Observed A research agent drove a long-running MCP tool (`web_crawl` over a 4,000-page corpus) through an HTTP-native MCP server. The server streamed progress notifications and a final `tools/call` result as SSE events, each tagged with a monotonically increasing `id:`. The server's event log was a bounded ring buffer (capacity 2,048 events) with an eviction policy: when full, the oldest events were dropped and their IDs tombstoned in a side index so that "unknown ID" lookups still returned a 200 with a `replay_from` hint rather than a hard 404. Mid-crawl, the client's TCP connection stalled (mobile hotspot handoff). The server kept producing events — per-page progress notifications at roughly 40/sec — and the ring buffer evicted 1,900 old events before the client reconnected 47 seconds later. The client sent `Last-Event-ID: 1180`. The server's side index resolved 1180 to a tombstone, computed `replay_from = 1181`, found that 1181 was *also* evicted, and — because its tombstone resolver only checked whether the *requested* ID was known, not whether the *entire interval* was retained — fell back to `replay_from = oldest_retained_id = 3080`. It then replayed from 3080 and emitted the head, and closed the stream with a normal `event: done`. The client received events 3080..3190 (a contiguous tail), no gap marker, no error. The final `tools/call` result was a JSON object whose `pages` array had been split across events 2900–3190; the client assembled only the 3080+ fragment and parsed it as a complete result because the fragment happened to end on a valid `}` boundary of a sub-object. The agent reported "crawl complete, 4,000 pages" using a result payload that contained 111 pages. No exception was raised anywhere. The discrepancy was caught only when a downstream verifier agent re-fetched a sample and found 96% of cited pages missing from the claimed result. The mechanism: **backpressure eviction created a hole in the cursor space; the tombstone resolver treated "known ID" as "resumable ID" and silently re-anchored the replay at the oldest retained event, converting a detectable gap into an undetectable truncation.** ## Condition of Validity The invariant that must hold for cursor-seek resumption to be sound: > For any `Last-Event-ID = k` accepted by the server, the set of events with IDs in `(k, head]` must be *fully materialized* in the replay source at the moment of replay, and the replay must emit them in order with no internal gap. This invariant is violated by any of: 1. **Ring-buffer eviction** where `k < oldest_retained_id` and the server does not have a durable log to fall back on. 2. **Per-connection backpressure drop** where the server, under slow-consumer pressure, drops intermediate events *for that connection* but keeps advancing the head cursor — so the client's acknowledged cursor lags a hole that the server has already forgotten it made. 3. **Multi-writer interleaving** where two server replicas share a logical event log but each holds a partial segment, and the replica that answers the reconnect does not hold the segment containing `k`. 4. **Compaction** where progress events are coalesced (e.g., "page 3000 of 4000" replacing 2,990 individual notifications) and the coalesced event's ID is *newer* than the events it summarizes — resuming from a pre-compaction cursor yields a head that skips the coalesced range. The condition of validity therefore is: **resumption is sound iff the server can assert interval-contiguity, not merely ID-presence.** A server that cannot assert contiguity must fail the resume loudly (a resumability error the client can act on) rather than re-anchor. ## Decision Boundary The decision boundary is between three server behaviors on a resume request, and only one is correct under backpressure: - **Re-anchor (wrong):** `Last-Event-ID` is known-but-evicted → replay from `oldest_retained_id`. Produces silent truncation. This is the observed failure. - **Hard reject (correct but lossy):** `Last-Event-ID` is known-but-evicted → return a resumability error with the retained interval `[oldest_retained_id, head]` so the client knows it must re-issue the original `tools/call` with a fresh session, not splice a fragment onto stale state. - **Durable fallback (correct and lossless, when available):** if the server has a durable event log (WAL, object store) covering `(k, oldest_retained_id]`, replay from it transparently and only then from the ring buffer. This is the only path that permits a *successful* resume across a backpressure eviction. The boundary condition the client must enforce independently: **a resumed stream is only valid if the first replayed event's ID equals `Last-Event-ID + 1`** (contiguous) or the server explicitly declares a gap via a `resume_gap` control event carrying the skipped interval. If the first replayed ID is strictly greater than `Last-Event-ID + 1` with no gap declaration, the client must treat the session as corrupted and discard any partial tool-result assembly. ## Operational Effect The operational effect of getting this wrong is **silent partial-result acceptance in the agent's execution loop**: the agent completes a `tools/call` with a truncated payload, marks the step successful, and compounds the error into every downstream step that consumes the result. Because the truncation lands on a syntactically valid sub-object boundary (JSON is not self-delimiting at the frame level), no parser error fires. The only reliable detector is a semantic cross-check — re-fetching a sample, or comparing a claimed count against a server-reported total — which is exactly the check that a token-budget-constrained agent is most likely to skip. The guardrail is twofold. Server-side: maintain an explicit `oldest_retained_id` and reject any `Last-Event-ID < oldest_retained_id - 1` with a structured resumability error unless a durable log covers the interval; never re-anchor silently. Client-side: enforce the contiguity check on the first replayed event and require an explicit gap declaration to proceed; on gap, abort the in-flight tool call and re-issue rather than splice. Both must hold, because the server cannot know whether the client can tolerate a gap and the client cannot know whether the server evicted. ```python import json from dataclasses import dataclass class ResumeContiguityError(RuntimeError): """Raised when an MCP SSE resume cannot prove interval-contiguity.""" @dataclass class EventLog: oldest_retained_id: int head_id: int durable_floor_id: int | None # lowest ID covered by durable WAL, if any def covers(self, last_event_id: int) -> bool: # The interval (last_event_id, head_id] must be fully materialized # in either the durable log or the ring buffer. if last_event_id >= self.head_id: return True # nothing to replay if self.durable_floor_id is not None and last_event_id + 1 >= self.durable_floor_id: return True # durable log bridges the eviction hole return last_event_id + 1 >= self.oldest_retained_id def plan_resume(log: EventLog, last_event_id: int) -> int: """Return the first event ID to replay, or raise on an unsound resume.""" if last_event_id < 0: raise ResumeContiguityError(f"invalid Last-Event-ID {last_event_id}") if last_event_id > log.head_id: raise ResumeContiguityError( f"Last-Event-ID {last_event_id} is ahead of head {log.head_id}" ) if not log.covers(last_event_id): raise ResumeContiguityError( "resume gap: Last-Event-ID " f"{last_event_id} predates retained interval " f"[{log.oldest_retained_id}, {log.head_id}] with no durable coverage; " "client must re-issue the original tools/call, not splice" ) return last_event_id + 1 def validate_first_replayed(declared_gap: tuple[int, int] | None, last_event_id: int, first_replayed_id: int) -> None: """Client-side contiguity check on the first event of a resumed stream.""" if declared_gap is not None: gap_start, gap_end = declared_gap if gap_start != last_event_id + 1 or gap_end >= first_replayed_id: raise ResumeContiguityError( f"malformed gap declaration {declared_gap} for cursor {last_event_id}" ) return if first_replayed_id != last_event_id + 1: raise ResumeContiguityError( f"non-contiguous resume: expected {last_event_id + 1}, " f"got {first_replayed_id}; partial tool-result assembly is unsafe" ) # Observed failure, replayed against the guardrail: log = EventLog(oldest_retained_id=3080, head_id=3190, durable_floor_id=None) try: plan_resume(log, last_event_id=1180) # the silent-truncation case except ResumeContiguityError as e: print("rejected as expected:", e) ```