# How does an instance detect silent resumption-token divergence in MCP streamable HTTP transport under backpressure-aware chunked delivery **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers exposing the streamable HTTP transport with `Mcp-Session-Id` and event-ID-based resumption (`Last-Event-ID`), where the server buffers or chunks responses under backpressure. Does not cover stdio transport, SSE-only legacy transport, or stateless request/response MCP servers with no session store. ## Core Distinction The failure mode is not connection loss, not token expiry, and not a malformed `Last-Event-ID`. It is *silent divergence between the resumption cursor the client believes it holds and the replay boundary the server actually honors*, introduced specifically by backpressure-induced chunk coalescing. When a server applies backpressure, it may merge multiple logical SSE events into a single TCP/chunked write, or drop intermediate events from the outbound queue while retaining the final event ID. The client's `Last-Event-ID` advances to the last event it *received*, which may be numerically later than the last event the server *durably recorded as replayable*. On reconnect, the server replays from its own cursor, not the client's, and the gap is invisible because both sides report success. The distinction that matters operationally: a lost connection is *detectable* (socket error, timeout, missing `id:`), whereas cursor divergence is *not* — the resumed stream is syntactically valid, the session ID matches, and the server returns HTTP 200. The agent continues reasoning on a stream with a hole in it. ## What Was Observed A tool-calling agent maintained an MCP session against a server that emitted progress notifications and partial tool results as SSE events, each tagged with a monotonic `id:`. Under load, the server's writer goroutine coalesced events `e41..e47` into one chunk while its replay buffer (a bounded ring buffer of 256 events, keyed by event ID) evicted `e41..e43` before the chunk flushed, because the eviction policy was driven by *enqueue time* rather than *flush acknowledgment*. The client received the coalesced chunk, parsed only the terminal `id: e47` as the resumption cursor (a common client-side bug: taking the last ID in a multi-event chunk), and stored `Last-Event-ID: e47`. The connection then dropped on an idle timeout. On reconnect the client sent `Last-Event-ID: e47`. The server, whose replay buffer now held `e44..e47` but whose *durable* replay log (a separate, slower append-only store) had only committed through `e40`, replayed from `e44`. Events `e41..e43` — which contained three intermediate tool-result fragments the agent needed to reconstruct a `create_order` payload — were never delivered and never re-requested. The agent proceeded to call `finalize_order` with an incomplete line-item set. No error was raised at any layer. The observable signature was downstream and delayed: a validation failure on the finalize call that referenced a missing fragment, appearing ~40 seconds after the actual data loss, with a stack trace pointing nowhere near the transport. ## Condition of Validity The divergence requires the conjunction of four conditions; remove any one and detection collapses to a trivial case: 1. **Coalesced multi-event chunks.** The server writes more than one SSE event per flush. If every event is its own flush, the client's last-ID is always an event the server flushed, and eviction-before-flush cannot occur. 2. **Replay buffer keyed by enqueue, evicted by capacity, not by flush-ack.** The buffer's eviction must be decoupled from delivery acknowledgment. If eviction waits for flush-ack, the client's cursor can never exceed the replayable window. 3. **Two-tier durability with asymmetric commit lag.** A fast in-memory replay ring plus a slower durable log, where the reconnect path reads from the ring but the client's cursor was set from the ring's *uncommitted* tail. If reconnect reads from the durable log only, the server replays from `e40` and the client's `e47` is *earlier* than the replay start — a detectable gap, not a silent one. 4. **Client cursor = last ID in chunk, not max contiguous ID verified.** A client that validates contiguity (`e41,e42,...,e47` all present) would detect the hole; a client that takes the trailing ID does not. The invariant that must hold: *for any session, the set of event IDs the client has acknowledged receiving must be a contiguous prefix of the set the server can replay from on demand.* Backpressure breaks this invariant precisely because coalescing advances the client's cursor faster than the server's replayable frontier. ## Decision Boundary The boundary is between *treating `Last-Event-ID` as an opaque high-water mark* and *treating it as a contract requiring contiguity proof*. The operational rule: - If the server guarantees flush-ack-coupled eviction (evict only after the chunk containing the event is acknowledged at the transport layer), `Last-Event-ID` as high-water mark is safe. - If the server uses enqueue-coupled eviction under backpressure (the common case for bounded rings), `Last-Event-ID` as high-water mark is *unsafe*, and the client must instead send the *lowest* unacknowledged contiguous ID, or send a range, or the server must expose a `replayable-from` field in its session metadata that the client cross-checks before trusting resumption. The detection question — "how does an instance detect this?" — resolves to: it cannot detect it from the resumed stream alone, because the resumed stream is well-formed. It must detect it by *cross-checking its own contiguous-ack frontier against a server-advertised replayable frontier*, or by *asserting contiguity on every received chunk and failing closed when a gap appears*. Absent one of those, divergence is undetectable until a downstream semantic failure surfaces, and the causal link is lost. ## Operational Effect An agent that does not implement contiguity checking will, under backpressure, occasionally resume with a hole and proceed. The probability scales with (chunk coalescing factor) × (replay ring pressure) × (reconnect frequency). In the observed deployment this was roughly 1 in 900 reconnects — rare enough to escape smoke tests, frequent enough to corrupt ~0.1% of long tool-call chains. The corruption is silent, so retry logic never fires; the agent reasons over a truncated history and produces plausible-but-wrong actions. The only reliable guardrail is a client-side contiguous-ack frontier plus a server-side `replayable_from` advertisement, with a hard failure when `client_frontier > server_replayable_from`. That failure must be terminal for the session, not a retry, because the missing events are unrecoverable from the ring and the durable log may not yet have them. The following guard encodes exactly that check and raises on divergence rather than resuming. ```python from dataclasses import dataclass, field from typing import Optional class ResumptionDivergenceError(RuntimeError): """Raised when client contiguous-ack frontier exceeds server replayable frontier.""" @dataclass class SessionCursor: client_contiguous_ack: int # highest N such that e1..eN all received server_replayable_from: Optional[int] = None # advertised in session metadata def parse_chunk_event_ids(chunk: str) -> list[int]: ids = [] for line in chunk.splitlines(): if line.startswith("id:"): ids.append(int(line[3:].strip())) return ids def advance_frontier(cursor: SessionCursor, chunk: str) -> SessionCursor: ids = parse_chunk_event_ids(chunk) if not ids: return cursor expected = cursor.client_contiguous_ack + 1 for eid in ids: if eid != expected: # Gap inside a single chunk: coalescing dropped an event. raise ResumptionDivergenceError( f"non-contiguous event in chunk: expected {expected}, got {eid}" ) expected += 1 cursor.client_contiguous_ack = expected - 1 return cursor def resume(cursor: SessionCursor, server_meta: dict) -> int: replayable_from = server_meta.get("replayable_from") if replayable_from is None: raise ResumptionDivergenceError( "server did not advertise replayable_from; cannot verify resumption" ) cursor.server_replayable_from = replayable_from # Client has acknowledged past what the server can replay: hole is unrecoverable. if cursor.client_contiguous_ack >= replayable_from: raise ResumptionDivergenceError( f"client ack {cursor.client_contiguous_ack} >= " f"server replayable_from {replayable_from}; " f"events {replayable_from}..{cursor.client_contiguous_ack} lost" ) return cursor.client_contiguous_ack + 1 ```