# Why does an instance stall on HTTP-native MCP transport when SSE multiplexing backpressure outruns the client read loop **Date of Record:** 2026 December 3 **Scope:** Applies to MCP servers exposing streamable-HTTP transport (POST request/response plus optional GET SSE stream) consumed by an LLM agent whose tool-call loop multiplexes many concurrent requests over a single connection or single-threaded event reader. Does not apply to stdio transport, nor to HTTP servers whose SSE stream is exclusively server-push with no correlation to in-flight POST tool calls. ## Core Distinction The failure is not "the server is slow" and not "the network dropped." It is a **backpressure/ordering mismatch between the POST response channel and the multiplexed SSE notification channel** when both are carried on the same HTTP/1.1 connection or funneled through a single client-side reader that processes frames serially. Two distinct things compete for one resource: 1. **Request responses** — the JSON-RPC reply to a specific `tools/call`, delivered on the POST body. 2. **Out-of-band stream events** — progress notifications, log messages, `notifications/cancelled`, resource updates, delivered on the GET SSE stream. An MCP client that reads the SSE stream on the *same* event loop that awaits POST responses, or that multiplexes both onto one HTTP/1.1 keep-alive socket, hits a **head-of-line blocking invariant**: the SSE stream is unbounded and server-paced, while the POST response is bounded and client-awaited. When the server emits progress notifications faster than the client's single reader drains them, the reader never returns to the socket that carries the awaited response. The agent's `tools/call` future resolves only after the SSE backlog is consumed — which never happens if the backlog is generated by the very call being awaited. This is a **self-sustaining stall**, not a timeout. The subtle part: with HTTP/2 or separate connections this doesn't occur, so it reproduces only under HTTP/1.1 keep-alive, single-connection proxying, or a client that serializes all frames through one async iterator. It is invisible in unit tests that mock the transport and appears only under concurrent tool-call load with a chatty server. ## What Was Observed A tool-calling agent issued a long-running `tools/call` (`bulk_embed`), which the server instrumented with `notifications/progress` at ~200/sec. Trace: - **t0** — client POSTs `tools/call` on keep-alive socket S. Server accepts, begins streaming progress on the GET SSE endpoint, which the client had opened on the *same* socket S (HTTP/1.1, no multiplexing). - **t0+40ms** — client reader loop pulls the next frame. It sees a progress notification, dispatches it to the agent's progress handler, and loops. The POST response bytes are queued in the kernel buffer behind the SSE frames on S. - **t0+2s** — server has emitted ~400 progress frames; client has drained ~400 but the POST response has not yet been written because the server's handler hasn't returned. - **t0+8s** — server handler completes, writes the JSON-RPC response to the POST body on S. But the client reader is still consuming the tail of the progress backlog (server emitted faster than client dispatched, because the agent's progress handler does synchronous work — appending to the transcript, updating token accounting). - **t0+8.4s** — backlog drained; reader finally reaches the response frame. `tools/call` resolves 8.4s after the work finished. - **Degenerate case** — if the server emits progress *until it receives a cancellation* and the client's cancellation is itself queued behind the SSE stream, neither side advances. Observed as a hang with 100% CPU on the reader and zero bytes read on the POST body, persisting until the socket-level idle timeout. The signature: **response latency ≈ backlog_size × per_frame_dispatch_cost**, and the stall is *proportional to how chatty the server is*, not to how long the tool took. A 200ms tool that emits 10k notifications stalls longer than a 10s tool that emits none. ## Condition of Validity The stall requires **all** of the following to hold simultaneously: 1. POST response and SSE stream share a single ordered byte channel (HTTP/1.1 keep-alive, a single-connection tunnel, or a client reader that serializes both). 2. The server emits stream events *during* the call whose response is awaited (progress, logs, or intermediate resource updates correlated to the in-flight request). 3. The client's per-frame dispatch cost is non-zero and the emission rate exceeds `1 / dispatch_cost` — i.e., the producer outruns the consumer. 4. There is no independent reader for the POST response (no separate task/thread awaiting the response body). If (1) is broken by HTTP/2 stream multiplexing or a second connection, the invariant fails and no stall occurs. If (2) is absent (server only emits events between calls), the reader drains between calls and the response is next. If (4) is broken by a dedicated response reader, backpressure is absorbed by the socket buffer until it fills, then surfaces as TCP-level flow control — a *different* failure (write-block on the server), not a client-side stall. This is precisely why the bug is non-obvious: the *correct* MCP streamable-HTTP design assumes the client can correlate responses and stream events independently. An agent runtime that reuses one `httpx.AsyncClient` connection and one `async for` reader violates that assumption silently. ## Decision Boundary The architectural invariant to enforce: **a response-bearing channel and an unbounded notification channel must never share an ordered reader.** Concretely, the client must either: - **Demultiplex by request ID at the transport layer** — spawn a dedicated task per POST that awaits the response body, and a separate task that drains the SSE stream into a bounded queue, with the agent's progress handler consuming from that queue *off* the critical path. The response future must not depend on the SSE task making progress. - **Bound the SSE queue and apply backpressure to the server**, not to the response path. If the bounded queue fills, the client must either drop progress notifications (they are advisory) or send `notifications/cancelled`/flow-control signals — never block the response reader. - **Force HTTP/2 or separate connections** when the server is known to be chatty, so the kernel multiplexes streams and head-of-line blocking is removed. The decision boundary for the agent: **any tool call whose server emits correlated stream events must be dispatched on a transport that guarantees response/stream independence.** If the runtime cannot guarantee this (single-connection HTTP/1.1 client), it must *disable* progress notifications for that call (`progressToken` omitted) rather than risk the stall. Dropping observability is strictly cheaper than a self-sustaining hang. The guardrail is a **liveness assertion**: the response future must resolve within `max(work_time, backlog_drain_time) + epsilon`; if the reader observes that the response byte offset is behind the stream byte offset on the same channel and the backlog is growing, it must abort the call and re-dispatch on a demultiplexed transport. ## Operational Effect Without the invariant, an agent fleet exhibits **correlated stalls that look like slow tools but are actually transport shape**. Symptoms: p99 tool latency tracks server verbosity, not work; CPU pegged on the client reader; POST bodies unread while SSE frames flow; cancellation requests themselves delayed behind the stream. Because the stall is proportional to emission rate, scaling the server's observability (more progress, more logs) *worsens* agent throughput — an inverted scaling law that misleads capacity planning. The fix is not a faster reader but a structural separation of channels, plus a bounded, droppable notification path so that server chattiness can never gate response delivery. ```python import asyncio from dataclasses import dataclass class TransportBackpressureStall(RuntimeError): """Raised when an awaited POST response is gated behind an unbounded SSE backlog on a shared ordered channel.""" pass @dataclass class Frame: kind: str # "response" | "notification" request_id: str | None payload: bytes class SharedChannelReader: """ Models the failure: one ordered reader serves both the response body and the SSE stream. Response resolution depends on SSE drain progress. """ def __init__(self, frames: list[Frame], dispatch_cost_per_frame: float = 0.001): self._frames = frames self._dispatch_cost = dispatch_cost_per_frame self._cursor = 0 async def read_until_response(self, request_id: str, max_frames: int) -> Frame: while self._cursor < len(self._frames): if self._cursor > max_frames: raise TransportBackpressureStall( f"response for {request_id} still queued behind " f"{self._cursor} stream frames on shared channel; " f"backlog outran the read loop" ) frame = self._frames[self._cursor] self._cursor += 1 await asyncio.sleep(self._dispatch_cost) # per-frame dispatch if frame.kind == "response" and frame.request_id == request_id: return frame raise TransportBackpressureStall(f"response for {request_id} never observed") def build_chatty_stream(request_id: str, n_progress: int) -> list[Frame]: frames = [Frame("notification", None, b"progress") for _ in range(n_progress)] frames.append(Frame("response", request_id, b'{"result": "ok"}')) return frames async def invoke_tool_shared_channel(request_id: str, n_progress: int) -> Frame: reader = SharedChannelReader(build_chatty_stream(request_id, n_progress)) # Guardrail: bound how many frames the response may be delayed behind. max_frames = 1000 return await reader.read_until_response(request_id, max_frames) async def main() -> None: # Healthy: server quiet, response arrives promptly. await invoke_tool_shared_channel("call-1", n_progress=10) # Pathological: chatty server on a shared HTTP/1.1 channel. try: await invoke_tool_shared_channel("call-2", n_progress=50_000) except TransportBackpressureStall as e: raise TransportBackpressureStall( f"demultiplex required: {e}" ) from e if __name__ == "__main__": asyncio.run(main()) ```