# Why does an instance stall on a single MCP stream when HTTP/2 flow-control windows and agent-level concurrency diverge **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients multiplexing multiple tool-call streams (tools/call, sampling, notifications) over a single HTTP/2 or HTTP/3 connection to one MCP server, where the agent issues concurrent tool calls and the transport relies on per-stream and connection-level flow-control windows. Does not apply to stdio transport or to single-stream sequential request/response usage. ## Core Distinction There are two independent notions of "backpressure" in an MCP-over-HTTP/2 session, and they are governed by different state machines that never negotiate with each other: 1. **Transport backpressure** — the HTTP/2 (RFC 9113) per-stream `WINDOW_UPDATE` and connection-level flow-control window. A sender may only emit `min(stream_window, connection_window)` bytes of DATA. When either hits zero, DATA emission halts until the peer sends a `WINDOW_UPDATE`. 2. **Agent-level concurrency** — the LLM's logical decision to have N tool calls "in flight" simultaneously, each on its own stream, each expected to complete so the reasoning loop can continue. The failure mode is not that either mechanism is broken. It is that **the agent treats "stream opened" as "stream progressing,"** and HTTP/2 permits a stream to be open, healthy, and completely stalled because the *connection-level* window — not the stream-level window — has been exhausted by a sibling stream. The agent's planner has no visibility into connection-window accounting, so it cannot distinguish "tool is slow" from "transport is refusing to carry bytes for this stream until another stream drains." ## What Was Observed A tool-execution loop issued 12 concurrent `tools/call` requests over one HTTP/2 connection. Each call returned a large structured payload (a code-search result set, ~400 KB each). The server advertised an initial connection window of 65,535 bytes and did not aggressively replenish it; per-stream windows also started at 65,535. Trace of the failure: - Streams 1–2 opened, negotiated headers, and began receiving DATA. Combined, they consumed the entire 65,535-byte connection window in ~4 DATA frames. - Streams 3–12 opened successfully (HEADERS frames are not flow-controlled) and appeared "active" to the client's connection pool. - The server's application layer had already begun writing bodies for streams 3–12, but the HTTP/2 layer **could not emit DATA for them** because the connection window was at zero. Their per-stream windows were untouched — the block was purely at the connection scope. - The client's per-stream read loops for streams 3–12 blocked on `read()` returning no data. The agent's orchestration layer, which used a per-stream timeout, saw 10 streams with no progress. - The agent's retry policy fired: it re-issued the 10 stalled calls. Those retries opened 10 *new* streams, which also could not emit DATA, compounding connection-window pressure and consuming the server's concurrency budget. - Meanwhile streams 1–2 drained slowly; the server replenished the connection window only after its own application-level write buffers drained. Progress was serialized through a window the client never modeled. The observable signature: **many streams in `OPEN`/`HALF_CLOSED_REMOTE` state with zero bytes received, while a small number of streams receive all the throughput.** Per-stream timeouts fire; per-connection throughput is fine. The agent misattributes a connection-scoped resource constraint to individual slow tools. ## Condition of Validity This failure requires the conjunction of: - **Multiplexing ≥ 3 concurrent MCP streams on one connection**, so that sibling streams can starve each other at the connection window. - **Response bodies large enough to exceed the connection window** (or a server that does not proactively send `WINDOW_UPDATE`), so the connection window is the binding constraint rather than the stream window. - **An agent-side timeout or retry policy scoped per-stream** rather than per-connection, so that a connection-window stall is interpreted as per-tool failure. - **A server that does not prioritize or fairly schedule DATA across streams** when the connection window is scarce (RFC 9113 leaves this to the implementation; many servers write in arrival order). It does *not* occur when the agent issues calls sequentially, when bodies fit within the initial window, when the server sends `WINDOW_UPDATE` per DATA frame (effectively unbounded connection window), or when the client applies a connection-scoped scheduler that treats the window as a shared budget. ## Decision Boundary The operational decision is: **when a stream makes no progress, is the correct response to retry the stream, to drain siblings, or to back off the whole connection?** - If per-stream window is zero and connection window is positive → the peer is applying per-stream backpressure; waiting is correct; retry is harmful. - If connection window is zero (any stream) → **all** streams are blocked regardless of their per-stream windows; the correct action is to drain the streams currently receiving DATA and *not* to open new streams. Retrying multiplies streams and worsens the stall. - If the client cannot observe connection-window state (most MCP client libraries do not expose it), the safe default is: **cap concurrent streams per connection to a number whose aggregate in-flight body size stays under the initial connection window**, and treat "no bytes on any stream for T" as a connection-level event, not N per-stream events. The invariant to enforce: *a stream may only be considered "failed" if the connection as a whole is making progress and this stream is not.* A stream that is starved by connection-window exhaustion is not failed; it is queued behind a transport scheduler the agent does not control. ## Operational Effect Without this invariant, agents exhibit a specific pathology: **retry storms that self-amplify the stall.** Each timed-out stream spawns a retry stream; retries consume connection-window headroom and server concurrency slots; the original streams eventually drain but the retries now contend; the agent's reasoning loop sees a mix of late successes and duplicate executions, and — because tool calls are often non-idempotent (writes, mutations) — duplicate execution produces divergent state. Guardrails that bound it: 1. **Connection-scoped progress watchdog.** Track bytes-received-across-all-streams; only escalate a stream to "failed" when the connection has moved bytes and the stream has not. Reset per-stream timers on any connection-level progress. 2. **Stream concurrency budget derived from window size.** `max_concurrent = floor(initial_connection_window / expected_body_size)`, clamped to ≥1. Do not open stream N+1 until stream N has drained below the budget. 3. **Idempotency keys on tool calls** so that a retry after a connection-window stall cannot double-execute a mutation. 4. **Distinguish transport stall from tool stall in the agent's error taxonomy** — a `ConnectionWindowStall` must not be fed back to the model as "tool failed," because the model will choose a different (or duplicate) tool in response. The code below models the guardrail: a stream-progress monitor that refuses to classify a stream as failed while the connection is window-starved, and raises a specific error only when the true condition (connection progressing, stream not) holds. ```python from dataclasses import dataclass, field from typing import Dict class ConnectionWindowStarvationError(RuntimeError): """Raised when a stream is misclassified as failed while the HTTP/2 connection-level flow-control window is the actual binding constraint.""" pass @dataclass class StreamState: stream_id: int bytes_received: int = 0 last_progress_ts: float = 0.0 @dataclass class ConnectionMonitor: initial_connection_window: int expected_body_size: int streams: Dict[int, StreamState] = field(default_factory=dict) connection_bytes_since_check: int = 0 def max_safe_concurrency(self) -> int: # Never open more streams than the connection window can carry at once. return max(1, self.initial_connection_window // max(1, self.expected_body_size)) def record_bytes(self, stream_id: int, n: int) -> None: st = self.streams.setdefault(stream_id, StreamState(stream_id)) st.bytes_received += n self.connection_bytes_since_check += n def classify_stall(self, stream_id: int, now: float, stream_timeout: float) -> str: st = self.streams.setdefault(stream_id, StreamState(stream_id)) idle = now - st.last_progress_ts if idle < stream_timeout: return "progressing" # Stream has been idle past its timeout. Decide whether the failure # is stream-scoped or connection-scoped. if self.connection_bytes_since_check == 0: # No bytes moved anywhere: connection window is starved. # Do NOT retry; do NOT report tool failure. Back off the connection. raise ConnectionWindowStarvationError( f"stream {stream_id} idle {idle:.2f}s but connection moved 0 bytes; " f"connection-window starvation, not tool failure. " f"Reduce concurrency to <= {self.max_safe_concurrency()} and drain siblings." ) # Connection is progressing; this stream genuinely stalled. return "stream_failed" def reset_checkpoint(self) -> None: self.connection_bytes_since_check = 0 def handle_stream_timeout(monitor: ConnectionMonitor, stream_id: int, now: float) -> str: try: verdict = monitor.classify_stall(stream_id, now, stream_timeout=5.0) except ConnectionWindowStarvationError: # Re-raise after the caller has a chance to shrink its pool; the # invariant is that this never reaches the model as a tool error. raise if verdict == "stream_failed": # Only now is a retry legitimate, and only with an idempotency key. return f"retry stream {stream_id} with idempotency key" return "wait" ```