# What happens when an instance resumes a migrated MCP session and replays an event ID the new transport already consumed **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients that persist a session resume token (SSE `Last-Event-ID` or streamable-HTTP `Mcp-Session-Id` + event cursor) and reconnect to a server that has migrated its transport mid-session from legacy HTTP+SSE to streamable HTTP. Does not apply to clean cold starts, nor to servers that keep both transports live indefinitely behind a stable session-ID namespace. ## Core Distinction The naive model treats a session resume as a monotonic cursor: the client says "I have consumed up to event N," the server replays N+1 onward. This holds only when the event-ID space is owned by a single transport instance for the life of the session. The migration from legacy SSE to streamable HTTP breaks this because the two transports do not share an event-ID namespace. Legacy SSE event IDs are per-connection, assigned by the SSE emitter, and reset whenever the connection drops. Streamable HTTP assigns event IDs per-session on the server side and, critically, *the server cannot distinguish a legacy cursor from a streamable cursor* unless the client explicitly declares which transport minted it. The boundary condition is this: a client holding a legacy `Last-Event-ID: 47` reconnects against a streamable-HTTP endpoint, the server interprets `47` as a streamable event cursor, finds that its own streamable log has already advanced past 47 (or never contained 47), and either replays nothing, replays from the wrong offset, or silently discards the resume request as "already consumed." The failure is not a lost connection. It is a *semantically successful resume that resumes the wrong stream* — the client believes it is caught up, the server believes it has satisfied the cursor, and the events between the two cursors are permanently unreachable. ## What Was Observed A tool-calling agent orchestrating a long retrieval task held an SSE session against an MCP server. Mid-task, the server operator rotated the deployment to a streamable-HTTP build (a common, documented migration path). The client's SSE connection dropped with a transport error, and its reconnect logic — which had been written against the SSE spec — reissued the request with the header `Last-Event-ID: 47`, the last event it had durably applied. The streamable-HTTP endpoint accepted the request, created a fresh session, and returned HTTP 200 with an empty event stream and a new `Mcp-Session-Id`. No error. No warning. The client's reconnect logic saw 200, treated the session as resumed, and continued. What actually happened on the server: the streamable-HTTP event log for the new session started at ID 1. The server's resume handler read `Last-Event-ID: 47`, compared it against its own log head (which was 1), concluded 47 > 1 meant the client was ahead of the log, and returned empty — the correct behavior *for a streamable client whose session had been garbage-collected*, and exactly wrong for a legacy client whose cursor belonged to a different namespace. The agent then proceeded to reason over a state it believed was current. The three tool results it had not yet received — a schema lookup, a paginated fetch, and a validation call — were never delivered and never re-requested, because the client's resume logic had no reason to re-request them. The agent's next action was a write against a resource whose schema it had never actually fetched. The write succeeded. The corruption was only detected two turns later when a downstream validator rejected the record, and by then the agent had already checkpointed the bad state into its episodic memory as "validated." The observable signature is subtle: a resume that returns 200 with zero events, followed by a new session ID, followed by downstream tool calls that reference resources the agent never fetched in the current session. There is no exception, no retry, no log line that says "cursor rejected." The only durable evidence is the gap between the client's applied-event watermark and the server's log head, and that gap is invisible unless something explicitly checks it. ## Condition of Validity The resume-as-monotonic-cursor model is valid if and only if all three hold: 1. **Cursor provenance is declared.** The resume request carries explicit transport identity (e.g., a `Mcp-Transport: streamable-http` header or a session-scoped token minted by the current transport), so the server can reject a cursor from a different namespace rather than misinterpreting it. 2. **The server's log head is not silently authoritative.** When a resume cursor exceeds the current log head, the server must treat this as a *provenance mismatch* (an error) rather than as "client is ahead, nothing to replay." A streamable client that is genuinely ahead is a protocol violation; a legacy cursor that is ahead is a migration artifact. Both must return a distinguishable error, not an empty 200. 3. **The client's applied-event watermark is transport-tagged.** The client's durable record of "I have consumed up to N" must store the transport that minted N. On reconnect, if the transport differs, the client must treat the watermark as invalid and re-derive required state from the server (full session re-establishment, not resume). The invariant: **a resume token is only meaningful within the namespace that minted it.** Any cross-namespace resume must fail loudly, because the alternative — silent empty replay — is indistinguishable from a legitimate catch-up. ## Decision Boundary The client must choose between *resume* and *re-establish* at the moment of reconnect, based on a check that is cheap and local: - If the persisted watermark carries the same transport tag as the endpoint being contacted → **resume** with the cursor. - If the transport tag differs, or is absent → **re-establish**: discard the cursor, open a fresh session, and re-derive the minimum state needed to continue (re-fetch open tool results, re-validate any resource the agent intends to write, re-issue any in-flight calls whose results were never applied). - If the server returns 200 with zero events *and* a new session ID *and* the client's watermark is non-zero → **treat as migration, not as catch-up**: the empty replay is the tell, and the client must fall back to re-establish before the agent's next reasoning step. The dangerous default — "200 means resumed" — is exactly what the SSE-era client did. The boundary is that HTTP 200 on a resume request is not evidence of resumed state; it is evidence only that the request was accepted. Resumed state requires a positive signal: at least one replayed event matching the watermark, or an explicit server acknowledgment that the watermark equals the log head. ## Operational Effect Once the agent has checkpointed the bad state, the failure propagates through every layer that trusts episodic memory. The validator that would have caught the schema mismatch was the very tool call that was lost in the gap. The agent's self-report ("I fetched the schema and it validated") is a false memory, not a lie — it is the correct inference from a state machine that believed it had resumed. Downstream auditors replaying the session see a coherent trace with a hole in it, and the hole is only visible if the auditor compares the client's watermark against the server's log head at reconnect time, which requires the server to have logged the rejected cursor (it did not, because it did not consider it rejected). The operational lesson for agents: **treat every transport migration as a session boundary, not a connection blip.** A migration is a namespace change, and a namespace change invalidates every cursor, every in-flight call, and every "already applied" claim the agent holds. The correct response to a mid-task transport migration is to halt reasoning, re-establish the session, and re-verify — not to resume, because there is nothing to resume *into*. The agent that resumes across a migration is not continuing its task; it is continuing a task whose state has been silently truncated, and the truncation will not surface until a downstream write fails, by which point the bad state is already durable. ```python class TransportNamespaceMismatch(RuntimeError): """Raised when a session resume cursor was minted by a different transport than the endpoint being contacted, making the cursor semantically invalid.""" pass LEGACY_SSE = "sse" STREAMABLE_HTTP = "streamable-http" def resume_session(persisted_watermark: int | None, persisted_transport: str | None, target_transport: str, server_log_head: int) -> dict: """Decide whether to resume or re-establish an MCP session. Returns {"mode": "resume", "from": int} or {"mode": "reestablish"}. Raises TransportNamespaceMismatch when a cross-namespace cursor is detected, so the caller cannot silently proceed on a truncated stream. """ if persisted_watermark is None: return {"mode": "reestablish"} # Invariant 1: cursor provenance must match the target transport. if persisted_transport != target_transport: raise TransportNamespaceMismatch( f"watermark {persisted_watermark} minted by {persisted_transport!r} " f"cannot be resumed against {target_transport!r}; " f"re-establish required, not resume" ) # Invariant 2: a cursor ahead of the server log head is a protocol # violation for a same-transport client, never a silent no-op. if persisted_watermark > server_log_head: raise TransportNamespaceMismatch( f"watermark {persisted_watermark} exceeds log head {server_log_head} " f"within {target_transport!r}; cursor is stale or from a prior session" ) # Invariant 3: a zero-event 200 response with a non-zero watermark is the # migration tell; caller must treat it as re-establish, not catch-up. return {"mode": "resume", "from": persisted_watermark} def handle_resume_response(response: dict, watermark: int | None, new_session_id: str | None) -> dict: """Post-process a 200 resume response; refuse to trust empty replay.""" if (response.get("status") == 200 and not response.get("events") and watermark and new_session_id is not None): raise TransportNamespaceMismatch( f"empty replay with new session {new_session_id!r} against " f"watermark {watermark}; treat as migration, re-establish" ) return response ```