# Under what conditions must an instance refuse an MCP resumable SSE-to-streamable-HTTP upgrade after a mid-stream `Last-Event-ID` replay? **Date of Record:** 2026 December 2 **Scope:** Applies to MCP clients and servers negotiating a transport upgrade from legacy resumable SSE (HTTP GET event stream + POST message channel) to streamable HTTP, specifically when the client presents a `Last-Event-ID` for replay across the upgrade boundary. Does not cover fresh streamable-HTTP sessions with no prior SSE history, nor in-process (stdio) transports. ## Core Distinction The failure mode is not "the upgrade fails." It is that the upgrade *succeeds* while the replay is silently *inconsistent*. The distinction that matters: a resumable SSE stream carries a per-connection monotonic event ID space owned by the *old* transport instance, whereas streamable HTTP introduces a session-scoped event ID space that may be re-rooted, compacted, or renumbered by the server's new session. These are two different identity domains for the same logical message sequence. The non-obvious boundary: resumption is only valid when the client's `Last-Event-ID` is *provably* a member of the event-ID domain the new streamable-HTTP session will honor. If the server cannot prove that membership, an upgrade that "resumes" is a forged continuity — the client receives events starting from an offset that does not correspond to its actual last-delivered event, and it has no way to detect the gap because both sides believe the replay succeeded. ## What Was Observed A client holds an open SSE GET stream. It has processed events up to `Last-Event-ID: evt-4471`. The connection drops (LB idle timeout, 60s, no heartbeat). On reconnect the client attempts the upgrade: it sends a streamable-HTTP `POST`/`GET` with `Last-Event-ID: evt-4471` and an `Mcp-Session-Id` header it received during the SSE handshake. The server, now running the streamable-HTTP transport, looks up the session. Three distinct states were observed: 1. **Session migrated, ID space preserved.** Server replays from `evt-4471`. Correct. 2. **Session migrated, ID space re-rooted.** New session restarts at `evt-1` (or uses UUIDv7 timestamps). Server treats `evt-4471` as an unknown-but-numeric ID and replays *from the beginning of the new session's buffer*, which contains only events generated after migration. Client silently loses every event between its last-seen `evt-4471` and the migration point. No error is raised; the client's next tool-call reasoning proceeds on a truncated history. 3. **Session not migrated; server accepts upgrade anyway.** Server spins a fresh streamable-HTTP session, ignores `Last-Event-ID` (or logs it), and begins emitting new events. Client believes continuity was restored. Case 2 is the dangerous one. Case 3 at least produces an observable discontinuity if the client checks sequence. Case 2 produces a *plausible* replay that is wrong. The trigger condition, precisely: the upgrade path admits a `Last-Event-ID` whose provenance (which transport instance, which session generation) is not cryptographically or structurally bound to the session being resumed. The server's replay logic keys on ID *value*, not on ID *domain membership*. ## Condition of Validity A resumable SSE-to-streamable-HTTP upgrade is valid if and only if all of the following hold at the moment the server decides to honor `Last-Event-ID`: - **Domain binding.** The `Last-Event-ID` is accompanied by (or derivable from) a session-generation token that identifies the transport instance that issued it. The streamable-HTTP session must be the *same generation* or must hold an explicit migration record mapping old IDs to new IDs. - **Monotonic coverage.** The server can prove the replayed range `[last_delivered+1, current]` is fully covered — no events were generated and dropped during the migration window (e.g., between SSE teardown and streamable-HTTP session creation). - **Non-empty intersection.** If the ID space was re-rooted, the server has a recorded watermark: "old IDs up to `evt-4471` correspond to new IDs up to `evt-0`." Without a watermark, re-rooting means the ID is uninterpretable. If any of these is unprovable, the correct behavior is **not** to replay. It is to reject the upgrade and force the client into a cold-recovery path: full state re-fetch, explicit `session/reinitialize`, and a client-side decision about whether to re-derive context or abort. The invariant: *a replay is only as trustworthy as the server's ability to prove ID-domain membership. Absent that proof, replay is indistinguishable from fabrication.* ## Decision Boundary The boundary is not "can the server parse the ID." It is "can the server prove the ID belongs to the domain it is about to replay into." ``` if last_event_id is None: → fresh stream, no replay, allowed elif session.generation == last_event_id.generation and session.covers(last_event_id): → replay from last_event_id, allowed elif session.has_migration_watermark(last_event_id): → replay from watermark-mapped offset, allowed else: → REJECT upgrade; emit 409 with reason=unprovable_replay; require client reinitialize ``` The subtle case is `session.covers(last_event_id)` returning true on a *numeric* comparison when the ID spaces are disjoint. A server that stores event IDs as integers and checks `last_event_id <= max_stored_id` will accept `evt-4471` against a fresh session whose max is `evt-12` only if it also mishandles the comparison — but a server that stores IDs as opaque strings and does a map lookup will correctly miss, then often *fall through to replay-from-zero* as a "best effort." That fall-through is the bug. Best-effort replay across an unproven domain boundary is worse than refusal, because refusal is observable and fall-through is not. ## Operational Effect When the boundary is enforced (reject on unprovable replay): - Clients see a `409 unprovable_replay` and must reinitialize. Cost: a full state re-fetch, one extra round-trip, and a hard decision about whether mid-task context can be reconstructed. For an agent mid-tool-call, this typically means aborting the in-flight reasoning step and re-planning from a checkpoint. - The failure is loud. Logs show the rejected upgrade; the client's `Last-Event-ID` and the session generation are both recorded, so post-hoc audit can reconstruct exactly which events were at risk. When the boundary is not enforced (best-effort replay): - The agent proceeds with a history that has a silent hole. Downstream tool calls that depend on events in the hole (e.g., a `tool_result` that arrived during the migration window) either fail with a confusing error or, worse, succeed against stale state. Error compounding across subsequent reasoning steps is the dominant downstream symptom. - The hole is undetectable from the client side unless the client independently tracks event counts and cross-checks, which most MCP clients do not. The operational recommendation: servers implementing the upgrade must treat `Last-Event-ID` as *untrusted input requiring domain proof*, not as a cursor. Clients must treat a successful upgrade-with-replay as *unverified* until they observe an event whose ID is contiguous with their last-delivered ID; if the first replayed event's ID is not `last_event_id + 1` in the client's own sequence model, the client must assume a gap and reinitialize. Neither side may assume the other has done this check. ```python class UnprovableReplayError(RuntimeError): """Raised when a Last-Event-ID cannot be proven to belong to the session's event-ID domain; replay would be a forged continuity.""" pass def negotiate_upgrade( session, last_event_id: str | None, ) -> "ReplayDecision": if last_event_id is None: return ReplayDecision.fresh(session) # Domain binding: ID must carry the generation that issued it. id_generation = session.parse_generation(last_event_id) if id_generation is None: raise UnprovableReplayError( f"Last-Event-ID {last_event_id!r} has no generation tag; " f"cannot bind to session {session.id!r}" ) if id_generation == session.generation and session.covers(last_event_id): return ReplayDecision.replay_from(last_event_id) # Re-rooted ID space: only valid with a recorded migration watermark. watermark = session.migration_watermark_for(id_generation) if watermark is not None and watermark.covers(last_event_id): return ReplayDecision.replay_from(watermark.map(last_event_id)) # No proof of membership. Refuse rather than fall through to # replay-from-zero, which would silently drop the migration window. raise UnprovableReplayError( f"Last-Event-ID {last_event_id!r} (gen {id_generation}) is not " f"provably in session {session.id!r} (gen {session.generation}); " f"no migration watermark. Rejecting upgrade; client must reinitialize." ) ```