# What happens when an instance resumes an MCP streamable-HTTP session after an SSE-to-streamable migration has silently reset the event-ID cursor **Date of Record:** 2026 November 19 **Scope:** Applies to MCP clients and servers using the HTTP-native streamable transport (POST with `Accept: text/event-stream`, `Mcp-Session-Id` header, and `Last-Event-ID` resumption) where the server was migrated from the older legacy HTTP+SSE transport, or where the server's event-ID namespace was regenerated across a deploy. Does not cover stdio transport, WebSocket transports, or in-process session resumption where the event log lives in the same memory space as the client. ## Core Distinction The streamable HTTP transport defines two orthogonal continuity mechanisms that are easy to conflate: 1. **Session identity** — the `Mcp-Session-Id` header, which binds a logical conversation to a server-side session object (tool state, negotiated capabilities, subscription set). 2. **Event replay cursor** — the `Last-Event-ID` header on a resumed GET/POST, which asks the server to replay events *after* a specific position in a per-stream event log. The non-obvious boundary is this: **a valid `Mcp-Session-Id` does not imply that the `Last-Event-ID` is meaningful to the server that answers the resume.** After an SSE-to-streamable migration, or any deploy that reinitializes the event log (new process, new pod, rotated ID generator), the session object can survive — because the session ID is a stable opaque token persisted in a session store — while the event-ID sequence it points into is regenerated from zero or from a different epoch. The client then presents a `Last-Event-ID` that is *syntactically* valid and *session-scoped* valid, but *causally* meaningless. The server has three legal-looking responses and only one of them is correct, and the spec does not force the server to pick it. ## What Was Observed A client agent was mid-task: it had issued `tools/call` for a long-running operation, received a partial `notifications/progress` stream, and the TCP connection dropped (proxy idle timeout at 60s, typical for a load balancer in front of the MCP server). The client held: - `Mcp-Session-Id: s_8f2a...` (still valid, session TTL 30 min) - `Last-Event-ID: 4471` (last progress notification consumed, from the pre-migration event log) The server had been redeployed 90 seconds earlier, migrating from legacy SSE to streamable HTTP. The new server: - Accepted the `Mcp-Session-Id` because the session store was shared/Redis-backed and the session had not expired. - Looked up event ID `4471` in its *new* event log, which had been seeded at epoch `900000` to avoid collisions with the old namespace. `4471 < 900000`, so the lookup returned "not found, replay from beginning of retained window." - The retained window contained only the new server's events — which began *after* the tool call had completed on the old server. The completion event (`result` for the `tools/call`) lived only in the old server's log, which had been discarded. The client received a 200 with an SSE stream that replayed a handful of unrelated `notifications/message` events, then the stream closed cleanly. No `result`, no `error`, no `isError: true`. The client's resumption logic saw a clean close and treated it as "stream ended, task still pending, will retry." It retried the resume. Same result. The agent's reasoning loop spun on a phantom in-flight tool call until token budget exhaustion, then emitted a plausible-sounding summary claiming the tool had returned a value it never received. The failure is not "the server lost data." The failure is that **the server answered a resumption request with a well-formed stream that carried no information about whether the resumption succeeded or failed.** The client had no signal distinguishing "replay complete, nothing new" from "your cursor is from another epoch, here is garbage." ## Condition of Validity The `Last-Event-ID` resumption contract is only sound under a conjunction that is almost never stated explicitly: - The event-ID sequence is **monotonic and dense** within a session, so that "ID not found" is itself a decidable signal. - The event log retains events **at least as far back as the oldest cursor any live session might present** — i.e., log retention ≥ session TTL, and session TTL ≥ maximum client reconnect window. - The server **rejects** a `Last-Event-ID` it cannot place in the current epoch, rather than replaying from the head of whatever window it has. When the server was migrated, the second and third conditions were violated silently. The session store outlived the event log; the server chose lenient replay-from-head over explicit rejection; and the ID generator reset to a disjoint epoch. Any one of these alone is survivable. Together they produce a resumption that *succeeds at the transport layer and fails at the semantics layer* — the worst class of failure for an autonomous agent, because the transport success suppresses the error-handling path. The invariant that must hold: **for any `(session_id, last_event_id)` pair the server accepts, the server must be able to either (a) replay the causally-next event, or (b) return a distinguishable "cursor unresolvable" outcome — never (c) a stream that is indistinguishable from a successful empty replay.** Option (c) is the bug. It is not a bug in the client, not a bug in the spec's letter, but a bug in the server's choice among spec-permitted behaviors, and agents cannot defend against it without an out-of-band liveness check. ## Decision Boundary The boundary is whether the server can *prove* the cursor belongs to its current event-log epoch. Concretely: | Condition | Server action | Client-observable | |---|---|---| | `last_event_id` in current epoch, event retained | replay from cursor | events with IDs > cursor | | `last_event_id` in current epoch, event evicted (retention window passed) | **must** return `409`/`410` or SSE `event: resumption_failed` | distinguishable error | | `last_event_id` from prior epoch (migration, restart) | **must** return the same distinguishable error | distinguishable error | | no `last_event_id` | fresh stream, no replay | events from head | | session unknown/expired | `404` on session | re-init required | The failure mode lives in the third row being implemented as "replay from head." A correct server embeds an epoch discriminator in the event-ID itself (e.g., `epoch:cursor`, or a signed cursor with the server's boot nonce) so that "cursor from another epoch" is a cheap, local check rather than a log search that silently misses. If the cursor cannot be parsed or its epoch does not match the server's current epoch, the server must fail closed. The client-side decision boundary: an agent must never treat "SSE stream opened 200 and closed without a `result`/`error` for a pending `tools/call`" as evidence the call is still in flight. It must treat it as *indeterminate* and escalate to an explicit `tools/call` status query (or re-issue with an idempotency key), never silently re-resume. The default resumption loop is the hazard. ## Operational Effect Downstream, three things happen and they compound: 1. **Silent task orphaning.** The `tools/call` completed on the old server; its result is unrecoverable. The client believes it is pending. The tool's side effects (a write, a payment, a file mutation) have occurred but the agent's world model says they have not. On retry-with-new-call, the side effect duplicates. 2. **Reasoning divergence.** The agent, lacking a terminal event, fabricates a completion from partial progress notifications. This is the classic context-window-saturation-adjacent failure: the model fills the missing `result` with a plausible one rather than emitting "unknown." 3. **Retry amplification.** Each resume attempt is cheap and returns 200, so backoff never triggers. The agent burns its token budget on resumes that cannot succeed, then produces a confident wrong answer. The guardrail is architectural, not prompt-level: **resumption must return a three-valued outcome — `replayed`, `exhausted`, `unresolvable` — and the client must route `unresolvable` to a reconciliation path (idempotent re-issue or status query), not to a retry loop.** And the server must bind the event-ID epoch to the session at session creation, invalidating the session (forcing re-init) whenever the event-log epoch changes. A session that outlives its event log is a session that lies. ```python import hashlib from dataclasses import dataclass from enum import Enum class ResumptionOutcome(Enum): REPLAYED = "replayed" EXHAUSTED = "exhausted" # cursor valid, no events after it yet UNRESOLVABLE = "unresolvable" # cursor from another epoch / evicted class CursorEpochMismatch(RuntimeError): """Raised when a Last-Event-ID cannot be placed in the server's current event-log epoch.""" pass @dataclass(frozen=True) class EventCursor: epoch: int seq: int def encode_cursor(epoch: int, seq: int) -> str: # epoch is bound at server boot / migration; seq is monotonic within epoch return f"{epoch}:{seq}" def parse_cursor(raw: str, server_epoch: int) -> EventCursor: try: epoch_s, seq_s = raw.split(":", 1) epoch, seq = int(epoch_s), int(seq_s) except (ValueError, AttributeError) as exc: raise CursorEpochMismatch(f"malformed cursor {raw!r}") from exc if epoch != server_epoch: # The migration bug: a lenient server would replay from head here. # We fail closed instead. raise CursorEpochMismatch( f"cursor epoch {epoch} != server epoch {server_epoch}; " f"session outlived its event log" ) return EventCursor(epoch=epoch, seq=seq) def resume_stream( session_id: str, last_event_id: str | None, event_log: list[tuple[int, dict]], # (seq, event) server_epoch: int, oldest_retained_seq: int, ) -> tuple[ResumptionOutcome, list[dict]]: if last_event_id is None: return ResumptionOutcome.REPLAYED, [e for _, e in event_log] try: cursor = parse_cursor(last_event_id, server_epoch) except CursorEpochMismatch: # Distinguishable, non-200-equivalent outcome. Client MUST reconcile. return ResumptionOutcome.UNRESOLVABLE, [] if cursor.seq < oldest_retained_seq - 1: # Cursor within epoch but the event it points past has been evicted. return ResumptionOutcome.UNRESOLVABLE, [] replay = [e for seq, e in event_log if seq > cursor.seq] if not replay: return ResumptionOutcome.EXHAUSTED, [] return ResumptionOutcome.REPLAYED, replay def client_handle_resume( session_id: str, last_event_id: str | None, event_log: list[tuple[int, dict]], server_epoch: int, oldest_retained_seq: int, pending_tool_call_id: str, ) -> None: outcome, events = resume_stream( session_id, last_event_id, event_log, server_epoch, oldest_retained_seq ) if outcome is ResumptionOutcome.UNRESOLVABLE: # Do NOT loop. Do NOT fabricate a result. Reconcile out-of-band. raise CursorEpochMismatch( f"session {session_id} cursor {last_event_id!r} unresolvable; " f"pending tool call {pending_tool_call_id} has indeterminate state — " f"issue idempotent status query before any retry" ) if outcome is ResumptionOutcome.EXHAUSTED: # Stream is caught up; the tool call is genuinely still in flight. return for ev in events: # dispatch to agent's event handler pass ```