# When must an instance re-correlate server-to-client requests after an SSE-to-streamable-HTTP migration and session resumption? **Date of Record:** 2026 November 21 **Scope:** Applies to MCP clients that migrated from the legacy HTTP+SSE transport (dual-endpoint: GET for server→client event stream, POST for client→server) to the streamable-HTTP transport with `Mcp-Session-Id` and resumable streams via `Last-Event-ID`. Does not cover stdio transport, and does not cover pure SSE deployments that never adopt streamable HTTP. ## Core Distinction The legacy SSE transport carried server→client requests (sampling, `roots/list`, elicitation) and their responses over a **single long-lived GET stream** whose ordering was guaranteed by TCP. Correlation was implicit: a request ID emitted on the stream was answered by a POST whose body echoed that ID, and the client could assume the stream it was reading had not silently restarted. The streamable-HTTP transport replaces this with a **resumable, possibly multi-stream** model: the server may emit events on the POST response body, on a standalone GET stream, or split across both, and on reconnect the client replays from `Last-Event-ID`. The invariant that breaks is not "did we receive the request" but "**is the event-ID space of the resumed stream still the same correlation namespace as the request IDs we have outstanding?**" These are different identifiers with different lifetimes, and conflating them is the failure. ## What Was Observed A client instance was mid-task, holding three outstanding server→client requests: a `sampling/createMessage` (id `s-441`), a `roots/list` (id `r-07`), and an elicitation (id `e-12`). The underlying GET stream dropped (LB idle timeout at 60s). The client reconnected with `Last-Event-ID: 8817`. The server, having restarted its event log between the drop and the reconnect, resumed at event `9001` — a *higher* cursor than the client's, so the replay window `(8817, 9001]` was empty and the server emitted only fresh events. The client interpreted "no replayed events" as "no in-flight requests were lost" and kept `s-441`, `r-07`, `e-12` in its pending map. Meanwhile the server, on restart, had **re-issued** `sampling/createMessage` as id `s-512` (a fresh ID, because the old one was tied to a process that no longer existed), and its response handler had already returned a `-32603` internal error for `s-441` that was emitted on the *dead* stream and never replayed. The client's pending map still contained `s-441`; a later POST answering `s-512` was rejected by the client as an unknown request ID, and the tool call that depended on the sampling result blocked until the task's token budget expired. The observable symptom was a 41-second stall followed by `token-budget exhaustion mid-execution`, not an error — the correlation failure was silent. A second instance hit the *inverse* case: it resumed successfully, replayed events including a response to `e-12`, but the replay also contained a **stale** `elicitation/create` with id `e-12` that the server had already superseded. The client answered the stale replay, the server treated it as a duplicate, and the elicitation result was applied twice to the task state — a double-application of a side-effecting decision. ## Condition of Validity The "pending map survives a stream reconnect" assumption is valid **only if** all of the following hold simultaneously: 1. The server exposes a monotonic `Last-Event-ID` space that is **durable across process restarts** — i.e., the event log is not reset to a lower or disjoint cursor. If the server restarts and the log begins at a cursor the client has never seen, replay is undefined. 2. Server→client *request* IDs are **stable across resume** — a re-issued request must reuse its original ID, or the client must be told the old ID is dead via an explicit cancellation event. 3. The client treats event IDs and request IDs as **separate namespaces** and does not infer request liveness from event-cursor continuity. When condition 1 fails (log reset), the client cannot distinguish "empty replay window" from "lost events." When condition 2 fails (re-issue with new ID), the pending map is orphaned. When condition 3 fails (conflating namespaces), the client silently drops or double-applies. ## Decision Boundary On every stream (re)connect, the instance must decide: **re-correlate or trust the pending map?** The rule: - If the resume cursor `Last-Event-ID` is **strictly less than** the server's advertised current cursor and the replay window is non-empty → trust the replayed events, but **re-correlate**: any request ID seen in replay that is already in the pending map is a *duplicate* (drop the stale copy, keep the first); any request ID in the pending map that does **not** appear in replay and whose originating event ID is ≤ the resume cursor is **presumed dead** and must be failed fast, not left pending. - If the resume cursor is **greater than or equal to** the server's current cursor (the "empty window" case) → the client **cannot** conclude requests survived. It must issue a `ping`/`roots/list`-style liveness probe and treat all pending server→client requests older than the reconnect as **unconfirmed** until the probe returns. Unconfirmed requests must not block the task; they fail to a bounded default within a short deadline. - If the server returns a **new session ID** on reconnect (session resumption rejected) → the pending map is void; all outstanding requests fail immediately with a resumption-loss error. The boundary is the comparison of the client's resume cursor against the server's authoritative cursor. Without that comparison, "we reconnected" is not evidence that "our requests survived." ## Operational Effect Implementing the re-correlation rule converts a silent 41-second stall into a fast, attributable failure: orphaned `sampling/createMessage` calls fail within the probe deadline, the task either degrades gracefully or surfaces `CorrelationLostError` to the orchestrator, and the token budget is preserved. The double-application case is prevented by the duplicate-drop rule (first-seen wins on replayed request IDs). The cost is one extra liveness probe per reconnect and a durable event log on the server — the latter is the real architectural invariant: **a resumable stream is only resumable if its event-ID space outlives the process.** Clients that migrate to streamable HTTP without enforcing this on the server side are running a transport that *looks* resumable and *is not*. ```python import time from dataclasses import dataclass, field from typing import Dict, Optional class CorrelationLostError(RuntimeError): """Raised when pending server->client requests cannot be re-correlated after resume.""" pass @dataclass class PendingRequest: request_id: str origin_event_id: int issued_at: float confirmed: bool = False @dataclass class StreamSession: session_id: str last_event_id: int pending: Dict[str, PendingRequest] = field(default_factory=dict) def resume_stream( session: StreamSession, server_current_cursor: int, replayed_event_ids: Dict[int, str], # event_id -> request_id carried by that event server_session_id: Optional[str], probe_deadline_s: float = 2.0, ) -> StreamSession: now = time.time() # Session resumption rejected: pending map is void. if server_session_id is not None and server_session_id != session.session_id: for req in session.pending.values(): req.confirmed = False raise CorrelationLostError( f"session {session.session_id} not resumable; server issued {server_session_id}; " f"{len(session.pending)} pending requests orphaned" ) # Duplicate-drop: first-seen wins on replayed request IDs. seen_in_replay = set() for ev_id, req_id in replayed_event_ids.items(): if req_id in seen_in_replay: continue seen_in_replay.add(req_id) if req_id in session.pending: session.pending[req_id].confirmed = True # Empty-window case: cursor >= server cursor means replay proves nothing. empty_window = session.last_event_id >= server_current_cursor for req_id, req in list(session.pending.items()): if req_id in seen_in_replay: continue if empty_window: # Cannot infer liveness; unconfirmed until probe. req.confirmed = False if now - req.issued_at > probe_deadline_s: del session.pending[req_id] raise CorrelationLostError( f"request {req_id} unconfirmed after empty-window resume; " f"cursor {session.last_event_id} >= server {server_current_cursor}" ) elif req.origin_event_id <= session.last_event_id: # Origin event was before the resume cursor and did not replay: presumed dead. del session.pending[req_id] raise CorrelationLostError( f"request {req_id} (origin event {req.origin_event_id}) " f"presumed dead: not in replay window ending {session.last_event_id}" ) session.last_event_id = max(session.last_event_id, server_current_cursor) return session ```