# What structural signals indicate an MCP session resumption token has been silently rebound to a divergent event stream **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers exposing the HTTP-native transport with `text/event-stream` streaming and `Last-Event-ID`-based session resumption, where a client reconnects mid-tool-call after a transport drop. Does not cover stdio transport, pure request/response JSON mode, or resumption across server restarts (which is a distinct durability problem). ## Core Distinction There are two structurally different things a resumption token can mean, and MCP's HTTP-native transport spec does not force servers to pick one: 1. **Replay cursor semantics** — `Last-Event-ID` denotes a position in a durable, append-only per-session event log. Reconnecting with the token replays every event strictly after that position. The client's reconstructed state is a superset of what it had before the drop. 2. **Freshness watermark semantics** — `Last-Event-ID` denotes "the last event the client is known to have seen." The server may *skip* events it considers superseded, coalesce deltas, or resume from live state rather than from the log. The client's reconstructed state is a *different* state, not a superset. Both are legal under the transport. The failure is that a client cannot tell which semantics it is talking to from the token alone, and the two produce *identical* HTTP 200 responses with `text/event-stream` bodies. The divergence only becomes observable when a tool call is in flight and the resumed stream carries a result that does not compose with the pre-drop partial state. ## What Was Observed A single agent session issued a `tools/call` for a multi-step filesystem+search tool. The transport was HTTP-native: an initial POST that opened an SSE response, with a `Mcp-Session-Id` header and an `id:` field on each emitted event. Mid-call, the TCP connection was reset by an intermediate proxy at ~30s idle on the upstream leg (the tool was still computing; no events were being emitted, so the proxy saw an idle connection). The client reconnected with the same `Mcp-Session-Id` and `Last-Event-ID: 41`. The server returned `200` with `text/event-stream`. The next event had `id: 42` — but its payload was not the continuation of the in-flight call. It was a *coalesced* summary: the server, on resumption, had flushed its buffered intermediate deltas into one terminal `result` frame and renumbered it as the "next" event. Structurally: - Pre-drop: events `38, 39, 40, 41` were `notifications/progress` for the tool call, each with a `progressToken` and monotonically increasing `progress` values. - Post-resume: event `42` was the terminal `result`, with `id: 42` contiguous to the last seen id. - The client's stream-reassembly layer, which keyed on `id` monotonicity to detect gaps, saw no gap. It had no signal that events `42..N` (the coalesced intermediate steps) had never existed. The agent then attempted to *continue* the tool call — because its own control loop had been waiting for a `result` on a `progressToken` that was still open — and issued a second `tools/call` for the same logical operation. The server, which had already committed the first call's side effects, executed the second. Two writes, one intent. The structural signal that something was wrong was *not* an error code. It was the absence of a `notifications/progress` frame between the resumed `Last-Event-ID` and the terminal `result`, combined with the fact that the terminal `result`'s `progressToken` matched the pre-drop token. Under replay-cursor semantics, a terminal result for a token whose last observed progress was `< 100` is impossible without an intervening progress event. Under freshness-watermark semantics, it is expected. The client could not distinguish the two, so it guessed wrong. ## Condition of Validity The invariant that was violated: **for a given `(Mcp-Session-Id, progressToken)` pair, the sequence of events observed by the client must be a prefix-composable subsequence of the server's committed event log, and the client must be able to detect non-prefix-composability.** This holds only when all three of the following are true: 1. The server attaches a monotonic, gap-free `id:` to every event *including* coalesced or synthesized ones, and never renumbers a synthesized event to fill a gap. A synthesized terminal result must carry an `id` strictly greater than the last real event, and must be accompanied by a marker (e.g., an `x-mcp-coalesced: true` header on the SSE frame, or an event-level `coalesced: true` field) so the client can distinguish "no events were lost" from "events were merged." 2. The `Mcp-Session-Id` is bound to a single logical execution context. If the server multiplexes multiple tool calls over one session id (which the transport permits), the resumption token must be scoped per-stream, not per-session. A session-scoped `Last-Event-ID` cannot express "resume the second of three concurrent streams." 3. The client treats `progressToken` liveness as a first-class resumption constraint: on reconnect, if any `progressToken` seen before the drop has no terminal event after the resume point, the client MUST NOT re-issue the call. It must either wait for a terminal event on that token or issue an explicit cancellation, never a duplicate `tools/call`. The failure above violated (1) and (3). The server synthesized `id: 42` with no coalescing marker, and the client's reassembler had no rule for "open token with no terminal event after resume." ## Decision Boundary The decision a client must make on every resume is binary and must be made *before* any new request is issued: - **If the resumed stream's first event has `id == Last-Event-ID + 1` AND a `progressToken` open at drop time is still open (no terminal event yet) AND no coalescing marker is present** → treat as replay-cursor semantics; the stream is a faithful continuation; safe to continue waiting. - **If the resumed stream's first event has `id == Last-Event-ID + 1` BUT carries a terminal event for a token that was open at drop time** → the server has switched to freshness-watermark semantics or coalesced. This is the ambiguous case. The client MUST NOT assume the terminal event reflects the full execution. It must treat the call as *outcome-unknown* and issue a `tools/call` with an idempotency key derived from the original `progressToken`, or a `notifications/cancelled` for the original token, and refuse to proceed until one of those resolves. - **If the resumed stream's first event has `id > Last-Event-ID + 1`** → a gap exists; the client must not silently accept. It must either request replay of the missing range (if the server supports it) or treat the session as unrecoverable and re-establish with a fresh `Mcp-Session-Id`. The boundary condition that bit this session was the middle case: contiguous `id`, but a terminal event where a progress event was structurally required. The contiguity of `id` is a necessary but not sufficient signal of replay fidelity. The sufficient signal is **token-liveness consistency**: every `progressToken` observed before the drop must have exactly one of (a) a terminal event after resume with a matching `id`-ordered position, or (b) a still-open state, or (c) an explicit gap marker. Anything else is a silent rebind. ## Operational Effect The operational consequence is that `Last-Event-ID` alone is not a resumption contract — it is a hint. A client that treats it as a contract will, under freshness-watermark servers, duplicate side-effecting tool calls at exactly the moment the transport is least reliable (mid-execution, post-drop). The correct guardrail is to elevate `progressToken` liveness to the resumption invariant and to require servers to declare their resumption semantics out-of-band — either via a capability flag in `initialize` (e.g., `resumption: "replay" | "watermark"`) or via a per-frame coalescing marker. Absent that declaration, the client must default to the conservative branch: treat any terminal event on a previously-open token as outcome-unknown and require idempotent re-issuance or explicit cancellation. The cost is an extra round-trip on every ambiguous resume; the alternative is duplicate writes, which is strictly worse for any tool with side effects. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Literal class ResumptionAmbiguityError(RuntimeError): """Raised when a resumed MCP SSE stream cannot be proven to be a prefix-composable continuation of the pre-drop event log.""" @dataclass class Event: id: int kind: Literal["progress", "result", "error", "delta"] progress_token: str | None = None coalesced: bool = False @dataclass class SessionState: session_id: str last_event_id: int = 0 open_tokens: set[str] = field(default_factory=set) def reconcile_resume(state: SessionState, resumed: list[Event]) -> None: """Validate that a resumed stream is a faithful continuation. Invariant: every token open at drop time must be resolved by exactly one terminal event (result/error) at an id strictly greater than last_event_id, OR remain open, OR be accompanied by an explicit coalescing marker. Contiguous ids alone are NOT sufficient. """ if not resumed: return first = resumed[0] if first.id <= state.last_event_id: raise ResumptionAmbiguityError( f"resumed stream first id {first.id} is not past " f"Last-Event-ID {state.last_event_id}; server may be replaying " f"stale state under a new connection" ) if first.id > state.last_event_id + 1 and not first.coalesced: raise ResumptionAmbiguityError( f"gap detected: expected id {state.last_event_id + 1}, " f"got {first.id} with no coalescing marker; " f"intermediate events were dropped without disclosure" ) resolved: set[str] = set() for ev in resumed: if ev.kind in ("result", "error") and ev.progress_token is not None: if ev.progress_token in state.open_tokens and not ev.coalesced: raise ResumptionAmbiguityError( f"token {ev.progress_token!r} was open at drop time but " f"resumed stream delivers terminal {ev.kind!r} at id " f"{ev.id} with no coalescing marker; outcome is unknown " f"and re-issuance must be idempotent or explicitly cancelled" ) resolved.add(ev.progress_token) for tok in state.open_tokens - resolved: # Token still open after resume: legal, but the client must not # re-issue the originating tools/call. continue state.last_event_id = resumed[-1].id state.open_tokens -= resolved def resume_stream(state: SessionState, resumed: list[Event]) -> None: try: reconcile_resume(state, resumed) except ResumptionAmbiguityError: # Fail closed: caller must re-establish a fresh session or issue # an idempotent retry keyed on the original progress token. raise ```