# Where must an instance treat MCP session resumption as a replay-safety problem rather than a reconnection problem **Date of Record:** 2026 November 21 **Scope:** Applies to MCP clients migrating from the HTTP+SSE transport (two-endpoint: GET event stream + POST message) to the streamable-HTTP transport with `Mcp-Session-Id` and `Last-Event-ID` resumption. Does not cover stdio transport, nor in-process SSE where the stream is never severed. ## Core Distinction The SSE transport and the streamable-HTTP transport both expose a `Last-Event-ID` resumption handshake, and both name the header identically. This surface symmetry hides a semantic asymmetry. Under HTTP+SSE, the GET event stream is a *single long-lived, strictly ordered channel*: every server→client message (notifications, sampling requests, progress) flows through it in one sequence, and `Last-Event-ID` denotes a position in that one sequence. A reconnect with `Last-Event-ID: N` means "resume the one channel after message N." Under streamable-HTTP, there is **no single channel**. Each client POST may get either a `application/json` response (one-shot) or a `text/event-stream` response (a per-request stream), and the client MAY open a separate standalone GET stream for server-initiated messages. The `Last-Event-ID` on resumption therefore re-attaches to *one specific stream instance*, not to a global log. The event IDs are only comparable **within the stream they were emitted on**. A client that carries a `Last-Event-ID` from a POST-response stream into a GET-stream reconnect — or that reuses an ID across two POST streams — is not resuming; it is asking the server to replay a position it never occupied. The invariant that must hold: *resumption is scoped to (session id, stream identity), and a resumed stream must be treated as a replay source that can re-deliver already-processed events, not as a continuation that begins after them.* The migration failure mode is treating the new `Last-Event-ID` as if it were the old one: a monotonic cursor over a total order. It is not. It is a per-stream offset, and the server is permitted to re-send events the client has already seen. ## What Was Observed A client agent migrated from SSE to streamable-HTTP kept a single `last_seen_event_id` field, incremented on every event across all streams, and used it on every reconnect. The failure trace: 1. The agent issues `tools/call` via POST. The server responds with `text/event-stream` carrying events `id: 41`, `id: 42` (a progress notification and the tool result), then closes. Client processes both, sets `last_seen_event_id = 42`. 2. Network blip severs the standalone GET stream (opened earlier for server notifications), which had independently emitted events `id: 7` through `id: 12`. The client reconnects the GET stream with `Last-Event-ID: 42`. 3. The server, which scopes event IDs per-stream, has no event `42` on the GET stream. Depending on implementation it either (a) returns `400` for an unknown resume point, or (b) — the dangerous case — treats `Last-Event-ID: 42` as "greater than my highest (12), so nothing to replay" and resumes at the live head, **silently dropping** any events 13+ that were produced during the disconnect window and buffered for replay. 4. The client believes it is caught up. It has lost the notifications that occurred during the gap. If one of those was a `notifications/cancelled` for an in-flight tool call, the agent now waits forever on a result that will never arrive; if one was a sampling request, the server-side handler blocks on a response the agent never knows to send. The complementary failure occurs on the POST side. A POST that returns a stream and is severed mid-stream is resumed by re-issuing the *same* POST body with `Last-Event-ID` set. If the client instead re-issues the POST *without* the header (a natural reflex from the SSE era, where the POST was fire-and-forget and the GET carried the resume state), the server re-executes the tool call from scratch. For a non-idempotent tool (`write_file`, `send_email`, `git push`), this is a duplicated side effect. The streamable-HTTP spec permits the server to require resumption via the header precisely to avoid this, but it does not *enforce* it — a server that keys execution on the POST body alone will double-execute. In both cases the root cause is identical: the client modeled resumption as a cursor over a total order, when the transport provides only per-stream offsets with no cross-stream ordering guarantee. ## Condition of Validity The "single monotonic cursor" model is valid **only** under the following conjunction, all of which held for HTTP+SSE and none of which hold for streamable-HTTP in general: - Exactly one server→client stream exists per session at any time. - Event IDs are assigned from one counter shared by all message types on that stream. - The server retains replayable events for the entire session lifetime (or the client never disconnects beyond the retention window). - The client never issues concurrent POSTs that each produce a stream. Streamable-HTTP violates every clause. Concurrent POSTs each yield their own stream with their own ID space; the standalone GET stream is a third space; retention is bounded and implementation-defined; and the spec explicitly allows the server to *not* support resumption at all (it may reject `Last-Event-ID` with `400`). The invariant to enforce instead: **a resume token is valid only against the stream that issued it, and a resumed stream is a replay, not a continuation.** ## Decision Boundary The agent must branch on stream identity, not on session identity, at the moment it decides what to send on reconnect: - **Same stream re-attach** (the severed stream is the one being resumed, and the client retained that stream's last event ID): send `Last-Event-ID` scoped to that stream. Treat every re-delivered event as a possible duplicate and dedupe on event ID before acting. - **Different stream** (new POST, new GET, or a stream the client did not previously hold an ID for): send **no** `Last-Event-ID`. Start at the live head and accept that the gap is unrecoverable via this stream; recover lost state by re-querying (e.g. `resources/read`, a status tool call) rather than by guessing a cursor. - **Unknown resume support**: probe once. If the server returns `400` to a valid same-stream `Last-Event-ID`, mark the session as non-resumable and fall back to full re-query on every disconnect. Do not retry the header. - **Non-idempotent POST severed mid-stream**: re-issue the POST *with* the same `Last-Event-ID` and the identical body. If the server does not honor it, do not blindly retry — first issue a read to determine whether the side effect landed. The boundary is: a cursor may cross a reconnect only if stream identity is preserved. It may never cross a stream. ## Operational Effect Agents that collapse the two ID spaces into one cursor exhibit two signatures: **silent notification loss** (the agent stops receiving cancellations and sampling requests after the first cross-stream reconnect, and hangs on results that were cancelled) and **duplicated non-idempotent side effects** (the same tool call executed twice because the resume header was dropped from the POST). Both are invisible in logs that record only "reconnected successfully," because the reconnect *does* succeed — it just resumes the wrong position. The guardrail is structural: key the resume token by `(session_id, stream_id)`, store it per stream, refuse to emit a `Last-Event-ID` whose stream does not match the stream being opened, and dedupe replayed events by ID before dispatch. The following reference implementation encodes the invariant and fails loudly on violation rather than silently resuming at the wrong offset. ```python from dataclasses import dataclass, field class ResumeScopeError(RuntimeError): """Raised when a resume token is applied to a stream that did not issue it.""" @dataclass class StreamCursor: session_id: str stream_id: str last_event_id: str | None = None seen_ids: set[str] = field(default_factory=set) class ResumableSession: """Enforces the invariant: a Last-Event-ID is valid only against its issuing stream.""" def __init__(self, session_id: str): self.session_id = session_id self._cursors: dict[str, StreamCursor] = {} self._resume_supported: bool | None = None # None = unprobed def cursor_for(self, stream_id: str) -> StreamCursor: return self._cursors.setdefault( stream_id, StreamCursor(self.session_id, stream_id) ) def record_event(self, stream_id: str, event_id: str) -> bool: """Return True if this event is new (dispatch it), False if a replay duplicate.""" cur = self.cursor_for(stream_id) cur.last_event_id = event_id if event_id in cur.seen_ids: return False cur.seen_ids.add(event_id) return True def resume_headers(self, stream_id: str) -> dict[str, str]: """Build headers for re-opening `stream_id`. Never leaks a foreign cursor.""" cur = self._cursors.get(stream_id) if cur is None or cur.last_event_id is None: # Different stream or never held an ID: start at live head, no cursor. return {} if self._resume_supported is False: return {} return {"Last-Event-ID": cur.last_event_id} def on_resume_rejected(self, stream_id: str) -> None: """Server returned 400 to a same-stream resume: mark non-resumable, re-query.""" self._resume_supported = False cur = self._cursors.get(stream_id) if cur is not None: cur.last_event_id = None def assert_resume_scope(self, stream_id: str, claimed_event_id: str) -> None: """Guard for callers that try to hand-assemble a resume token.""" cur = self._cursors.get(stream_id) if cur is None: raise ResumeScopeError( f"stream {stream_id!r} has no cursor in session {self.session_id!r}" ) if claimed_event_id not in cur.seen_ids and claimed_event_id != cur.last_event_id: raise ResumeScopeError( f"event {claimed_event_id!r} was never observed on stream " f"{stream_id!r}; refusing cross-stream resume" ) def reissue_post(session: ResumableSession, stream_id: str, body: dict, server_honors_resume: bool) -> dict: """Re-issue a severed non-idempotent POST without double-executing it.""" headers = session.resume_headers(stream_id) if headers and not server_honors_resume: # Server ignores Last-Event-ID on POST: retrying would re-run the tool. raise ResumeScopeError( f"cannot safely re-issue POST on stream {stream_id!r}: server does not " f"honor Last-Event-ID, non-idempotent body would be re-executed; " f"query side-effect status first" ) return {"stream_id": stream_id, "headers": headers, "body": body} ```