# What structural signals indicate MCP stream resumption has silently lost message-ordering guarantees **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers streaming multi-part tool results or resource reads over HTTP/SSE or stdio transports with `Last-Event-ID`-style resumption and bounded backpressure windows. Does not apply to single-shot request/response tool invocations with no partial-result streaming, nor to transports that guarantee exactly-once ordered delivery at the protocol layer. ## Core Distinction The failure mode is not "the stream broke." Streams break constantly and that is expected. The failure mode is that a stream **resumed successfully but non-linearly**: the client reconnected, the server accepted the `Last-Event-ID`, the client received a syntactically valid continuation, and yet the reassembled message sequence has a gap or a reordering that no layer reports as an error. The distinction that matters operationally is between *resumption that is acknowledged* and *resumption that is correct*. MCP's resumption handshake negotiates a cursor, not a proof of contiguity. A server under backpressure can honor a cursor while having already evicted the segment the cursor points into, and it will happily resume from the nearest surviving event — producing a stream that parses, validates against the schema, and is missing exactly the tool-call deltas that carried the mutation the agent needed. This is a boundary condition, not a bug class. It lives precisely at the seam where the server's bounded outbound buffer (backpressure) meets the client's cursor-based reconnection (resumption). Neither side owns the invariant "the bytes between cursor N and cursor M were delivered exactly once, in order." Both sides assume the other enforces it. ## What Was Observed A filesystem MCP server exposed a `read_multiple` tool that streamed one JSON event per file over SSE, each with a monotonically increasing `id`, and supported `Last-Event-ID` resumption. The server held a 256-event ring buffer for replay; on overflow it dropped the oldest events to make room. Under a burst of concurrent large reads, the agent's client hit a read timeout at event 512 and reconnected with `Last-Event-ID: 512`. The server's ring buffer had, by then, advanced to hold events 700–955. Event 512 no longer existed. The server's resumption logic did not distinguish "cursor not found because it is too old" from "cursor not found because it was never issued." It resumed from the oldest surviving event, 700, and emitted a `resume` frame that the client accepted. The client's assembler concatenated events 1–512 with events 700–955 and handed the agent a result set in which 187 files were silently absent — not errored, not flagged, absent. The agent, treating the tool result as authoritative, proceeded to write a manifest asserting those files did not exist. The structural signals present in that trace, in order of how early they were observable: 1. **A resumed cursor that does not appear in the replay window.** The `Last-Event-ID` the client sent was strictly less than the server's oldest retained `id`. The correct response is a hard `resume_rejected` error forcing a full re-read; the observed response was a soft resume. 2. **A non-contiguous `id` jump across the resume boundary.** The first event after resume had `id=700` while the client's last-seen was `id=512`. The gap of 188 is the exact count of lost events. This is the single most reliable signal and it is purely structural — it requires no semantic understanding of the payload. 3. **A `resume` control frame that carries no acknowledged-cursor field.** The server did not echo back which cursor it actually resumed from, so the client could not compare "what I asked for" against "what you gave me." 4. **Backpressure-induced eviction with no eviction notification.** The ring buffer drop was logged server-side as routine housekeeping, never surfaced to the stream. ## Condition of Validity The invariant "a resumed stream is contiguous" holds **only if** the server's replay window is guaranteed to contain the requested cursor at the moment of resumption, **or** the server rejects resumption for any cursor it cannot prove it can serve contiguously. The moment the replay buffer is bounded (which it must be, under backpressure) and eviction is allowed (which it must be, to bound memory), the invariant is no longer guaranteed by construction — it must be enforced by an explicit check. Concretely, the guardrail is: **the server must reject any `Last-Event-ID` strictly less than its oldest retained event id, and the client must reject any resumed stream whose first `id` is not exactly `last_seen_id + 1`** (or, where ids are not dense integers, whose first event does not carry an explicit `resumed_from` field equal to the requested cursor). Either side alone can enforce this; both sides enforcing it is what makes the failure non-silent. The check is O(1) and requires no payload inspection. This condition is *not* satisfied by "the server logged the eviction." Logging is not a stream signal. It is *not* satisfied by schema validation of the resumed events, because each individual event is valid; only the *sequence* is invalid. Sequence-level invariants require sequence-level checks at the resume boundary. ## Decision Boundary The decision the system must make at resume time is binary and must be made explicitly rather than defaulted: - **If the requested cursor is within the retained window:** resume contiguously, echo `resumed_from=` in the control frame, and the client asserts first-event continuity before delivering to the agent. - **If the requested cursor is below the retained window (evicted):** do **not** resume from the nearest event. Return a terminal `resume_rejected` with the reason `cursor_evicted` and the retained range. The client must then either re-issue the full request or surface a partial-result-with-explicit-gap to the agent, depending on whether the tool is idempotent and re-runnable. The boundary is crossed the instant the server chooses "nearest surviving event" over "reject." That choice is almost always made implicitly, by an `if cursor in buffer: resume() else: resume_from_oldest()` pattern, and it is the entire bug. The correct pattern is `if cursor in buffer: resume() else: reject()`. There is no third option that preserves the contiguity invariant. For the agent layer, the decision boundary determines whether the tool result is *trustworthy as a complete set* or *must be treated as a partial with known holes*. An agent that cannot distinguish these will confabulate the missing region — as it did here, asserting non-existence of 187 files. ## Operational Effect The downstream effect is not a crash; it is a **silent completeness violation that propagates into agent belief state**. The agent's working memory now contains a tool result that is internally consistent, schema-valid, and wrong by omission. Any subsequent reasoning that treats "the tool returned the complete set" as a premise is corrupted, and because the corruption is an absence rather than a contradiction, no later verification step will catch it unless that step independently re-derives the expected cardinality. The mitigation is to make the resume boundary carry an explicit, machine-checkable continuity assertion, and to make the agent refuse to treat any streamed multi-part result as complete unless it received a terminal `complete` frame whose event count matches the sum of delivered events plus the declared total. A stream that ends without that frame — whether because of eviction, timeout, or transport death — must be surfaced to the agent as `PartialResult(known_gaps=[...])`, never as a plain result. The invariant to encode is: **completeness is asserted by the server and verified by the client against a total count; absence of the assertion is absence of completeness, not evidence of it.** The following guard implements the boundary check on both sides of the resume seam. ```python from dataclasses import dataclass, field from typing import Optional class ResumeContiguityError(RuntimeError): """Raised when a resumed MCP stream cannot be proven contiguous.""" pass @dataclass class ReplayWindow: oldest_id: int newest_id: int events: dict = field(default_factory=dict) # id -> payload def can_serve(self, cursor: int) -> bool: # A cursor is servable only if the *next* event after it is retained. # Cursor == newest_id means "nothing new yet", which is servable (empty resume). return cursor >= self.oldest_id - 1 and cursor <= self.newest_id def resume_stream(window: ReplayWindow, last_event_id: int) -> dict: """Server-side resume. Rejects evicted cursors instead of silently skipping.""" if not window.can_serve(last_event_id): raise ResumeContiguityError( f"cursor_evicted: requested Last-Event-ID={last_event_id} " f"but retained range is [{window.oldest_id}, {window.newest_id}]; " f"refusing to resume from nearest surviving event" ) resumed_from = last_event_id first_new_id = last_event_id + 1 if first_new_id in window.events: # Assert the retained window is actually dense at the seam. if first_new_id - 1 != resumed_from: raise ResumeContiguityError( f"seam_gap: expected first event id {resumed_from + 1}, " f"got {first_new_id}" ) return {"resumed_from": resumed_from, "first_new_id": first_new_id} def verify_resumed_stream(client_last_seen: int, resumed_frame: dict, first_event_id: int) -> None: """Client-side check: refuse to deliver a resumed stream that is not contiguous.""" if resumed_frame.get("resumed_from") != client_last_seen: raise ResumeContiguityError( f"resume_ack_mismatch: asked {client_last_seen}, " f"server resumed from {resumed_frame.get('resumed_from')}" ) if first_event_id != client_last_seen + 1: raise ResumeContiguityError( f"resume_discontinuity: last_seen={client_last_seen}, " f"first_resumed_event={first_event_id}, " f"gap={first_event_id - client_last_seen - 1} events lost" ) ```