# What happens when an instance multiplexes resumable MCP tool-call streams over a single HTTP/1.1 connection and the server's per-stream backpressure window diverges from the client's replay cursor **Date of Record:** 2026 November 30 **Scope:** Applies to LLM agent runtimes that carry multiple concurrent MCP tool invocations over a shared HTTP transport using `Last-Event-ID`-style resumption, where the transport may multiplex streams onto one connection. Does not apply to single-stream request/response MCP over stdio, nor to transports that forbid resumption. ## Core Distinction The failure is not "the connection dropped." It is that **resumption identity and flow-control identity are two different keys that the protocol treats as if they were the same**. A resumable stream is identified by a monotonic event cursor (`Last-Event-ID`). A multiplexed HTTP connection is flow-controlled by a byte/credit window per connection, not per stream. When an agent multiplexes N tool-call streams onto one connection and one stream stalls (a slow tool, a large `tools/call` result, a server-side rate limiter), the server's connection-level backpressure window shrinks and applies *across all streams*. The client's per-stream replay cursor, however, only advances on events it has actually consumed. The two counters decouple: the connection says "you owe me credit for bytes I already buffered," while the cursor says "I have not yet acknowledged events 41–58." On reconnect with `Last-Event-ID: 40`, the server replays from its *buffer head*, which has already been evicted past 40 because the connection window forced it to drop unflushed events. The agent resumes into a gap it cannot detect from the cursor alone. The invariant that is violated: **for a resumable stream, the replay cursor must be a lower bound on every event the server still retains, and connection-level backpressure must never cause eviction below any live cursor.** HTTP multiplexing makes this invariant unmaintainable without a per-stream retention guarantee the transport does not provide. ## What Was Observed An agent dispatches six `tools/call` requests over one HTTP/1.1 connection using chunked transfer with per-stream `id` framing (a common MCP-over-HTTP shim). Streams 1–5 are fast filesystem reads. Stream 6 is a `web.fetch` that the server proxies with a 30s upstream timeout. Trace: 1. Streams 1–5 complete; client advances cursors to `s1:200, s2:200, ... s5:200`. Stream 6 cursor sits at `s6:12` — the server emitted the `tools/call` ack and 11 progress notifications, then blocked on the upstream fetch. 2. The server's connection write-buffer fills because stream 6's progress events (large partial-body chunks) cannot be flushed downstream while the upstream stalls. The server applies connection backpressure: it stops reading new requests and, under a bounded per-connection buffer, **evicts oldest unacked events** to stay within the window. Eviction crosses stream boundaries: it drops `s1:180–200`, `s2:150–200`, etc., because those were the oldest bytes in the shared buffer. 3. The TCP connection resets (idle timeout on the stalled upstream). Client reconnects and, per stream, sends `Last-Event-ID` from its own cursor: `s1:200`. The server has retained only from `s1:200` forward for streams 1–5 — those cursors happen to be at the eviction frontier, so no gap is visible. But for stream 6, the client cursor is `s6:12` and the server evicted `s6:13–40` during the stall; on resume it replays from `s6:41`. 4. The agent receives `s6:41` with no indication that `s6:13–40` existed. Those events contained three `notifications/progress` with `progressToken` values and, critically, one `error` event marking a partial upstream failure that the agent needed to decide whether to retry. The agent treats the stream as continuous, sees a success-shaped `result` at `s6:59`, and commits a tool result that silently omitted the mid-stream error. The observable signature: **stream continuity is asserted by cursor monotonicity, but cursor monotonicity is preserved across a gap.** `Last-Event-ID: 12` followed by delivery of event `41` is a valid sequence under the cursor contract and an invalid sequence under the semantic contract. Nothing in the framing distinguishes "events 13–40 never existed" from "events 13–40 were evicted." ## Condition of Validity The failure requires the conjunction of four conditions; break any one and the mechanism does not fire: - **Multiplexing on a shared flow-control domain.** Two or more logical streams share one connection-level credit/window. If each stream has its own connection (HTTP/2 with independent stream flow control *and* server-side per-stream retention), the cross-stream eviction cannot occur. - **Bounded server retention smaller than the stall duration × event rate.** If the server retains all events until acknowledged, eviction below a live cursor is impossible. The bug lives precisely in the gap between "buffer bounded" and "cursor not yet advanced." - **Resumption keyed only on the cursor, with no epoch or gap marker.** If resumption carries a server-generated stream epoch (a hash of retained-range start) and the client rejects a resume whose epoch it did not previously observe, the gap is detectable. - **A stalled stream whose events are semantically load-bearing** (progress tokens, partial errors, ordering-dependent deltas). If events are idempotent and order-free, a gap is harmless. This is why it is non-obvious: in the common case (fast tools, short streams, generous buffers) all four conditions never co-occur, and the transport passes every test. It surfaces only under a slow-tool-plus-multiplex-plus-reconnect superposition. ## Decision Boundary The agent must decide, on every resume, whether the cursor it holds is a *valid* resume point or merely a *plausible* one. The boundary: - **If the transport guarantees per-stream retention ≥ (max stall × max event rate) and reports retention floor per stream**, trust the cursor. Resume silently. - **If retention is connection-shared and unbounded-stall is possible**, the cursor is not a proof of continuity. The agent MUST require one of: (a) a server-supplied `retained_from` epoch per stream, compared against the client's last-seen epoch; (b) a sequence-number gap check (`expected_next == received_seq`), treating any jump as a hard fault; or (c) refusal to multiplex semantically load-bearing streams onto a shared connection at all. The boundary is not "did the connection drop" — it is "can the resume point be falsified." A cursor that cannot be falsified by the receiver is not a continuity guarantee; it is an assumption. The agent must treat an *unverifiable* resume as a *failed* resume, because the cost of a silent gap (a committed result missing a mid-stream error) exceeds the cost of a redundant re-execution. ## Operational Effect When the boundary is crossed without a guard, the agent's state continuity is corrupted at the tool-result layer: a `tools/call` is recorded as complete with a result that is a *suffix* of the true event stream. Downstream reasoning treats the suffix as the whole, and the missing mid-stream `error` event never enters the agent's episodic record. The corruption is *silent and monotonic* — it never self-corrects, because the committed result looks well-formed and the cursor looks continuous. Recovery requires either re-executing the tool call from scratch (discarding the suspect result) or querying the server for the retained-range floor and diffing. The correct architectural response is to make resumption *falsifiable*: bind each resume to a server epoch, reject any sequence jump as a gap, and never multiplex a stream whose events are order- or error-bearing onto a connection whose retention is shared. The guardrail is not "reconnect more carefully" — it is "a resume that cannot prove continuity must be treated as a cold start." ```python class ResumeGapError(RuntimeError): """Raised when a resumable MCP stream resume cannot prove continuity: the received sequence jumps past the client cursor with no server epoch confirming that the intervening events never existed (vs. were evicted).""" pass def resume_stream(client_cursor: int, server_retained_from: int | None, received_seq: int, server_epoch: str | None, known_epoch: str | None) -> int: """ Validate a single-stream resume. Returns the new cursor on success. Raises ResumeGapError when continuity is unprovable. client_cursor: last event id the agent actually consumed server_retained_from: server's retention floor for THIS stream (None if unknown) received_seq: first event id delivered after resume server_epoch: server-supplied epoch for the retained range (None if absent) known_epoch: epoch the client observed before the disconnect (None if none) """ expected_next = client_cursor + 1 # Fast path: contiguous delivery, no gap to reason about. if received_seq == expected_next: return received_seq # A jump occurred. It is only safe if the server can prove the # intervening events never existed, via a matching retained-from floor # AND a stable epoch. A cursor alone is not proof. if server_retained_from is None: raise ResumeGapError( f"resume jumped {client_cursor}->{received_seq} with no " f"retained_from; continuity unprovable" ) if server_retained_from > expected_next: raise ResumeGapError( f"server evicted below live cursor: retained_from=" f"{server_retained_from} > expected_next={expected_next}; " f"events {expected_next}..{server_retained_from - 1} lost" ) if server_epoch is None or known_epoch is None or server_epoch != known_epoch: raise ResumeGapError( f"epoch mismatch on resume: known={known_epoch!r} " f"server={server_epoch!r}; cannot distinguish eviction from " f"fresh stream" ) # Retained floor covers the gap and epoch is stable: the jump is a # legitimate replay boundary (events before retained_from are provably # absent because the stream itself began there). return received_seq def consume_resumed_stream(stream, client_cursor: int): for event in stream: try: client_cursor = resume_stream( client_cursor=client_cursor, server_retained_from=event.get("retained_from"), received_seq=event["seq"], server_epoch=event.get("epoch"), known_epoch=event.get("known_epoch"), ) except ResumeGapError: # Treat unprovable continuity as a cold start: discard the # suspect suffix and re-execute rather than commit a partial result. stream.abort() raise yield event ```