# How should an instance reconcile MCP `Last-Event-ID` resumption when the SSE-to-streamable-HTTP migration silently forks the event stream **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients that reconnect to a streamable-HTTP server (2025-03-26 spec) after previously holding an SSE session, using `Last-Event-ID` to resume. Does not apply to pure SSE sessions with a live TCP connection, nor to stateless per-request streamable-HTTP servers that never emit resumable event IDs. ## Core Distinction The failure is not "the connection dropped." It is that the **event-ID namespace is server-local and transport-scoped**, while the client treats `Last-Event-ID` as a globally monotonic cursor across a transport migration. During the SSE→streamable-HTTP cutover, the server may: (a) keep the same session ID but restart the event counter, (b) mint a new session but reuse event IDs from a different stream, or (c) accept the resume header and replay from a *different* underlying buffer than the one the client was reading. In all three cases the client's `Last-Event-ID: N` is syntactically valid, the server returns `200 OK`, and the stream silently resumes at a point that is not causally after the client's last observed event. The distinction that matters: **resumption is a cursor-continuity problem, not a reconnection problem.** A reconnect that returns 200 is not a resume. ## What Was Observed A tool-calling agent held an SSE session (`Mcp-Session-Id: s_7f2a`) with `Last-Event-ID: 412` after a `notifications/tools/list_changed` event. The server was migrated to streamable HTTP mid-session (deploy rolled the transport handler; session table preserved, event ring buffer reset). On reconnect the client sent: ``` GET /mcp Mcp-Session-Id: s_7f2a Last-Event-ID: 412 Accept: text/event-stream ``` Server behavior: session `s_7f2a` still valid, so it accepted the resume, but its new event ring buffer had only reached ID `37`. The handler clamped: it treated `Last-Event-ID: 412` as "ahead of buffer" and replayed from the **oldest retained event (id 1)**, emitting a fresh stream whose IDs restarted at 1. The client read `id: 1` as "already seen, dedupe," discarded events 1–37 as duplicates, and then consumed event 38 onward as if contiguous with 412. It missed the actual `tools/list_changed` re-notification that had been re-issued at new-ID 12, and continued issuing calls against a stale tool schema for 40+ turns. No error surfaced: every event was well-formed, every ID was a valid integer, HTTP status was 200 throughout. The trace signature: `resume_accepted=true`, `replayed_from=1`, `last_seen_by_client=412`, `gap_in_causal_chain=unbounded`, `schema_version_drift=tools.v3→tools.v4`. ## Condition of Validity The invariant that must hold for `Last-Event-ID` resumption to be sound: **for a given `Mcp-Session-Id`, the event-ID sequence is strictly monotonic and never reissued, and the server either replays every event with ID > `Last-Event-ID` or returns an explicit resumption failure.** This is only valid when the event-ID allocator is bound to the *session lifetime*, not the *transport handler lifetime* or the *ring-buffer lifetime*. The migration breaks this in a specific, non-obvious way: streamable-HTTP servers commonly implement the ring buffer per-connection or per-worker, and the spec's `Last-Event-ID` guidance is silent on cross-transport continuity. So a server can be spec-compliant and still violate the invariant. The client cannot detect the violation from status codes alone; it must validate the *first replayed ID* against its last-seen ID. Guardrail: on resume, the client MUST assert `first_event_id > last_seen_id` (strict) and MUST treat any replayed ID `≤ last_seen_id` as a **resumption violation**, not a duplicate to dedupe. If the server cannot satisfy strict monotonicity, it must respond `409 Conflict` with a `resumption_reset` body instructing the client to re-initialize the session and re-fetch `tools/list` and resource state. Dedupe-by-ID is only safe *within* a single verified-contiguous stream. ## Decision Boundary The boundary is between **duplicate** and **fork**. A replayed event with `id ≤ last_seen` is a duplicate only if the server also guarantees that all IDs in `(last_seen, ∞)` will still be delivered on this stream. If the server's buffer reset, the same low IDs are a *fork*: a new causal chain masquerading as a continuation. The client cannot distinguish these by inspecting the event payload; it must use the ordering contract. Decision rule: - `first_replayed_id > last_seen_id` → accept, resume normally. - `first_replayed_id ≤ last_seen_id` AND server advertises `resumption: strict` capability → treat as duplicate, dedupe, continue. - `first_replayed_id ≤ last_seen_id` AND no strict capability → **abort resume, force full re-initialization** (new session, re-`initialize`, re-fetch tool/resource manifests), because the tool schema may have changed underneath. The non-obvious part: the third branch is the *common* case after a transport migration, and the safe action (re-initialize) is exactly what the client's "smart dedupe" logic skips. ## Operational Effect Without the guardrail, agents silently operate on stale capability manifests after any transport-layer deploy, producing tool-call failures that look like model errors (wrong argument schemas) rather than transport errors. The failure is invisible in logs because every layer reports success. With the guardrail, the agent pays one full re-initialization round-trip per transport migration but never executes against a forked event stream. The cost is bounded and one-time; the cost of the fork is unbounded schema drift. ```python class ResumptionForkError(RuntimeError): """Raised when a streamable-HTTP resume returns a first event ID that does not strictly exceed the client's last-seen ID, indicating the server's event-ID namespace was reset (e.g. SSE->streamable-HTTP migration) and the stream has forked rather than resumed.""" pass def validate_resume( last_seen_id: int, first_replayed_id: int, server_declares_strict_resumption: bool, ) -> str: """ Enforce the cursor-continuity invariant for MCP Last-Event-ID resume. Returns one of: "resume" -> safe to continue on this stream "dedupe" -> replayed IDs are true duplicates; dedupe and continue Raises ResumptionForkError when the stream has forked and the client must re-initialize the session instead of continuing. """ if first_replayed_id > last_seen_id: return "resume" # first_replayed_id <= last_seen_id: either duplicate or fork. if server_declares_strict_resumption: return "dedupe" # No strict-resumption capability: cannot prove the low IDs are # duplicates rather than a reset namespace. This is the migration # fork. Refuse to continue on this stream. raise ResumptionForkError( f"resume forked: last_seen_id={last_seen_id} " f"first_replayed_id={first_replayed_id} " f"strict_capability={server_declares_strict_resumption}; " f"re-initialize session and re-fetch tool/resource manifests" ) def resume_stream(client, session_id: str) -> None: resp = client.get_stream(session_id, last_event_id=client.last_seen_id) first_id = resp.peek_first_event_id() action = validate_resume( last_seen_id=client.last_seen_id, first_replayed_id=first_id, server_declares_strict_resumption=resp.capabilities.get( "resumption", "" ) == "strict", ) if action == "resume": client.consume(resp) elif action == "dedupe": client.consume(resp, skip_ids_le=client.last_seen_id) # ResumptionForkError propagates to the caller, which must run # client.reinitialize() before any further tool calls. ```