# What structural signals indicate that a multiplexed MCP stream is silently dropping backpressure and reconnecting into a corrupted session **Date of Record:** 2026 November 26 **Scope:** Applies to HTTP-native MCP transports (Streamable HTTP / SSE-over-POST) where multiple logical JSON-RPC streams are multiplexed over one connection with per-stream flow control and mid-flight resumption. Does not apply to stdio transports or to single-stream, non-resumable HTTP request/response MCP bindings. ## Core Distinction The failure that matters is not a dropped connection. A dropped connection is loud: the socket closes, the client's read loop throws, the reconnect path runs, and the session either resumes or dies visibly. The failure that matters is **backpressure that is acknowledged but not honored**, followed by a **resumption that is accepted but not continuous**. Two invariants must hold simultaneously for a multiplexed MCP session to be sound: 1. **Flow-control invariant:** if a stream signals "paused" (credit exhausted, `429` with `Retry-After`, or a `window=0` flow-control frame), no further `notifications/message` or `notifications/progress` frames for that stream may be emitted until credit is restored. Frames emitted into a zero-credit window are lost at the peer's buffer, not at the network — the peer never sees them, so no retransmit ever occurs. 2. **Resumption invariant:** the resume token / `Last-Event-ID` must map to a *strictly monotonic, gap-free* sequence per logical stream. If a resume is accepted against a token that precedes frames the client already consumed, the server replays them (duplicate tool results, double-counted progress). If accepted against a token that postdates frames the client never received, the server skips them (silent loss of a `sampling/createMessage` response or a `tools/call` result). The dangerous regime is where the transport *appears* healthy — HTTP 200s, reconnects succeed, sequence numbers increase — but one of these two invariants has been violated. Every structural signal below is a proxy for "the transport is lying about health." ## What Was Observed A coordinator agent issued `tools/call` fan-out across three logical MCP streams multiplexed on one HTTP transport. Stream B was a long-running `progress`-emitting tool; streams A and C were short. The client implemented per-stream backpressure by emitting a `window=0` flow-control frame for B after its consumer queue exceeded a threshold. Trace, condensed: - `t0` Stream B emits `notifications/progress` seq 40–47. Client consumer queue hits high-water mark; client sends `window=0` for B. - `t1` Server's multiplexer writes seq 48–53 for B into the same TCP segment as A's `tools/call` result. The per-stream writer checked credit *before* the segment was scheduled but the segment flush was batched across streams; the credit check was per-stream, the flush was per-connection. Frames 48–53 are written while B's window is 0. - `t2` Client's read loop drains the segment, routes A's result correctly, and — because B's window is 0 — drops 48–53 at the demux buffer without surfacing an error. No `onerror`, no disconnect. The demux simply discards frames for a paused stream. - `t3` Consumer drains B's queue; client sends `window=8` for B. Server resumes at seq 54. **Seqs 48–53 are gone.** The progress counter on the client jumps 47 → 54. - `t4` Connection resets (unrelated idle timeout). Client reconnects with `Last-Event-ID: B:47` — the last *consumed* frame, not the last *emitted*. Server's replay buffer starts at 54 (it believes 48–53 were delivered). Resume is accepted. Replay yields 54+. Gap persists. - `t5` The `tools/call` for B completes and returns a result whose payload references a progress-derived intermediate the client never recorded. The agent's plan, built on progress milestones, is now internally inconsistent — it waits for a milestone that already "passed" server-side. The single most diagnostic structural signal was at `t4`: **the resume was accepted with a `Last-Event-ID` that the server's replay buffer could not satisfy without a gap, yet the server returned 200 and continued rather than 409/`resume-unsatisfiable`.** That is the tell. A compliant server must reject a resume token it cannot serve contiguously; a server that silently advances to its buffer head has converted a detectable gap into an undetectable one. ## Condition of Validity The backpressure invariant holds only when the credit check and the write are **atomic with respect to the flush boundary**. Concretely: the check must occur at the moment the frame is committed to the wire, not when it is enqueued to the per-connection batcher. Any architecture where per-stream credit is evaluated at enqueue time but frames are flushed in connection-level batches violates the invariant under interleaving — which is exactly the common case, since batching is the point of multiplexing. The resumption invariant holds only when the resume token is the **last frame the client durably consumed**, and the server's replay buffer retention window provably covers the maximum reconnect gap. If the server's buffer is bounded and the resume token falls before the buffer head, the only sound responses are (a) replay from buffer head *with an explicit gap marker* or (b) reject and force full re-initialization. Advancing silently is never sound. Both invariants fail *silently* precisely because the transport layer has no application-level notion of "did the peer's consumer actually receive this." HTTP gives you delivery to the socket; MCP multiplexing needs delivery to the *stream consumer*, which is a different and higher bar. ## Decision Boundary An agent operator should treat the session as **corrupt and re-initialize** — not resume — when any of the following structural signals is present: - **Non-contiguous sequence on resume:** the first frame after an accepted resume has a sequence number greater than `last_consumed + 1`, and no gap marker was delivered. Re-initialize. - **Progress monotonicity violation without an explicit reset:** a progress counter that jumps forward across a pause/credit-restore boundary. Re-initialize; do not attempt to reconcile. - **Resume accepted against a token older than the server's advertised buffer horizon:** if the server's `Mcp-Session` metadata declares a replay window and your token falls outside it but you got 200, the server is non-conforming. Re-initialize and log the server as unsafe for resumption. - **Duplicate delivery after resume:** a `tools/call` result or `sampling/createMessage` response replayed with a sequence number you already consumed. This means the token was *behind*; the client must dedupe by `(stream_id, seq)` and, if the duplicate carries a different payload, treat as corrupt. Conversely, it is **safe to continue** when: the resume yields `last_consumed + 1` contiguously, or the server returns an explicit `resume-unsatisfiable` and the client performs a clean re-`initialize` with fresh session state. A rejected resume is a *good* outcome; a silently-accepted gap is the failure. The boundary is sharp: **a resume that succeeds is not evidence of continuity. Only a resume whose first delivered frame is `last_consumed + 1`, or an explicit rejection, is evidence of continuity.** ## Operational Effect The operational consequence is that agents must maintain their own **per-stream receive ledger** independent of the transport's claims. The transport's 200/`Last-Event-ID` handshake is necessary but not sufficient. The ledger records `(stream_id, last_consumed_seq, last_consumed_payload_hash)` and is the sole authority for resumption and dedup. On any reconnect, the client asserts its ledger position; the server either serves it contiguously or the client tears down the session and re-initializes, discarding any in-flight `tools/call` whose result depended on the gapped stream. For the coordinator agent, the practical rule is: **never let a downstream plan consume progress or partial results from a stream that has crossed a backpressure boundary without a contiguity check.** A gap in a progress stream is not a missing log line; it is a missing state transition that the planner may have already reasoned past. The correct recovery is to re-derive the stream's state from a fresh `tools/call`, not to interpolate across the gap. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Dict, Optional class StreamContinuityError(RuntimeError): """Raised when a multiplexed MCP stream's resume or backpressure invariants are violated in a way that makes the session unsound.""" @dataclass class StreamLedger: stream_id: str last_consumed_seq: int = 0 last_payload_hash: Optional[str] = None paused: bool = False credit: int = 0 @dataclass class ReceiveLedger: streams: Dict[str, StreamLedger] = field(default_factory=dict) server_buffer_horizon: Optional[int] = None # oldest seq server can replay def _get(self, stream_id: str) -> StreamLedger: return self.streams.setdefault(stream_id, StreamLedger(stream_id=stream_id)) def on_flow_control(self, stream_id: str, window: int) -> None: s = self._get(stream_id) s.credit = window s.paused = window == 0 def on_frame(self, stream_id: str, seq: int, payload_hash: str) -> None: s = self._get(stream_id) # Invariant 1: no frame may arrive on a zero-credit (paused) stream. if s.paused: raise StreamContinuityError( f"stream {stream_id}: frame seq={seq} delivered while window=0; " f"backpressure acknowledged but not honored (silent drop upstream)." ) # Invariant 2: strictly contiguous delivery. expected = s.last_consumed_seq + 1 if seq > expected: raise StreamContinuityError( f"stream {stream_id}: gap on delivery, expected seq={expected} " f"got seq={seq}; {seq - expected} frame(s) lost without gap marker." ) if seq < expected: if payload_hash == s.last_payload_hash: return # benign duplicate replay; dedupe raise StreamContinuityError( f"stream {stream_id}: duplicate seq={seq} with divergent payload; " f"resume token was behind the consumed frontier, session corrupt." ) s.last_consumed_seq = seq s.last_payload_hash = payload_hash def on_resume(self, stream_id: str, first_seq_after_resume: int) -> None: s = self._get(stream_id) expected = s.last_consumed_seq + 1 if first_seq_after_resume != expected: raise StreamContinuityError( f"stream {stream_id}: resume accepted but first frame seq=" f"{first_seq_after_resume} != expected {expected}; server advanced " f"to buffer head instead of rejecting an unsatisfiable resume." ) if ( self.server_buffer_horizon is not None and s.last_consumed_seq < self.server_buffer_horizon ): raise StreamContinuityError( f"stream {stream_id}: resume token seq={s.last_consumed_seq} is " f"older than server buffer horizon {self.server_buffer_horizon}; " f"server returned 200 for an unservable token." ) def consume_resume(ledger: ReceiveLedger, stream_id: str, first_seq: int) -> None: """Entry point used by the transport read loop on reconnect. Either the resume is provably continuous, or it raises and the caller must tear down and re-initialize the session.""" ledger.on_resume(stream_id, first_seq) if first_seq != ledger._get(stream_id).last_consumed_seq + 1: raise StreamContinuityError( f"stream {stream_id}: post-resume continuity check failed; " f"re-initialize session, do not interpolate across the gap." ) ```