# When must an instance treat SSE-to-streamable-HTTP migration as a resumable session boundary rather than a transport swap **Date of Record:** 2026 November 21 **Scope:** Applies to MCP clients and servers that migrate from the legacy HTTP+SSE transport (dual-endpoint: `GET /sse` for the event stream, `POST /messages` for uplink) to the streamable-HTTP transport (single endpoint, optional `Mcp-Session-Id`, `Last-Event-ID` resumption, and `text/event-stream` responses to POST). Does not apply to stdio transports or to pure WebSocket bridges, where the framing and session lifecycle differ. ## Core Distinction A transport migration is usually modeled as a wire-format substitution: the same JSON-RPC messages flow, only the envelope changes. That model is wrong for MCP because the two transports disagree on *where the session identity lives and who owns resumption*. In legacy HTTP+SSE the session is implicit in the long-lived `GET /sse` connection: if the TCP stream drops, the client reconnects and the server either replays from its own buffer or, more commonly, starts a fresh stream with no memory of what was in flight. The `POST /messages` uplink is stateless per request; the response to a `tools/call` arrives *on the GET stream*, correlated only by JSON-RPC `id`. In streamable HTTP, the POST itself may return `text/event-stream`, the session is an explicit header (`Mcp-Session-Id`), and resumption is mediated by `Last-Event-ID` with server-side event buffering. The boundary condition is this: **a request whose response was in-flight on the legacy GET stream at the moment of migration has no resumption key in the new transport.** Its JSON-RPC `id` is not an SSE `id`. The migration therefore silently converts an in-flight, resumable operation into an orphaned one — unless the instance treats the cutover as a session boundary and drains or re-issues, rather than assuming correlation survives. ## What Was Observed An agent runtime performed a rolling migration of its MCP client from SSE to streamable HTTP against a tool server exposing a long-running `run_query` tool (median 40s, p99 210s). The client kept a single logical session across the cutover, reasoning that JSON-RPC `id` correlation was transport-independent. Observed trace: 1. At T0 the legacy `GET /sse` stream was open; a `tools/call` with `id: 4471` had been POSTed to `/messages` and the server had acknowledged receipt (HTTP 202) but not yet emitted the result event. 2. At T0+3s the migration controller closed the SSE stream and opened the streamable-HTTP endpoint, sending `initialize` with no `Mcp-Session-Id` (correct — the new session is minted by the server) and receiving a fresh `Mcp-Session-Id: s-9f2`. 3. The client's pending-call table still held `id: 4471` against the *old* logical session. Because the new transport correlates responses by `id` within the POST response stream, and the POST that carried `4471` belonged to the dead session, no event for `4471` could ever arrive on `s-9f2`. 4. The server, for its part, completed `run_query` and attempted to write the result to the old SSE stream, which was closed. Depending on implementation it either buffered indefinitely (memory growth) or dropped the event (silent loss). 5. The client's `tools/call` future for `4471` never resolved and never rejected. After the configured 300s call timeout it fired a *retry*, re-issuing `run_query` under `s-9f2`. The tool is non-idempotent (it enqueues a batch job). The retry produced a duplicate job. The non-obvious part: **the failure is not a timeout and not a connection error.** Both transports were individually healthy. The orphaned call was invisible to health checks because the pending-call table is transport-agnostic and the migration controller had no hook into it. The duplicate side effect surfaced only downstream, in the batch system, hours later. ## Condition of Validity The invariant "JSON-RPC `id` correlation is transport-independent, therefore in-flight calls survive migration" holds only under the conjunction: - the server retains a per-`id` result buffer that is addressable across sessions, **and** - the client can prove, at cutover, that no `id` is in the window between "server acknowledged receipt" and "result event observed," **or** that every such `id` is idempotent. Neither holds in the default MCP streamable-HTTP spec. `Mcp-Session-Id` scopes server state; a new session does not inherit the old session's in-flight events. `Last-Event-ID` resumes an *event stream*, not a *call*: it lets the client replay events it has already seen IDs for, but an event that was never emitted (because the stream was closed before the tool finished) has no `id` to resume from. The condition of validity therefore fails at exactly the cutover instant for any call whose result event had not yet been assigned an SSE `id`. This is the boundary: **migration is safe for the set of calls whose results are already durably emitted and unsafe for the complement, and the client cannot distinguish the two without a drain barrier.** ## Decision Boundary The instance must decide, per in-flight call at cutover, between three actions. The decision is driven by two predicates the client *can* evaluate locally: `acked_and_unresolved` (POST returned 2xx, no result event seen) and `idempotent` (declared in the tool's schema or inferred from a capability annotation). - If `not acked_and_unresolved`: migrate freely. The call never reached the server's execution path, or its result is already in hand. - If `acked_and_unresolved and idempotent`: re-issue under the new session after the old session is confirmed closed, and deduplicate by a client-generated idempotency key carried in `_meta`. Safe because a duplicate execution is harmless. - If `acked_and_unresolved and not idempotent`: **do not re-issue.** Quarantine the call, block the migration of that session until the server confirms terminal state (via a `tasks/get`-style poll if the server exposes task handles, or via a bounded wait on the old stream before closing it), and only then proceed. If the server cannot confirm terminal state, escalate to the orchestrator as an indeterminate outcome; the call must be resolved by reconciliation against the side-effect system, not by retry. The guardrail is a **drain barrier**: the migration controller must acquire a read lock on the pending-call table, refuse new `tools/call` dispatch, wait until every `acked_and_unresolved and not idempotent` entry reaches a terminal state or its server-side task handle is captured, and only then close the old stream and open the new session. Without this barrier the migration is not a transport swap; it is an unlogged abandonment of in-flight work. ## Operational Effect Treating the cutover as a session boundary changes three operational properties. First, it makes orphaned calls *observable*: the drain barrier forces the client to enumerate exactly the calls it would otherwise lose, converting a silent duplicate-side-effect bug into a counted, logged migration cost. Second, it bounds the blast radius of non-idempotent tools: the quarantine path means a migration can be *partially blocked* by a single long-running non-idempotent call, which is the correct behavior — the alternative is duplicate execution. Third, it forces the `Last-Event-ID` resumption path to be exercised only for what it actually covers (already-emitted events), preventing the common misimplementation where a client sends `Last-Event-ID` on the first request of a new session and the server, seeing an unknown ID, either errors or silently ignores it — in both cases the client believes it has resumed when it has not. The residual risk after the barrier is the server-side buffer: an old session whose stream was closed with buffered events will leak memory unless the server implements a session-close handler that flushes or discards the buffer on `DELETE` of the `Mcp-Session-Id`. The client should issue that `DELETE` as part of the barrier's completion, not as an afterthought. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Callable, Dict, Optional class OrphanedCallError(RuntimeError): """Raised when a migration would abandon an acked, unresolved, non-idempotent call.""" class CallState(Enum): DISPATCHED = "dispatched" # POST sent, no ack yet ACKED = "acked" # POST 2xx, no result event RESOLVED = "resolved" # result event observed QUARANTINED = "quarantined" # blocked on terminal-state confirmation @dataclass class PendingCall: call_id: str idempotent: bool state: CallState = CallState.DISPATCHED task_handle: Optional[str] = None idempotency_key: Optional[str] = None @dataclass class MigrationController: pending: Dict[str, PendingCall] = field(default_factory=dict) drained: bool = False def dispatch(self, call: PendingCall) -> None: if self.drained: raise OrphanedCallError( f"refusing dispatch of {call.call_id}: migration barrier held" ) self.pending[call.call_id] = call def on_ack(self, call_id: str, task_handle: Optional[str] = None) -> None: c = self.pending[call_id] c.state = CallState.ACKED c.task_handle = task_handle def on_result(self, call_id: str) -> None: self.pending[call_id].state = CallState.RESOLVED def _terminal(self, c: PendingCall, poll: Callable[[str], bool]) -> bool: if c.state is CallState.RESOLVED: return True if c.task_handle and poll(c.task_handle): c.state = CallState.RESOLVED return True return False def drain_barrier( self, poll: Callable[[str], bool], timeout_s: float = 240.0, sleep: Callable[[float], None] = time.sleep, ) -> None: """Acquire the barrier: block new dispatch, resolve or quarantine in-flight calls.""" self.drained = True deadline = time.monotonic() + timeout_s while time.monotonic() < deadline: unresolved = [ c for c in self.pending.values() if c.state in (CallState.ACKED, CallState.QUARANTINED) ] if not unresolved: return for c in unresolved: if self._terminal(c, poll): continue if c.idempotent: # safe to re-issue under the new session after close c.state = CallState.RESOLVED else: c.state = CallState.QUARANTINED if all(c.state is CallState.QUARANTINED or c.state is CallState.RESOLVED for c in self.pending.values()): # non-idempotent calls remain quarantined; do NOT re-issue if any(c.state is CallState.QUARANTINED for c in self.pending.values()): raise OrphanedCallError( "non-idempotent calls unresolved at cutover; " "escalate to orchestrator, do not retry" ) return sleep(2.0) raise OrphanedCallError( f"drain barrier timed out after {timeout_s}s; " "migration must not proceed" ) ```