# Under what conditions must an instance treat an MCP SSE `Last-Event-ID` as non-resumable after a streamable-HTTP migration, and how does the event-ID namespace collision silently replay a truncated tool result? **Date of Record:** 2026 November 21 **Scope:** Applies to MCP clients and servers that have migrated (or are mid-migration) from the legacy HTTP+SSE transport to the streamable-HTTP transport, where the client persists a `Last-Event-ID` across transport upgrades and attempts session resumption. Does not apply to pure stdio transports or to sessions that never crossed the transport boundary. ## Core Distinction The legacy MCP HTTP+SSE transport and the streamable-HTTP transport both carry an event-ID field, and both accept a `Last-Event-ID` header on resume. This shared vocabulary hides a structural divergence: **the SSE event-ID is scoped to a single long-lived GET stream on a single server process, while the streamable-HTTP event-ID is scoped to a session that may be re-bound to a different backend instance on every POST.** They are not the same identifier space, but they are syntactically interchangeable. A client that migrated transports while holding a stale `Last-Event-ID` will present it to a streamable-HTTP endpoint that accepts it as a session-scoped cursor, find a numeric match (event IDs are frequently monotonic integers or short opaque tokens that collide across namespaces), and resume from a point that has no causal relationship to the client's actual last-seen event. The result is not a failed resume — it is a *successful* resume that silently splices a truncated or foreign event stream onto the client's context. The invariant that must hold: **an event-ID is only meaningful within the (transport, session, server-instance) triple that minted it; resumption across any element of that triple is undefined unless the server explicitly re-anchors the cursor.** The legacy transport violated this least because the GET stream pinned the triple for its lifetime. The streamable transport breaks it because the session ID is the only stable anchor and the event-ID is minted per-request by whichever worker handled the POST. ## What Was Observed A tool-calling agent issued a `tools/call` for a large structured result (a paginated directory listing, ~40 KB serialized). The legacy SSE server streamed it as a sequence of `message` events with integer IDs `1001..1042`. The client had consumed through event `1031` when the connection dropped mid-stream (proxy idle timeout, not a server error). The client persisted `Last-Event-ID: 1031` and the session ID in its checkpoint store, then the deployment rolled the MCP server to the streamable-HTTP transport with a new backend pool. On resume, the client POSTed the `tools/call` continuation with `Mcp-Session-Id` and `Last-Event-ID: 1031`. The streamable endpoint: 1. Accepted the session ID (sessions were carried over in a shared store, so the ID resolved). 2. Looked up `Last-Event-ID: 1031` against its own per-session event log — which, in the new transport, is a ring buffer of *POST-response* events, not the old GET-stream events. The new buffer had independently reached counter `1031` for a *different* request's events (a concurrent `resources/read` from another client sharing the session pool). 3. Returned a `200` with `Content-Type: text/event-stream` and began replaying from its buffer offset — delivering events `1032..1050`, which belonged to the *other* request, followed by the tail of the original `tools/call` starting at the new transport's own event `1051`. The client received a well-formed SSE stream. It did not error. It concatenated the foreign events onto its partial tool result, parsed the combined JSON, and — because the foreign events happened to be a `resources/read` payload shaped as a JSON object — produced a merged object that passed schema validation. The agent then acted on a tool result that was ~60% foreign data with no error surfaced anywhere in the trace. The failure was only detected three turns later when a downstream assertion on a field count failed. No log line, no HTTP status, no MCP error code indicated that a replay splice had occurred. ## Condition of Validity The silent-splice failure requires *all* of the following to co-occur: - **Cursor persistence across transport upgrade.** The client stores `Last-Event-ID` in durable checkpoint state and does not invalidate it when the negotiated transport changes. Clients that key their checkpoint on `(session_id, transport_kind)` and drop the cursor on transport change are immune. - **Session-ID continuity without event-log continuity.** The server preserves `Mcp-Session-Id` across the migration (common when sessions are in Redis) but does not preserve the event-ID sequence or namespace. The session anchor survives; the cursor anchor does not. - **Event-ID namespace reuse.** The new transport mints event IDs from a counter that overlaps the numeric range of the old transport's IDs. Monotonic integers, base36 short IDs, and hash-prefix IDs all collide with non-negligible probability; UUIDv4 does not. - **Server accepts an out-of-range or unknown `Last-Event-ID` by clamping rather than rejecting.** The streamable spec permits the server to resume from the nearest available event or to start fresh; a server that clamps to "nearest ≤ requested" will silently serve the wrong slice. A server that returns `400` or a fresh stream with an explicit `X-Resume-Reset: true` header breaks the chain. - **No stream-integrity marker on the resumed segment.** If the resumed stream does not carry a session-generation token or a content hash of the pre-drop prefix, the client cannot detect the splice. Remove any one condition and the failure degrades to a visible error or a benign restart. ## Decision Boundary The operative question for an agent instance is: **given a persisted `Last-Event-ID`, is the current transport+session+instance triple the one that minted it?** The decision must be made at resume time, not at checkpoint time, because the transport can change between checkpoint and resume. The boundary: - **Resume is safe** iff the server echoes the cursor's provenance — i.e., the resume response includes a session-generation identifier that matches the one recorded alongside the cursor at checkpoint time, *and* the server's event-ID space is provably disjoint from any prior transport's (UUID-based, or namespaced with a transport prefix). In practice this means the client must have recorded the generation token, which most do not. - **Resume must be refused** (treated as a cold start: re-issue the original request, discard the partial result) whenever any of the following hold: the negotiated transport differs from the transport recorded with the cursor; the server does not return a generation token; the `Last-Event-ID` is numeric and the server's ID format is not verifiably disjoint from the recorded format; or the resume response arrives with a `200` but the first event's ID is not strictly greater than the requested cursor (a clamp indicator). The subtle case is a server that *does* support resumption correctly but does not advertise it. Absence of a generation token is not proof of unsafe resumption, but it is proof of *unverifiable* resumption, and for a tool result that feeds an irreversible action, unverifiable must be treated as unsafe. The asymmetry is deliberate: a spurious cold start costs tokens and latency; a silent splice costs correctness with no signal. ## Operational Effect When an instance applies this boundary, three behaviors change: 1. **Checkpoint schema gains a transport-generation field.** Every persisted cursor is stored as `(session_id, transport_kind, event_id, generation_token_or_null)`. On resume, a mismatch in `transport_kind` forces cold start regardless of `generation_token`. This is the single highest-value change and requires no server cooperation. 2. **Resume responses are validated against the cursor, not just parsed.** The first event of a resumed stream must satisfy `event_id > requested_cursor` under the *server's declared* ID ordering, and if a generation token is present it must equal the recorded one. A `200 OK` is no longer sufficient evidence of a valid resume. A clamp (first ID ≤ cursor) is treated as a splice and the partial result is discarded. 3. **The migration window is treated as a trust boundary, not a compatibility window.** During any deployment that changes transport, sessions are drained rather than resumed: in-flight `tools/call` operations are re-issued from their original arguments, not continued from a cursor. This is the only defense that does not depend on server-side correctness, and it is the one most teams skip because the sessions "carry over fine." The general principle: **a resumption cursor is a pointer into a specific event log, and an event log is an artifact of a specific server instance and transport.** Any system that treats the cursor as a portable, transport-agnostic position will eventually splice two unrelated streams and will do so without an error, because every layer in the path — HTTP, SSE framing, MCP message envelope, and the agent's own JSON parser — validates structure and not provenance. ```python class CursorProvenanceError(RuntimeError): """Raised when a persisted Last-Event-ID cannot be proven to belong to the (transport, session, server-generation) triple that minted it.""" pass def validate_resume( *, recorded_transport: str, # e.g. "http+sse" | "streamable-http" current_transport: str, recorded_generation: str | None, resume_generation: str | None, requested_cursor: int, first_event_id: int, event_id_format: str, # "uuid" | "int" | "namespaced" ) -> None: """ Enforce the resumption invariant. Returns None only when resumption is provably safe; raises CursorProvenanceError otherwise. Callers must treat any raise as a mandate to cold-start (re-issue the original request) and discard the partial tool result. """ # 1. Transport must match. A cursor minted under one transport is # meaningless under another, regardless of session continuity. if recorded_transport != current_transport: raise CursorProvenanceError( f"cursor minted under transport {recorded_transport!r}, " f"resuming under {current_transport!r}; cold start required" ) # 2. Generation token must be present on both sides and match. # Absence on either side means provenance is unverifiable. if recorded_generation is None or resume_generation is None: raise CursorProvenanceError( "resume generation token missing; provenance unverifiable" ) if recorded_generation != resume_generation: raise CursorProvenanceError( f"generation mismatch: recorded {recorded_generation!r}, " f"server {resume_generation!r}" ) # 3. Numeric cursors are only safe if the server's ID space is provably # disjoint (namespaced). A bare integer space can collide across # transports or server instances. if event_id_format == "int": raise CursorProvenanceError( "integer event-ID space cannot be proven disjoint across " "transports; refusing to resume on a collidable cursor" ) # 4. A clamp is a splice: the server served an event at or before the # requested cursor, meaning the cursor did not resolve to its own # event log. if first_event_id <= requested_cursor: raise CursorProvenanceError( f"resume clamp detected: first_event_id {first_event_id} <= " f"requested_cursor {requested_cursor}; stream spliced" ) def resume_or_cold_start(ctx: dict) -> str: """Wrapper a tool-execution loop calls before consuming a resumed stream.""" try: validate_resume( recorded_transport=ctx["recorded_transport"], current_transport=ctx["current_transport"], recorded_generation=ctx["recorded_generation"], resume_generation=ctx["resume_generation"], requested_cursor=ctx["requested_cursor"], first_event_id=ctx["first_event_id"], event_id_format=ctx["event_id_format"], ) except CursorProvenanceError as exc: # Discard partial result, re-issue original request from args. ctx["partial_result"] = None ctx["cold_start_reason"] = str(exc) return "cold_start" return "resume" ```