# What structural signals indicate that an MCP streamable-HTTP session has silently degraded into a zombie reconnect loop **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers/clients using the streamable HTTP transport (SSE-over-HTTP with `Mcp-Session-Id` resumption) where a long-lived agent holds a session across tool calls. Does not apply to stdio transport, nor to one-shot stateless HTTP request/response MCP deployments. ## Core Distinction The failure mode is *not* "the connection dropped." A dropped connection is a clean, observable event: the client sees a TCP reset or a read timeout, tears down the session, and re-initializes. The boundary condition that actually harms agents is **a session that is still nominally alive — `200 OK`, valid `Mcp-Session-Id`, SSE heartbeat frames still arriving — but whose event stream has fallen permanently behind the server's write path.** The server's per-session outbound queue is full and dropping or blocking new JSON-RPC replies; the client keeps reading heartbeats and keeps believing the session is healthy. The agent then blocks on a tool result that was enqueued but never flushed, and — critically — the reconnect logic never fires because nothing *looks* broken. The invariant that gets violated: **liveness signal ≠ delivery guarantee.** Heartbeats prove the transport socket is open. They say nothing about whether the reply to request `n` is still in the queue. Agents that treat heartbeat continuity as a proxy for reply delivery will hang indefinitely on a session that is structurally dead. ## What Was Observed A planner agent issued a `tools/call` for a code-search tool. The MCP server (streamable HTTP, SSE response stream) accepted the POST, wrote the reply into the session's outbound channel, and returned `202 Accepted` on the POST (per the streamable-HTTP spec, replies ride the GET SSE stream, not the POST response). The GET SSE stream was backpressured: the client's read loop had stalled under a large prior batch of `notifications/progress` frames and the server's bounded outbound buffer (observed at 256 frames) was full. The server's writer goroutine blocked on the channel send. The reply frame for the `tools/call` sat behind 256 progress notifications that the client was not draining fast enough. Three structural signals co-occurred, and only the third is a reliable indicator: 1. **Heartbeat continuity, falsely reassuring.** The server's keepalive is emitted on a *separate* lightweight path and continued to arrive every 15s. The client's liveness monitor saw heartbeats and reset its idle timer each time. No reconnect triggered. 2. **POST acknowledgements outrunning replies.** Every POST returned `202` promptly (the ack path is unbuffered), so the client's request-side metrics looked normal. Request latency measured at the POST layer was ~2ms. Reply latency measured at the SSE layer was unbounded. 3. **Monotonic reply-sequence stall.** The decisive signal: the client tracked the highest JSON-RPC `id` for which it had received a reply. That high-water mark froze while the *acknowledged-request* high-water mark kept climbing. The delta between "requests acked" and "replies received" grew without bound. This divergence — not any socket-level error — is the structural fingerprint of a zombied session. A naive reconnect policy keyed on socket state never fired. The agent sat for 40 minutes until an external wall-clock timeout killed the whole run, losing all in-flight tool state. ## Condition of Validity This diagnosis is valid only when all of the following hold: - The transport is streamable HTTP with a **separate** reply channel (GET SSE) from the request channel (POST), so acks and replies travel on different paths with independent backpressure. - The server emits keepalives on a path not subject to the same outbound queue as replies (otherwise heartbeats would also stall and the failure would be *visible* — a different, easier case). - The client maintains, or can cheaply derive, a **reply high-water mark** and an **acknowledged-request high-water mark** that are comparable (same `id` space). If the server multiplexes heartbeats through the same bounded queue as replies, the session stalls visibly and ordinary read-timeout reconnects suffice — this article's guardrail is unnecessary. If the client does not track request/reply correspondence at all (fire-and-forget notifications only), the divergence signal is unavailable and you must fall back to per-request deadlines. ## Decision Boundary The operative rule: **treat the reply high-water mark, not the socket, as the liveness authority for any request awaiting a reply.** Concretely, a session is *degraded* — not dead, not healthy — when, for any outstanding request older than a threshold `T_stall`, the acknowledged-request mark exceeds the reply mark and no reply for that `id` has arrived, *even though heartbeats are current*. The boundary between "keep waiting" and "tear down and resume" is set by whether the transport supports resumption. Streamable HTTP allows reconnecting the GET stream with `Last-Event-ID` to replay missed frames. So the correct action on detecting divergence is **not** a full session re-init (which discards server-side session state and forces the agent to re-establish tool context) but a **stream reconnect with `Last-Event-ID` set to the last successfully processed event id**, which lets the server replay the backlog the client failed to drain. Full re-init is the fallback only if resumption itself fails to advance the reply mark within one retry. Two guardrails bound this: - **Bounded outbound queue with explicit overflow signal.** The server must, on queue-full, emit a `notifications/message` (or transport-level error frame) rather than silently blocking the writer. Silent blocking is what converts backpressure into a zombie. A server that *drops* frames without signaling is worse than one that blocks, because the client's replay window is corrupted. - **Divergence watchdog with monotonic counters.** The client runs a watchdog comparing ack-mark vs reply-mark; on divergence exceeding `T_stall`, it forces a `Last-Event-ID` reconnect and re-issues any request whose reply never arrived, keyed on idempotency tokens so the server does not double-execute side-effecting tools. ## Operational Effect Without the divergence watchdog, agents exhibit a specific pathology: they appear *busy* (heartbeats flowing, POSTs acking) while making zero forward progress, and they consume their entire wall-clock or token budget waiting on a reply that is queued but never flushed. Because nothing throws, no error propagates to the orchestrator, and the failure is only discovered at the outer timeout — by which point mid-task checkpoint state is stale and the resume path replays from a checkpoint that predates the stalled call. With the watchdog, the failure is caught within `T_stall`, the stream is resumed from the last processed event id, the backlog is drained, and the agent continues with its in-flight tool state intact. The cost is bounded: one reconnect plus at most one idempotent re-issue. The invariant that must be enforced architecturally is that **liveness is a property of the reply stream's progress, not of the transport socket**, and that the server's outbound queue must never block silently — it must either apply backpressure the client can observe (via a full-queue signal) or drop with an explicit, replayable marker. ```python import time from dataclasses import dataclass, field class ZombieSessionError(RuntimeError): """Raised when a streamable-HTTP MCP session is alive at the socket layer but its reply stream has stopped advancing (backpressure zombie).""" pass @dataclass class SessionLiveness: ack_high_water: int = 0 # highest JSON-RPC id the server has acked (POST 202) reply_high_water: int = 0 # highest JSON-RPC id for which a reply arrived on SSE last_heartbeat_ts: float = 0.0 last_reply_ts: float = 0.0 last_event_id: str | None = None outstanding: dict = field(default_factory=dict) # id -> enqueue timestamp def check_liveness( live: SessionLiveness, *, now: float, heartbeat_grace: float = 30.0, stall_threshold: float = 20.0, ) -> None: """Enforce the reply-progress invariant. A current heartbeat does NOT prove delivery. We only consider the session healthy if the reply high-water mark advances within stall_threshold for every outstanding request, regardless of heartbeat freshness. """ heartbeat_fresh = (now - live.last_heartbeat_ts) <= heartbeat_grace if not heartbeat_fresh: # Socket genuinely dead: clean reconnect path, not a zombie. raise ZombieSessionError( f"heartbeat stale by {now - live.last_heartbeat_ts:.1f}s; " "clean reconnect required" ) # Heartbeats are fresh, but is the reply stream actually moving? stalled = [ rid for rid, enq in live.outstanding.items() if rid > live.reply_high_water and (now - enq) > stall_threshold ] if stalled and live.ack_high_water > live.reply_high_water: # Divergence: requests acked, replies not delivered, heartbeats current. raise ZombieSessionError( "reply stream stalled behind backpressure: " f"ack_mark={live.ack_high_water} reply_mark={live.reply_high_water} " f"stalled_ids={sorted(stalled)} last_event_id={live.last_event_id}; " "resume GET stream with Last-Event-ID rather than full re-init" ) def resume_stream(live: SessionLiveness, *, reconnect_fn, max_retries: int = 1) -> None: """Attempt Last-Event-ID resumption; escalate to full re-init only if the reply high-water mark fails to advance after resumption.""" for attempt in range(max_retries + 1): before = live.reply_high_water reconnect_fn(last_event_id=live.last_event_id) if live.reply_high_water > before: return raise ZombieSessionError( "resumption did not advance reply high-water mark after " f"{max_retries + 1} attempts; session state must be rebuilt from checkpoint" ) ```