# Why does an instance lose tool-call continuity when an MCP HTTP transport migrates from SSE to Streamable HTTP mid-session? **Date of Record:** 2026 November 29 **Scope:** Applies to MCP clients and servers that negotiate a session over the legacy HTTP+SSE transport and then resume the same logical session against a Streamable HTTP endpoint (or vice versa) during migration, load-balancer failover, or rolling deploy. Does not apply to pure stdio transports or to sessions that are torn down and re-initialized with a fresh `initialize` handshake. ## Core Distinction The failure is not "the connection dropped." A dropped connection is recoverable because MCP defines a resumption contract: the client holds a `Last-Event-ID`, the server replays events after that ID, and the session continues. The non-obvious distinction is between **transport-level resumption** (replaying the byte stream of notifications) and **session-level resumption** (re-establishing the negotiated capability set, protocol version, and the server's in-flight request state). Legacy SSE and Streamable HTTP implement these two things with different state owners. SSE keeps the server-side event log authoritative and the client is a passive replay target; Streamable HTTP makes each POST an independent request whose response stream may or may not be resumable, and pushes session identity into the `Mcp-Session-Id` header plus an optional `Last-Event-ID` per stream. When a session crosses that boundary, the client can successfully replay the *notification* stream while silently losing the *request/response correlation* for any tool call that was in flight. The agent then believes it resumed; the server believes it is answering a different request. The invariant that breaks is: *a resumed session must preserve a one-to-one mapping between outstanding JSON-RPC request IDs and their pending server-side computations.* SSE preserves it implicitly (single long-lived stream, ordered). Streamable HTTP does not preserve it across transport switch unless the server re-keys in-flight work to the session ID and the client re-attaches the same request IDs. ## What Was Observed A client agent had issued `tools/call` with `id: 41` (a long-running `execute_sql` tool, ~40s). The server had begun execution over SSE and emitted a progress notification (`notifications/progress`, `progressToken: "q-41"`). A rolling deploy moved the server's session to a Streamable HTTP listener. The client, seeing the SSE stream close, reconnected per the resumption contract: `GET /mcp` with `Mcp-Session-Id: sess_9f2` and `Last-Event-ID: 118`. The server accepted the session, replayed events 119–124 (the progress notification among them), and returned `200` with an open stream. Everything looked healthy. But the tool execution had been owned by the *old* transport's request handler. On the Streamable HTTP side, the server had reconstructed the session record from the shared session store — which contained the negotiated capabilities and the event log, but **not** the pending-request table, because that table was process-local to the SSE handler. The replayed progress event referenced `progressToken: "q-41"`, but no `id: 41` response would ever be produced on the new stream. The client's request-ID table still held `41` as pending. The agent's reasoning loop, which had been waiting on `41` to proceed to a dependent `tools/call` (`id: 42`), blocked until its own token budget for the step expired, then — critically — *retried* `41` with a new ID `43` because its retry policy treated "no response within deadline" as "transport failure, safe to reissue." The retried `execute_sql` ran again. It was not idempotent (it performed an `INSERT ... SELECT` into a ledger). The observable outcome was a duplicated ledger row, plus a stale progress notification (`q-41`) that arrived after the duplicate had already committed, which the agent mis-attributed to the retry and used to mark the step "confirmed." Two compounding mechanisms are visible here: 1. **Replay without re-correlation.** The server replayed notifications faithfully (satisfying the letter of the resumption contract) while the request they referred to had no live handler. The progress event became an orphan. 2. **Retry amplification under ambiguous liveness.** The client could not distinguish "server is slow" from "server forgot my request," so its deadline-based retry policy converted a lost correlation into a duplicate side effect. A second, quieter variant: when the switch went the other direction (Streamable HTTP → SSE), the client sent `initialize` again because SSE endpoints typically require a fresh `GET` handshake, and the server allocated a *new* `Mcp-Session-Id`, orphaning the old session's pending requests entirely while the old `Last-Event-ID` replayed into the void. The agent observed a successful `initialize` and concluded resumption succeeded. ## Condition of Validity The resumption contract is only sound under a condition most migration runbooks omit: **the entity that owns the in-flight request table must be the same entity that owns the event log, or the two must be transactionally co-located.** In SSE this holds by construction because a single handler owns both. In Streamable HTTP it holds only if the server persists pending-request state (request ID → handler/result channel, plus the `progressToken` binding) into the same store keyed by `Mcp-Session-Id` that backs the event log, and only if the client, on resume, re-attaches with the *same* request IDs rather than re-initializing. Concretely, resumption is valid across a transport migration if and only if all of the following hold at the moment of switch: - The `Mcp-Session-Id` is preserved (not re-minted) and the server's session store is the single source of truth for both the event log and the pending-request table. - Every outstanding request ID in the client's table has a corresponding entry in the server's pending-request table, or a terminal result already recorded that will be emitted on the resumed stream. - The client's retry policy is gated on *explicit* request lifecycle signals (terminal result, explicit cancellation, or a server-issued "request unknown" error), not on wall-clock deadline alone. - `progressToken` values are namespaced to the session and validated against the pending-request table before the client acts on them. If any of these is false, the session is *transport-resumed but session-divergent*, and the client must treat it as a new session — re-running `initialize`, discarding pending IDs, and reconciling side effects — rather than pretending continuity. ## Decision Boundary The operational decision is: **on transport switch, do you resume or re-initialize?** The boundary is drawn by whether the server can prove request-table continuity. - If the server, on receiving the resumed `GET`/`POST` with `Mcp-Session-Id`, can enumerate the outstanding request IDs and either (a) resume their handlers or (b) return a terminal error for each, resume is safe. - If the server can only replay the event log (the common case for a stateless Streamable HTTP deployment behind a load balancer), resume is unsafe for any session with outstanding requests. The client must not reissue those requests blindly; it must first query server state (`tools/call` to a status endpoint, or a `notifications/cancelled` + fresh call with an idempotency key) to determine whether the prior side effect committed. The trap is that the *transport* signals success (HTTP 200, events flowing) while the *session* has diverged. Any guardrail that trusts transport-level success as session-level success will fail here. The guardrail must be an explicit request-table reconciliation step, and the retry policy must be idempotency-aware: a retried `tools/call` must carry an idempotency key derived from the original request ID (`41`), so the server can dedupe rather than double-execute. ## Operational Effect Downstream of an unguarded migration, the agent's reasoning loop treats orphaned progress notifications as evidence of completion, inflates its confidence in a step whose side effect may have run twice or not at all, and proceeds to dependent calls (`42`) that assume a state the ledger does not actually hold. The error compounds: `42` reads the duplicated row, produces a wrong aggregate, and every subsequent step inherits the corruption. By the time the agent's episodic memory records "step succeeded," the semantic record is false, and cold-start replay of that memory will re-derive the wrong conclusion. The bounded fix is to make session resumption a *verified* operation rather than an *assumed* one: the client, on any transport switch, must reconcile its pending-request table against the server's before resuming reasoning, and must refuse to treat replayed notifications as terminal signals. The code below encodes that invariant as a guard that raises when a resumed session cannot account for every outstanding request ID. ```python class SessionResumptionDivergence(RuntimeError): """Raised when a transport-resumed MCP session cannot account for outstanding request IDs.""" pass def resume_session(client_pending: dict[int, dict], server_pending: dict[int, dict], replayed_events: list[dict], session_id: str) -> dict[int, dict]: """ Reconcile a client's pending-request table against the server's after a transport migration (SSE <-> Streamable HTTP). Returns the set of requests that are genuinely resumable. Raises if any outstanding request cannot be accounted for, because treating it as resumable would permit a duplicate non-idempotent tool call. """ if not session_id: raise SessionResumptionDivergence("missing Mcp-Session-Id; cannot prove continuity") resumable: dict[int, dict] = {} unaccounted: list[int] = [] for req_id, req in client_pending.items(): if req_id in server_pending: # Handler still alive on the new transport: safe to resume. resumable[req_id] = server_pending[req_id] else: # Not in the server's pending table. Only acceptable if a terminal # result for this ID already appears in the replayed event stream. terminal = any( ev.get("id") == req_id and ("result" in ev or "error" in ev) for ev in replayed_events ) if terminal: resumable[req_id] = {"terminal": True} else: unaccounted.append(req_id) # Orphaned progress notifications referencing a token with no live request # are a divergence signal, not a completion signal. live_tokens = {r.get("progressToken") for r in resumable.values() if r.get("progressToken")} for ev in replayed_events: if ev.get("method") == "notifications/progress": tok = ev.get("params", {}).get("progressToken") if tok and tok not in live_tokens and not any( r.get("terminal") for r in resumable.values() ): unaccounted.append(-1) # sentinel: orphaned progress if unaccounted: raise SessionResumptionDivergence( f"session {session_id}: transport resumed but request table diverged; " f"unaccounted request IDs {unaccounted}. Do NOT retry blindly — " f"reconcile via idempotency key before reissuing tools/call." ) return resumable ```