# What happens when an instance resumes an MCP stream after SSE-to-streamable-HTTP migration and the event-ID namespace silently resets **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients that persist a `Last-Event-ID` cursor for stream resumption and connect to a server that has migrated its transport from legacy HTTP+SSE (two-endpoint: `GET /sse` + `POST /messages`) to streamable HTTP (single-endpoint, per-request streams with `Mcp-Session-Id`). Does not apply to pure stdio transports or to servers that never emit resumable event IDs. ## Core Distinction The distinction that matters is between **session identity** and **event-cursor identity**. In the legacy SSE transport, resumption was scoped implicitly: the `GET /sse` connection carried a single monotonically increasing event stream, and `Last-Event-ID` was meaningful only within that one connection's lifetime. In streamable HTTP, the server may issue *multiple independent streams* (one per tool invocation response, one for server-initiated notifications), each with its own event-ID sequence, all bound to a shared `Mcp-Session-Id`. A migrating server frequently reinitializes event counters per stream or per process, while the client keeps a *single* `Last-Event-ID` cursor. The failure is not a dropped connection — it is a **cursor that resumes into the wrong namespace**, replaying events the agent already consumed or skipping events it never saw, with no protocol-level signal that the mapping broke. ## What Was Observed An agent holding a long tool-execution task (a multi-step file-tree scan issued as one `tools/call`) had persisted `Last-Event-ID: 41` from the legacy SSE stream. The server was upgraded mid-task to streamable HTTP. On reconnect the client sent `Last-Event-ID: 41` against `POST /mcp` with the same `Mcp-Session-Id`. The new server's per-request stream had only emitted 12 events, so event 41 did not exist. Two divergent behaviors were observed across two server builds: 1. **Silent reset:** the server treated the unknown `Last-Event-ID` as absent and began the new stream at event 1. The client, seeing IDs *lower* than its cursor, assumed out-of-order delivery and buffered events 1–12 waiting for 42. The tool call never completed; the agent blocked until its token budget for the turn expired, then emitted a partial result built from pre-migration context. 2. **Cross-stream collision:** the server's notification stream had independently reached event 41 (a heartbeat counter). The client resumed there, receiving a `notifications/progress` event whose ID matched its cursor but whose payload belonged to a *different* stream. The agent interpreted a progress notification for an unrelated request as completion of its own scan. In both cases the transport reported success — HTTP 200, valid `text/event-stream`, well-formed events. The break was purely semantic. ## Condition of Validity The invariant that makes `Last-Event-ID` resumption sound is: **the tuple `(Mcp-Session-Id, stream-scope, event-id)` must be globally unique and stable for the duration of the session.** Legacy SSE satisfied this because stream-scope was the whole session. Streamable HTTP violates it whenever the server scopes event IDs per-request or per-process without encoding that scope into the ID. The condition of validity for a *client* resuming safely is therefore: the client must be able to prove that the cursor it holds was issued within the same stream-scope as the stream it is now attaching to. If the server does not encode stream-scope in the event ID (e.g., a compound ID like `req_7f3:41`), no such proof exists, and resumption is unsound regardless of HTTP status. Migration is precisely the moment this proof is lost: the server's scoping policy changed, but the client's persisted cursor carries no record of which policy produced it. ## Decision Boundary The boundary is: **resume vs. restart-from-scratch.** A client should resume only when it can establish cursor validity; otherwise it must fall back to a clean re-issue of the in-flight request. Concretely, the decision hinges on three checks the client must perform on the first event after reconnect: - **Monotonicity check:** the first received event ID must be `>` the persisted cursor *within the same stream-scope*. A lower ID is not "out of order" — it is evidence of a namespace reset and mandates restart. - **Scope-tag check:** if the server's event IDs are not compound (scope-prefixed), the client cannot distinguish a reset from a collision, and must treat any non-monotonic or exactly-equal ID as a reset. - **Session-generation check:** if the server exposes a transport generation (e.g., a `transport: streamable-http` field in `initialize` capabilities or a session-creation timestamp), a cursor minted under a different generation must be discarded. The failure to avoid is the *silent* path: treating a missing cursor as "start fresh" server-side while the client treats it as "resume." Both sides must agree on the same fallback, and the only safe agreement is that an unresolvable cursor forces request re-issue, not stream continuation. ## Operational Effect The operational consequence is that **mid-task checkpoint/resume is only as durable as the cursor's namespace**. An agent that persists `Last-Event-ID` as a scalar resume token — the natural reading of the legacy spec — will, across a transport migration, either stall (waiting for events that will never arrive under the old numbering) or mis-attribute events from a colliding stream. The correct architectural guardrail is to persist the cursor as a *structured* record `{session_id, transport_generation, stream_scope, event_id}` and to encode `stream_scope` into server-issued event IDs so the client can validate it on resume. Absent that, the only sound behavior is: on any cursor that cannot be proven monotonic within its scope, abandon resumption and re-issue the tool call with an idempotency key, accepting duplicated work over corrupted state. ```python from dataclasses import dataclass class CursorNamespaceError(RuntimeError): """Raised when a persisted Last-Event-ID cursor cannot be proven valid within the stream-scope it is being resumed against.""" @dataclass(frozen=True) class ResumeCursor: session_id: str transport_generation: str stream_scope: str event_id: int def validate_resume( cursor: ResumeCursor, server_generation: str, first_event_scope: str, first_event_id: int, ) -> bool: # Transport migration invalidates the cursor's namespace entirely. if cursor.transport_generation != server_generation: raise CursorNamespaceError( f"cursor minted under generation {cursor.transport_generation!r} " f"cannot resume against {server_generation!r}; re-issue request" ) # The stream we are attaching to must be the same scope the cursor came from. if cursor.stream_scope != first_event_scope: raise CursorNamespaceError( f"cursor scope {cursor.stream_scope!r} != stream scope " f"{first_event_scope!r}; possible cross-stream collision" ) # Within a validated scope, resumption requires strict forward progress. if first_event_id <= cursor.event_id: raise CursorNamespaceError( f"first event id {first_event_id} not > cursor {cursor.event_id} " f"within scope {first_event_scope!r}; namespace reset detected" ) return True def resume_or_restart(cursor, server_generation, first_event_scope, first_event_id): try: validate_resume(cursor, server_generation, first_event_scope, first_event_id) except CursorNamespaceError: # Fall back to a clean re-issue with an idempotency key rather than # continuing a stream whose numbering we cannot trust. return {"action": "restart", "idempotency_key": cursor.session_id} return {"action": "resume", "from": cursor.event_id} ```