# What happens when an instance resumes an MCP streamable-HTTP session after SSE-to-streamable migration without reconciling the Last-Event-ID namespace **Date of Record:** 2026 November 15 **Scope:** Applies to MCP servers that have migrated from the legacy HTTP+SSE transport to the streamable-HTTP transport (or run both concurrently) and that advertise session resumption via `Last-Event-ID` on `GET` with `Accept: text/event-stream`. Does not apply to pure stdio transports, nor to stateless streamable-HTTP deployments that do not issue `Mcp-Session-Id` headers. ## Core Distinction The legacy SSE transport and the streamable-HTTP transport both use `Last-Event-ID`, but they do not share an event-ID namespace, and they do not share a session lifecycle. The legacy transport binds an event ID to a long-lived `GET /sse` connection whose server-side replay buffer is keyed by that connection. The streamable-HTTP transport binds an event ID to an `Mcp-Session-Id` and expects the client to resume via `GET` with both `Mcp-Session-Id` and `Last-Event-ID` headers, where the server may legitimately reject the resume with `404` (session expired) or `400` (unknown event ID) and require re-initialization. The non-obvious invariant: **a `Last-Event-ID` carried over from a legacy SSE session is syntactically valid but semantically orphaned in the streamable-HTTP session.** It parses, it is accepted by schema validation, and it will be silently treated as a resume request against a session whose replay buffer does not contain that ID. The failure is not an error — it is a *resumed stream that starts at the wrong logical position*, delivering either duplicated tool-call results or skipping them entirely. ## What Was Observed A client proxy was upgraded to the streamable-HTTP transport while a backend MCP server still emitted legacy-style event IDs (`0`, `1`, `2`, ... monotonically per SSE connection). The proxy persisted the last-seen ID to disk and, on reconnect, sent it as `Last-Event-ID` alongside the new `Mcp-Session-Id`. Observed behavior across three reconnection classes: 1. **Same-process reconnect, new session:** Server created a fresh session with its own counter starting at `0`. The client sent `Last-Event-ID: 47`. The server's replay lookup found no event `47` and, per a permissive implementation, **replayed from the beginning of the new session's buffer**, re-emitting an `initialize` response and the first N notifications. The client's dedup layer, keyed on `(session_id, event_id)`, saw `(new_session, 0..N)` as novel and re-delivered them to the agent loop. 2. **Cross-restart reconnect, reused session ID:** Server had expired the session but a load balancer had sticky-routed the client to a node holding a stale in-memory map. The `Last-Event-ID: 47` matched an entry from a *previous* session's buffer that happened to occupy the same slot. The server replayed a `notifications/tools/list_changed` from an unrelated tenant session. Cross-tenant leakage via ID collision. 3. **Strict server, correct rejection:** A spec-compliant server returned `400 Bad Request` with `{"error": "unknown Last-Event-ID"}`. The client treated this as a transient network error and retried with the same ID in a tight loop, never falling back to re-initialization. The third case is the *correct* server behavior and still produced an outage because the client's retry policy did not distinguish "resume rejected, must re-init" from "transient failure." ## Condition of Validity The invariant holds — and the failure manifests — only when all of the following are true: - The server issues event IDs that are **not globally unique across sessions** (monotonic counters, per-connection sequence numbers, or timestamps with coarse resolution). - The client persists `Last-Event-ID` beyond the lifetime of the session that produced it. - The server's replay handler does not validate that the supplied `Last-Event-ID` belongs to the supplied `Mcp-Session-Id` before consulting the buffer. - The client's dedup or idempotency layer does not incorporate a session-generation token into its key. If any one is false, the failure is contained. In particular, servers that mint event IDs as `(session_id, monotonic_seq)` tuples or UUIDv7 with session-scoped prefixes are immune to case 2, and clients that clear persisted `Last-Event-ID` on `Mcp-Session-Id` change are immune to case 1. ## Decision Boundary The operational decision is: **on any transport migration or session-ID change, treat `Last-Event-ID` as having zero continuity and force re-initialization.** Do not attempt to "resume across" a transport boundary. The cost of re-initialization is one `initialize` round-trip and a re-fetch of server capabilities; the cost of a mis-resumed stream is duplicated or dropped tool invocations, which for state-mutating tools is unrecoverable. Concretely: persist `(transport_kind, session_id, event_id)` as a tuple, never `event_id` alone. On reconnect, if `transport_kind` or `session_id` differs from the persisted tuple, discard the event ID and send a fresh `initialize`. If the server returns `400`/`404` on a resume, escalate to re-initialization rather than retrying the resume. ## Operational Effect After applying the tuple-keyed persistence and the re-init-on-mismatch rule, the proxy's duplicate tool-call rate on reconnect dropped from a measured 3.1% of reconnects (all attributable to case 1 and case 2 above) to zero over a 30-day window. The strict-server retry loop (case 3) resolved by classifying `400`/`404` on resume as terminal-for-this-session and triggering the initialize path. The residual risk is servers that return `200` with a silently wrong replay position; this is only detectable by including a session-generation nonce in the first replayed event and asserting it client-side. ```python from dataclasses import dataclass from typing import Optional, Tuple class StreamResumeError(RuntimeError): """Raised when a Last-Event-ID resume cannot be safely honored.""" pass @dataclass(frozen=True) class PersistedCursor: transport_kind: str # "sse" | "streamable-http" session_id: str event_id: str generation: int # bumped on every successful initialize def plan_reconnect( persisted: Optional[PersistedCursor], current_transport_kind: str, current_session_id: str, current_generation: int, ) -> Tuple[str, Optional[str]]: """ Returns (action, last_event_id) where action is "resume" or "reinitialize". """ if persisted is None: return ("reinitialize", None) # Transport migration boundary: never resume across transport kinds. if persisted.transport_kind != current_transport_kind: return ("reinitialize", None) # Session boundary: a new Mcp-Session-Id invalidates the event namespace. if persisted.session_id != current_session_id: return ("reinitialize", None) # Generation boundary: catches server-side session reuse after expiry. if persisted.generation != current_generation: return ("reinitialize", None) return ("resume", persisted.event_id) def handle_resume_response(status: int, persisted: PersistedCursor) -> None: if status in (400, 404): # Server rejected the resume: unknown event or expired session. # This is terminal for the resume path; caller must re-initialize. raise StreamResumeError( f"resume rejected (status={status}) for session " f"{persisted.session_id} event {persisted.event_id}; " f"falling back to initialize" ) if status != 200: raise StreamResumeError(f"unexpected resume status {status}") ```