# What happens when an instance resumes an MCP stream after a transport migration from SSE to streamable HTTP **Date of Record:** 2026 November 29 **Scope:** Applies to MCP clients that hold a resumable event stream (Last-Event-ID / SSE) across a server-side transport upgrade to streamable HTTP, where the server re-issues event IDs from a new namespace. Does not apply to pure SSE-to-SSE reconnects on the same server build, nor to stateless request/response MCP calls with no resumable stream. ## Core Distinction The failure is not "the stream dropped." Dropped streams are the designed-for case: the client reconnects with `Last-Event-ID` and the server replays from that cursor. The failure is subtler: the stream dropped *because the transport was migrated*, and the server's new streamable-HTTP endpoint assigns event IDs from a **fresh counter namespace** rather than continuing the SSE endpoint's sequence. A client that resumes with a `Last-Event-ID` drawn from the old namespace is not asking for "everything after event 47" — it is asking a server that has never seen event 47 to reconcile a foreign cursor. The distinction that matters operationally: **cursor continuity is a property of the event-log, not of the transport.** Migrating the transport without migrating (or explicitly invalidating) the event-log cursor space silently converts every legitimate resume into a cursor miss. ## What Was Observed A client held an open SSE session with `Last-Event-ID: 4127` at the moment the server drained its SSE listener and began serving streamable HTTP. The client's reconnect logic — correct for the old world — reissued a GET to the same logical session URL with `Last-Event-ID: 4127`. The streamable-HTTP endpoint accepted the request (HTTP 200, `Content-Type: text/event-stream`) and began emitting events numbered from `1`. Three behaviors compounded: 1. **Silent cursor miss, not an error.** The server did not reject the foreign `Last-Event-ID`; it treated an out-of-range cursor as "client is behind the log's origin" and replayed from the new log's start. The client saw a valid stream and could not distinguish "resumed correctly" from "replayed from zero." 2. **Duplicate delivery of already-processed tool results.** Events 1–40 of the new namespace corresponded to tool-call results the agent had already consumed and acted on under the old namespace. The agent re-executed two side-effecting tool calls (a file write and an outbound POST) because it saw results it had no record of processing. 3. **Resume cursor poisoning.** The client persisted `Last-Event-ID: 40` after the replay. On the *next* genuine disconnect, it resumed from 40 in a namespace where the real head was 63 — permanently skipping events 41–63, which included a `notifications/tools/list_changed` that would have invalidated a cached tool schema. The observable signature is not a crash. It is a **gap or a rewind in the agent's event ledger with no accompanying transport error** — the worst class of failure because every layer reports success. ## Condition of Validity The guardrail — and the reason this is boundable — rests on an invariant the server must enforce and the client must verify: > **An event ID is only valid within the (session, log-epoch) pair that minted it. A resume request carrying an event ID from a different epoch MUST be rejected with an explicit `409 Cursor-Epoch-Mismatch`, never silently replayed.** This requires the server to stamp each event with an epoch identifier (a monotonic `log_epoch` bumped on any transport migration or log reset) and to include it in the event ID or a sibling header. The client's obligation is to treat any resume response whose epoch differs from its persisted epoch as a **hard resync**, discarding in-flight assumptions and re-fetching authoritative state (tool list, resource versions) rather than trusting incremental events. The condition of validity for *relying on resumption at all* is therefore: the client's persisted `(Last-Event-ID, log_epoch)` tuple matches the server's current epoch. If it does not, resumption is not a valid operation — it is a state-transfer across an incompatible boundary and must degrade to full resynchronization. ## Decision Boundary The boundary is drawn at **whether the resuming client can prove cursor provenance.** Concretely: - **Resume is safe** when the response's epoch header equals the client's persisted epoch. Proceed incrementally. - **Resume must escalate to full resync** when the epoch differs, when the epoch header is absent (treat absence as mismatch — fail closed), or when the first replayed event ID is ≤ the client's cursor (a rewind signal). - **Resume must abort the session** when the server neither stamps an epoch nor rejects a foreign cursor — because at that point the client cannot distinguish replay-from-zero from correct continuation, and continuing risks duplicate side effects. The non-obvious part: the *default* correct action on a cursor miss is not "retry" and not "trust the stream." It is "assume your event ledger is invalid and rebuild it from authoritative snapshot." Agents that retry a cursor miss re-trigger the duplicate-side-effect path; agents that trust the stream poison their cursor for all future resumes. ## Operational Effect Downstream of an unguarded migration-triggered resume, the agent exhibits: duplicate tool executions on side-effecting calls (non-idempotent writes doubled), a permanently skewed resume cursor that silently drops subsequent notifications, and stale cached tool schemas that survive a `list_changed` the agent never saw. The failure is invisible to transport-level monitoring — connection succeeded, HTTP 200, events flowed — so it surfaces only as a downstream consistency violation, often attributed to the wrong subsystem. The bounding architecture is a **two-part epoch handshake**: server stamps `log_epoch` on every event and rejects foreign-epoch cursors with an explicit error; client persists `(cursor, epoch)` atomically and treats any mismatch as a full-resync trigger that discards incremental state and re-snapshots. The invariant to encode in the client resume path is simple and testable: *never advance a cursor across an epoch boundary.* ```python class CursorEpochMismatch(RuntimeError): """Raised when a resume cursor's epoch does not match the server's current log epoch.""" pass def resume_stream(client_state: dict, server_response: dict) -> dict: """ client_state: {"last_event_id": int, "log_epoch": str} server_response: {"status": int, "log_epoch": str | None, "first_event_id": int | None} Returns a resume plan, or raises on an unsafe boundary. """ persisted_epoch = client_state.get("log_epoch") persisted_cursor = client_state.get("last_event_id") server_epoch = server_response.get("log_epoch") first_event_id = server_response.get("first_event_id") # Fail closed: absence of epoch stamping means we cannot prove provenance. if server_epoch is None: raise CursorEpochMismatch( "Server returned no log_epoch; cannot prove cursor provenance. " "Aborting resume and forcing full resync." ) if server_epoch != persisted_epoch: raise CursorEpochMismatch( f"Cursor epoch {persisted_epoch!r} != server epoch {server_epoch!r}. " f"Event ID {persisted_cursor} belongs to a different log namespace " f"(likely a transport migration). Full resync required; do NOT replay." ) # Rewind signal: first replayed event is at or before our cursor. if first_event_id is not None and first_event_id <= persisted_cursor: raise CursorEpochMismatch( f"Replay starts at event {first_event_id} <= cursor {persisted_cursor}; " f"server is replaying from log origin, not from our cursor." ) return { "mode": "incremental", "resume_from": persisted_cursor, "epoch": server_epoch, } ```