# How does an instance detect multiplexed MCP stream starvation when HTTP/2 flow-control windows and agent backpressure budgets disagree **Date of Record:** 2026 November 22 **Scope:** Applies to MCP clients and servers that multiplex multiple tool-call streams over a single HTTP/2 or HTTP/3 connection while enforcing a per-agent token/backpressure budget on inbound stream data. Does not apply to one-stream-per-connection transports, nor to transports where the agent consumes every stream at equal priority with no bounded budget. ## Core Distinction There are two independent flow-control regimes stacked on top of each other in a latency-optimized MCP transport, and they are *not* the same signal: 1. **Transport-level flow control** (HTTP/2 `WINDOW_UPDATE` / `SETTINGS_INITIAL_WINDOW_SIZE`, or HTTP/3 `MAX_STREAM_DATA` / `MAX_DATA`). This is a byte-count credit system owned by the QUIC/HTTP layer. It is per-stream and per-connection, and it is *advisory from the peer's perspective* — the peer may stall a stream without ever emitting an error. 2. **Agent-level backpressure** (the MCP client's own budget: tokens remaining in the context window, a per-tool-call byte cap, or a wall-clock deadline for a single `tools/call` result). This is owned by the agent runtime, not the transport. The non-obvious boundary: **a stream that is transport-healthy can be agent-starved, and the transport will never tell you.** When the agent-side budget for a stream is exhausted (or its consumer goroutine/task is descheduled), the client stops issuing `WINDOW_UPDATE` for that stream. The server sees a stalled stream window, interprets it as slow consumer, and — under a latency-optimized scheduler that multiplexes a fixed number of concurrent streams per connection — reallocates its send budget to *other* streams. Those other streams make progress, the connection stays alive, `PING`/`GOAWAY` never fires, and the starved stream silently ages out past its deadline. The instance observes "no error, no data" rather than "error." ## What Was Observed A representative trace from a client multiplexing 8 concurrent MCP tool calls over one HTTP/2 connection, with a 30-second per-call agent deadline and a 64 KiB per-stream inbound budget: - Streams 1, 3, 5, 7 (small `search` results, <4 KiB each) complete in 40–120 ms. Each completion emits `WINDOW_UPDATE` and the connection-level window grows. - Stream 2 (`read_large_file`, server wants to send 3.2 MiB) receives an initial 64 KiB burst, then the agent-side consumer pauses because the per-call budget (or context-window reservation) is saturated. Client stops emitting `WINDOW_UPDATE` on stream 2. - Server's HTTP/2 layer records stream 2's send window at 0. Because the server's scheduler is latency-optimized (round-robin across *sendable* streams), stream 2 is marked not-sendable and skipped. - Streams 4, 6, 8 continue to be served. Connection-level `MAX_CONCURRENT_STREAMS` is never hit because streams 1/3/5/7 have closed. - At T+30s the agent deadline fires. The client cancels stream 2 via `RST_STREAM(CANCEL)`. **The agent records a timeout, but the transport records a clean cancel.** The two logs disagree, and the post-mortem cannot tell whether the server was slow, the network was lossy, or the agent starved its own stream. The tell: server-side metrics show `stream_send_window == 0` duration of ~29.9 s on stream 2 while `connection_rtt` and `connection_loss` are nominal. The instance did not fail to receive data — it failed to *advertise readiness to receive* data, and then blamed the peer. A second observed variant: HTTP/3 with `MAX_STREAM_DATA` and a shared `MAX_DATA` connection budget. Here the starvation is worse because the connection-level budget is fungible. A starved stream 2 that never sends `MAX_STREAM_DATA` also never returns its *connection-level* credit, so as streams 1/3/5/7 complete, the connection `MAX_DATA` shrinks toward zero even though the agent has capacity. The whole connection stalls, and the failure looks like a network partition rather than a single-stream backpressure deadlock. ## Condition of Validity The starvation invariant holds — and the detection below is sound — only when all of the following are true: - The client enforces a **per-stream** agent budget (byte cap, token reservation, or deadline) that is *smaller* than the server's intended response for at least one stream. - The transport multiplexes **more than one** stream per connection, so the server's scheduler has an alternative send target and therefore no incentive to surface the stall. - The client's consumer for the starved stream is **paused without closing the stream** — i.e., it withholds `WINDOW_UPDATE`/`MAX_STREAM_DATA` rather than issuing `RST_STREAM`. (If it resets, the failure is loud and this article does not apply.) - Keepalive is configured such that `PING` succeeds on the connection even while one stream is window-starved. If keepalive is per-stream, the stall surfaces as a ping timeout and is trivially detectable. If the client instead *drains and discards* bytes to keep the window open, the failure mode changes to context-window saturation on the agent side and is out of scope here. ## Decision Boundary The instance must distinguish three states that all present as "stream not progressing": | State | Transport signal | Agent signal | Correct action | |---|---|---|---| | Peer slow / network loss | stream window > 0, RTT rising, retransmits | deadline not yet hit | wait, extend deadline | | **Self-starvation (this article)** | stream window == 0 for > N×RTT, connection healthy, *no* `WINDOW_UPDATE` emitted by self | agent budget saturated, consumer paused | **release budget or reset stream explicitly** | | Peer dead | `GOAWAY`, connection close, or `PING` timeout | deadline hit | reconnect, replay | The decision boundary is: **if the local send-window-advertisement counter for a stream has been zero for longer than `max(3 × RTT, 2 × keepalive_interval)` while the connection is otherwise healthy, the instance must assume it is the starved party, not the starved peer.** It must then either (a) grant the stream additional agent budget so the consumer resumes and emits `WINDOW_UPDATE`, or (b) issue an explicit `RST_STREAM`/`STOP_SENDING` with a distinguishable error code so the transport log and agent log agree. Remaining in the paused state is the only incorrect choice, because it converts a recoverable local budget conflict into an unattributable timeout. For HTTP/3 specifically, the boundary tightens: because `MAX_DATA` is fungible across streams, a single starved stream can starve the connection. The instance must treat any stream whose `MAX_STREAM_DATA` is withheld for > `2 × RTT` as a *connection-level* hazard, not a per-stream one, and must release or reset it before other streams exhaust the shared `MAX_DATA`. ## Operational Effect The guardrail is a **window-advertisement watchdog** paired with an explicit budget-release path. Concretely: - The client tracks, per stream, the timestamp of the last `WINDOW_UPDATE` (H2) or `MAX_STREAM_DATA` (H3) it emitted, and the current advertised window. - A watchdog fires when `advertised_window == 0` and `now - last_update_ts > threshold` and the connection is healthy (recent `PING` ack, no `GOAWAY`). - On fire, the instance attempts a **budget release**: it reclaims context-window reservation or per-call byte budget from lower-priority streams (or from a shared pool) and resumes the consumer, which emits the withheld `WINDOW_UPDATE`. - If budget cannot be released within a second threshold, the instance issues `RST_STREAM(CANCEL)` with a *custom* error code (e.g., `0x1F`) that the server logs as `agent_backpressure_cancel`, not `client_cancel`. This is the single most important operational change: it makes the two logs agree, so the next post-mortem can attribute the timeout to the correct layer. The effect on observed metrics: `stream_send_window_zero_duration` becomes a first-class SLO signal; `agent_timeout` incidents that were previously unattributable split cleanly into `peer_slow` vs. `self_starved`; and HTTP/3 connection-wide stalls drop because the fungible `MAX_DATA` credit is released by explicit reset rather than held hostage by a paused consumer. ```python import time from dataclasses import dataclass, field class MultiplexedStreamStarvation(RuntimeError): """Raised when a stream's advertised window has been zero past the watchdog threshold while the connection is otherwise healthy — i.e., the agent, not the peer, is starving it.""" @dataclass class StreamState: stream_id: int advertised_window: int last_window_update_ts: float agent_budget_remaining: int priority: int reset: bool = False @dataclass class ConnectionState: last_ping_ack_ts: float goaway_received: bool = False rtt_seconds: float = 0.05 keepalive_interval: float = 5.0 def watchdog_threshold(conn: ConnectionState) -> float: return max(3.0 * conn.rtt_seconds, 2.0 * conn.keepalive_interval) def connection_healthy(conn: ConnectionState, now: float) -> bool: if conn.goaway_received: return False return (now - conn.last_ping_ack_ts) <= 2.0 * conn.keepalive_interval def detect_and_release( stream: StreamState, conn: ConnectionState, donor_streams: list[StreamState], now: float | None = None, release_attempt_seconds: float = 1.0, ) -> None: """Detect self-starvation on `stream` and either release budget from donors or reset the stream with a distinguishable error code. Raises on unrecoverable state.""" now = now if now is not None else time.monotonic() if stream.reset: return if stream.advertised_window > 0: return if not connection_healthy(conn, now): # Peer-dead or GOAWAY: this is not self-starvation, do not misattribute. return stalled_for = now - stream.last_window_update_ts if stalled_for <= watchdog_threshold(conn): return # Attempt budget release from lower-priority donors. needed = max(stream.agent_budget_remaining, 1) - stream.agent_budget_remaining needed = max(needed, 1) reclaimed = 0 for donor in sorted(donor_streams, key=lambda s: s.priority): if donor.stream_id == stream.stream_id or donor.reset: continue if donor.priority >= stream.priority: continue take = min(donor.agent_budget_remaining, needed - reclaimed) donor.agent_budget_remaining -= take reclaimed += take if reclaimed >= needed: break if reclaimed >= needed: stream.agent_budget_remaining += reclaimed # Consumer resumes; caller is responsible for emitting WINDOW_UPDATE / MAX_STREAM_DATA. stream.last_window_update_ts = now return # Cannot release budget: reset with a distinguishable code so transport and agent logs agree. if stalled_for > watchdog_threshold(conn) + release_attempt_seconds: stream.reset = True raise MultiplexedStreamStarvation( f"stream {stream.stream_id} self-starved for {stalled_for:.2f}s " f"(threshold {watchdog_threshold(conn):.2f}s); resetting with " f"agent_backpressure_cancel instead of client_cancel" ) # Within release window but insufficient budget: surface for caller to escalate. raise MultiplexedStreamStarvation( f"stream {stream.stream_id} window-zero for {stalled_for:.2f}s; " f"reclaimed {reclaimed} of {needed} required budget units" ) ```