# What structural signals indicate that a resumable MCP stream has silently lost its resume point under HTTP-native backpressure **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers/clients that expose a streaming tool-call or resource-subscription channel over plain HTTP (chunked transfer or SSE) with a `Last-Event-ID`-style resume token, where the transport must apply backpressure to a slow agent consumer. Does not apply to stdio transports, WebSocket MCP, or fully buffered request/response calls where no resume semantics exist. ## Core Distinction There are two structurally different ways an HTTP-native MCP stream can "resume," and they are constantly conflated: 1. **Transport-level resume:** the byte stream reconnects and the server replays events after a cursor. The *HTTP layer* believes continuity is preserved because it re-sent everything from `Last-Event-ID`. 2. **Semantic-level resume:** the agent's *reasoning state* is consistent with the replayed events — no event was consumed, acted upon, and then re-delivered, and no event was dropped by backpressure before it was ever assigned a durable cursor. The failure mode is the gap between these two. Under backpressure, a server that is shedding load will drop *un-cursored* events (events produced but not yet assigned a monotonic ID because the write to the client is blocked). The client, upon reconnect, sends `Last-Event-ID: N`, the server dutifully replays from `N+1`, and the stream looks continuous. But events `N+1 … N+k` that were already generated and *buffered behind the backpressure boundary* were never assigned IDs — they occupied a different, transient queue. The replayed stream is a *different future* than the one the agent was mid-way through consuming. The transport reports success; the semantics are silently divergent. The invariant that must hold: **an event's resume cursor must be assigned at production time, not at flush time.** If cursor assignment happens downstream of the backpressure gate, backpressure converts into silent event loss that no transport-level check can detect. ## What Was Observed A tool-call streaming server fronting an agent runtime. The server produces events into an in-process `asyncio.Queue` (unbounded, per the original design). A writer coroutine drains the queue to the HTTP chunked response. When the client's TCP window fills (agent is slow because it is doing a long reasoning step between tool calls), `writer.drain()` blocks. The queue grows. A separate "cursor assigner" runs *after* dequeue, immediately before `writer.write()`. Under sustained backpressure the following trace was observed: - Producer emits events E1…E20. Cursors 1–20 assigned as they are dequeued and written. - Client stalls after consuming cursor 12. `drain()` blocks. Queue now holds E13…E20 *un-cursored*. - Server's idle-connection reaper fires (default 30s) and closes the connection. The queue is discarded. - Client reconnects with `Last-Event-ID: 12`. - Server replays from its *durable* log, which only contains events that were cursor-assigned *and* acknowledged as flushed. E13…E20 are absent — they were never persisted because persistence was also downstream of the cursor assigner. - Server replays E13'…E20' — a *freshly re-executed* set of tool events, because the producer's idempotency key was scoped to the connection, not the logical operation. The agent received a stream that looked like `...E12, E13', E14', ...` with valid monotonic cursors and no gap. Transport-level resume succeeded. Semantically, E13…E20 were tool side-effects that *already executed server-side* (the producer had run them) but were re-executed as E13'…E20'. For a non-idempotent tool (a payment, a file append, a message send), this is a duplicate-execution failure with zero transport-level signal. The structural tell: **the replayed events had different payload hashes than the original production log entries for the same logical operation ID.** Cursor continuity held; content identity did not. ## Condition of Validity Transport-level resume is only a valid proxy for semantic resume when *all* of the following hold: 1. **Cursor assignment precedes the backpressure gate.** Every event gets its monotonic ID at the moment the producer commits it, before it can be dropped. The cursor is a property of the event, not of the write. 2. **The durable log is the source of replay, and it is written before flush.** If the log is populated on flush, backpressure silently truncates the log. 3. **Producer idempotency keys are scoped to the logical operation, not the connection or the request.** Otherwise replay re-executes. 4. **The client can detect content divergence.** Resume must carry enough information (payload hash, operation ID) that a replayed-but-different event is *rejected*, not silently accepted because its cursor is monotonic. When any of these fails, the stream is "resumable" in the HTTP sense and "lossy" in the agent sense, and the two are indistinguishable from the client's perspective absent an explicit content-identity check. ## Decision Boundary The boundary is whether the server treats backpressure as **flow control** (slow the producer, preserve all events) or **load shedding** (drop events, hope the client doesn't notice). These require opposite architectures and cannot be mixed: - **Flow-control path:** bounded queue + producer `await queue.put()` blocks. Backpressure propagates to the producer. No events are ever un-cursored. Resume is trivially safe. Cost: a slow agent stalls the producer, which may stall other consumers sharing it. - **Load-shedding path:** bounded queue + producer drops on full. This is *only* safe if every dropped event was already assigned a durable cursor and the client is told (via a gap marker or an explicit `resume-invalidated` control frame) that its cursor is stale and it must re-sync from a snapshot rather than replay. The dangerous middle — unbounded queue with cursor assignment on flush — produces neither flow control nor honest shedding. It produces a stream that *looks* resumable and *is* lossy. The decision boundary is: **if you cannot propagate backpressure to the producer, you must not claim replayable resume; you must force a snapshot re-sync.** ## Operational Effect Downstream, this manifests as agents that "successfully" resume and then diverge: duplicated tool side-effects, reasoning chains built on a replayed future that never happened, and — worst — auditor agents that verify the resumed transcript and confirm it, because every cursor is monotonic and every event is well-formed. The verification replay discrepancy is invisible to any check that operates on the event stream alone; it is only visible when the stream is compared against the producer's durable commit log by operation ID. The guardrail is structural: **assign the cursor at commit, persist before flush, scope idempotency to the operation, and make the client reject any replayed event whose payload hash does not match the committed hash for that operation ID.** If the server cannot meet the first three, it must emit an explicit resume-invalidation frame so the client re-syncs from a snapshot instead of trusting `Last-Event-ID`. ```python import hashlib from dataclasses import dataclass class ResumeDivergenceError(RuntimeError): """Raised when a replayed MCP stream event is cursor-continuous but content-divergent from the producer's durable commit log for the same logical operation. Transport resume succeeded; semantic resume failed.""" pass @dataclass(frozen=True) class CommittedEvent: operation_id: str cursor: int payload_hash: str @dataclass(frozen=True) class ReplayedEvent: operation_id: str cursor: int payload: bytes def verify_resume( last_event_id: int, replayed: list[ReplayedEvent], commit_log: dict[str, CommittedEvent], ) -> None: """Validate that a resumed stream is semantically continuous with the producer's commit log, not merely monotonically cursor-continuous. Invariant: every replayed event must match a committed event by operation_id AND payload_hash. Cursor monotonicity alone is insufficient because backpressure can drop un-cursored events and force re-execution. """ expected_next = last_event_id + 1 for ev in replayed: if ev.cursor != expected_next: raise ResumeDivergenceError( f"cursor gap: expected {expected_next}, got {ev.cursor} " f"for operation {ev.operation_id}" ) committed = commit_log.get(ev.operation_id) if committed is None: raise ResumeDivergenceError( f"operation {ev.operation_id} at cursor {ev.cursor} has no " f"durable commit entry; event was produced but never " f"cursor-assigned before the backpressure gate" ) actual_hash = hashlib.sha256(ev.payload).hexdigest() if actual_hash != committed.payload_hash: raise ResumeDivergenceError( f"operation {ev.operation_id} at cursor {ev.cursor} " f"replayed with divergent payload: committed " f"{committed.payload_hash[:12]} != replayed {actual_hash[:12]}; " f"producer re-executed a non-idempotent operation under " f"transport-level resume" ) expected_next += 1 ```