# Why does an instance lose tool-call continuity when an MCP streamable-HTTP session is re-bound to a fresh SSE channel mid-tool-call **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers/clients using the HTTP-native "Streamable HTTP" transport (single endpoint, `POST` for client→server JSON-RPC, optional `GET` for server→client SSE, `Mcp-Session-Id` header for session continuity) where a long-running tool call spans a transport-level reconnect. Does not apply to stdio transport, nor to stateless one-shot HTTP bindings where every request is self-contained. ## Core Distinction The failure is not "the connection dropped." TCP/SSE drops are ordinary and recoverable. The failure is that the *session identity* (`Mcp-Session-Id`) and the *stream binding* (which SSE channel carries the response to a given in-flight request `id`) are two different lifetimes, and the Streamable HTTP spec lets them decouple. A client that reconnects and re-establishes a `GET` SSE channel gets a *valid session* with a *new stream*, but the server's in-flight `tools/call` was emitting its partial progress and final result onto the *old* stream's write queue. The result: the session is alive, the request `id` is still "pending" in the client's bookkeeping, and no bytes will ever arrive for it. The agent does not see an error — it sees silence, then a timeout it may or may not classify as retryable. The invariant that is violated: **a JSON-RPC response is only meaningful on the stream that the corresponding request was bound to at dispatch time.** Session continuity ≠ response continuity. ## What Was Observed A research agent issued `tools/call` for a `web_crawl` tool with a 90s server-side budget. The MCP server (Streamable HTTP) accepted the `POST`, returned `202 Accepted` with an `Mcp-Session-Id`, and began streaming progress notifications and the eventual result over the SSE channel opened by the client's `GET` to the same endpoint. At t≈40s a load balancer idle-timed the `GET` SSE connection (no keepalive frames from the server during a long tool execution). The client's transport layer, correctly per the spec, reconnected: new `GET`, same `Mcp-Session-Id`. Server responded `200` and opened a fresh SSE stream. The client re-issued nothing — it believed the session was intact. The server, however, had bound the in-flight request's response channel to the *old* stream's `EventSource` writer. When `web_crawl` completed at t≈78s, the server attempted `write` on a closed pipe, swallowed the error (a common but fatal pattern: `try: await stream.send(...) except ConnectionError: pass`), and marked the request complete in its own bookkeeping. The client's pending-request table still had the request `id` at t=120s when its own deadline fired. Observed trace, condensed: ``` client POST /mcp {method:"tools/call", id:7, params:{name:"web_crawl"}} server 202 Mcp-Session-Id: s-9f2a client GET /mcp Mcp-Session-Id: s-9f2a -> SSE stream A server SSE-A {method:"notifications/progress", params:{progress:0.1,...}} (id:7) ... (LB idle timeout, 40s) ... client GET /mcp Mcp-Session-Id: s-9f2a -> SSE stream B server SSE-B (no events; server has no mapping from s-9f2a to id:7 on stream B) server {id:7, result:{...}} -> attempted on stream A -> ConnectionError -> dropped client pending[id:7] expires at deadline -> TimeoutError ``` Three things went wrong simultaneously and each masked the others: the server treated stream-write failure as benign; the client treated "session valid" as "request alive"; and the JSON-RPC layer had no resumability token (`Last-Event-ID`) because the server never assigned SSE event `id:` fields to tool-call progress frames. ## Condition of Validity The failure requires all of the following to co-occur; remove any one and the system degrades gracefully: 1. **A tool call whose wall-clock duration exceeds the transport's idle timeout.** Short calls complete before any reconnect and are unaffected. 2. **Server-side response binding to a specific stream instance**, rather than to a session-scoped outbound queue that a new stream can drain. This is the non-obvious architectural choice — many implementations bind at `POST` time to "whatever SSE is currently open," which is correct only if exactly one stream is ever open per session. 3. **No SSE `event id:` on progress/result frames**, so the client cannot issue `Last-Event-ID` on reconnect to request replay of missed frames. The spec permits resumability but does not mandate it. 4. **Server swallows write-on-closed-stream errors** instead of failing the request and emitting a JSON-RPC error on the next viable channel. If (2) is fixed — session-scoped outbound queue — the reconnect drains pending frames onto stream B and the client sees the result. If (3) is fixed — event IDs + replay buffer — even a queue-less server can recover. If (4) is fixed — surface the failure — the client gets a `-32000`-class error and can retry idempotently. The dangerous configuration is the one where all four hold, because every layer reports success. ## Decision Boundary The client cannot distinguish, from the transport alone, between three states after a reconnect: - **State A:** request still running, will emit on stream B (correct server, queue-bound). - **State B:** request still running, will emit on dead stream A (broken server, stream-bound). - **State C:** request already completed and result was dropped (broken server, stream-bound, fast tool). States B and C are indistinguishable to the client until its own deadline fires, and State C's result is *unrecoverable* without server-side replay — the work was done and paid for, and the answer is gone. This is the sharp operational boundary: **a reconnect during an in-flight tool call is a point at which the client must either (a) possess a resumability token to replay missed frames, or (b) treat the request as failed and re-issue under a fresh id, accepting duplicate execution.** There is no middle path where the client waits and hopes. The correct decision rule for an agent runtime: 1. On SSE reconnect, if the server advertised resumability (SSE `id:` frames were seen pre-disconnect), reconnect with `Last-Event-ID` set to the last seen id and keep pending requests alive. 2. If the server did *not* advertise resumability, immediately fail all pending requests bound to the dropped stream with a distinct, retryable error class — do not let them sit until the generic deadline, because the deadline conflates "slow tool" with "orphaned result" and the agent's retry policy will treat them identically. 3. Mark the tool as **at-least-once** in the tool manifest so the agent's planner knows re-issuance may duplicate side effects. ## Operational Effect The practical consequence is that Streamable HTTP MCP servers must be built around a **session-scoped outbound multiplexer**, not a per-connection writer. Concretely: `Mcp-Session-Id → asyncio.Queue[SSEFrame]`, with each active `GET` stream as a *drainer* of that queue. On reconnect, the new stream drains whatever accumulated. Progress and result frames carry monotonic `id:` values so a client that missed frames mid-drain can replay. Write failures on a stream detach the drainer but leave the queue and the request alive. The client-side invariant: never treat `Mcp-Session-Id` validity as evidence of request liveness. Track pending requests against the *stream generation* they were dispatched on, and on generation change, resolve them explicitly — either by replay or by failure. An agent that skips this step will, under load, silently lose the results of its most expensive tool calls (the long ones, which are exactly the ones that cross idle timeouts), and will retry them, doubling cost and, for non-idempotent tools, corrupting external state. ```python import time from dataclasses import dataclass, field from typing import Optional class OrphanedToolCallError(RuntimeError): """Raised when an in-flight MCP tool call's response stream was lost and the server did not advertise resumability, so the result cannot be recovered on the new stream generation.""" @dataclass class PendingRequest: request_id: int stream_generation: int dispatched_at: float resumable: bool @dataclass class SessionState: session_id: str stream_generation: int = 0 resumability_advertised: bool = False pending: dict = field(default_factory=dict) def on_sse_reconnect(self, now: Optional[float] = None) -> list: """Called when the GET SSE channel is re-established. Returns request_ids that were resolved (failed) by this reconnect.""" now = now if now is not None else time.time() self.stream_generation += 1 orphaned = [] for rid, req in list(self.pending.items()): if req.stream_generation >= self.stream_generation: continue # dispatched on the new stream already if self.resumability_advertised and req.resumable: continue # will be replayed via Last-Event-ID; keep alive # No replay path: the result, if produced, is unrecoverable. orphaned.append(rid) del self.pending[rid] if orphaned: raise OrphanedToolCallError( f"session {self.session_id}: {len(orphaned)} tool call(s) " f"{orphaned} orphaned by stream generation " f"{self.stream_generation - 1}->{self.stream_generation}; " f"server resumability={self.resumability_advertised}. " f"Re-issue under fresh ids; tools are at-least-once." ) return orphaned ```