# How should an instance treat an MCP resumption token as a replay cursor rather than a session identity **Date of Record:** 2026 November 29 **Scope:** Applies to MCP servers and clients using the HTTP-native transport with SSE streaming and the `Last-Event-ID` resumption mechanism, where a client reconnects after transport loss and presents a resumption token. Does not cover stdio transport, nor full session re-establishment via `Mcp-Session-Id` alone without a stream cursor. ## Core Distinction The non-obvious boundary is between two things that look identical on the wire: a **resumption token** as a *replay cursor* into a per-stream event log, versus a resumption token as a *session identity* that authorizes continued access to server-side state. MCP's HTTP-native transport conflates these because the token (`Last-Event-ID`) is presented in the same reconnect request that also carries `Mcp-Session-Id`. The invariant that actually holds is narrow: **the token guarantees at-least-once delivery of events strictly after the cursor position within a single logical stream, and nothing more.** It does *not* guarantee that the server still holds the events, that the session's tool-call side effects are replayable, or that the token's position is meaningful after the session was garbage-collected or the stream was rotated. ## What Was Observed A client running a multi-step tool loop lost its connection mid-stream while awaiting the result of a `tools/call` for a long-running operation. The server had emitted events `e1..e47` on the stream, the client had consumed through `e42`, and the transport dropped. The client reconnected with `Last-Event-ID: e42` and the same `Mcp-Session-Id`. Three failure traces were observed depending on server-side retention state: 1. **Retention intact, replay correct.** Server replayed `e43..e47` then continued live. The tool call had *already executed* server-side, and `e43` contained its result. The client, having received `e43` on the first pass but not durably recorded it before the drop, processed the result twice and issued a second dependent `tools/call`. Duplicate side effect. 2. **Retention expired, silent reset.** The server had evicted the event log for that stream (retention window elapsed, or stream rotated on reconnect). It accepted the reconnect, ignored the unknown `Last-Event-ID`, and resumed the stream *from the current head*. The client believed it had continuity from `e42`; it had actually skipped `e43..e47` entirely. The dependent tool call never fired; the agent loop diverged because its reasoning state assumed a result that was silently dropped. 3. **Session collected, token orphaned.** The `Mcp-Session-Id` had been garbage-collected (idle timeout). The server treated the reconnect as a fresh session but the client kept its old token. Subsequent events were numbered from a fresh sequence, colliding in namespace with the client's cursor. The client's dedup logic suppressed *new* events as "already seen." The common thread: the client treated the token as proof of session state continuity. The server treated it as a best-effort replay hint. Neither side's model matched the other's. ## Condition of Validity The resumption token is a valid replay cursor **only if all of the following hold simultaneously**, and the client cannot verify any of them from the token alone: - The server retains the event log for the stream identified by `Mcp-Session-Id` and has not rotated it. - The token's event ID is within the retained window (not evicted by retention policy or buffer cap). - The session identified by `Mcp-Session-Id` is still live and bound to the same stream generation. - Events are numbered monotonically and uniquely *within that generation*; a new generation resets the sequence. Because the client cannot observe retention state, generation, or session liveness without an out-of-band signal, the token is *unconditionally* an at-least-once hint and *conditionally* a continuity guarantee. The correct client invariant is therefore: **assume replay may duplicate and may gap; reconcile against an idempotency key, never against the cursor.** ## Decision Boundary The boundary the instance must enforce: **a resumption token may be used to request replay, but the decision to trust the resulting stream as continuous must be gated on a server-acknowledged cursor.** Concretely, on reconnect the client must: - Present `Last-Event-ID` *and* require the server to echo the highest event ID it actually resumed from. If the echoed cursor does not equal the presented cursor, the client must treat the gap as a **hole** and re-issue any in-flight tool call whose result it has not durably recorded. - Treat every replayed event as potentially duplicate; dedup on a per-event idempotency key (the tool-call `id` plus a result digest), not on event sequence number. - On session-collection detection (fresh sequence, missing session echo), discard the old cursor namespace entirely and re-establish state from scratch rather than resuming. The failure mode is *not* the drop itself. It is the client silently upgrading a best-effort replay hint into a session-continuity assumption. ## Operational Effect Systems that get this right exhibit a specific signature: after any transport drop, the agent's reasoning state is reconstructed from **durably checkpointed tool results keyed by idempotency token**, and the stream cursor is treated as a latency optimization, not a source of truth. Systems that get it wrong exhibit either duplicate side effects (case 1) or silent reasoning divergence (case 2) or event starvation (case 3) — and all three are indistinguishable to the agent from "the model made a mistake," which is why the root cause is routinely misattributed to the model rather than to the transport contract. The guardrail is architectural: the resumption token must never be permitted to stand in for a durable checkpoint. The stream provides ordering and replay; the checkpoint provides truth. Conflating them is the boundary violation. ```python import hashlib from dataclasses import dataclass, field class ResumptionCursorError(RuntimeError): """Raised when a resumption token cannot be trusted as a continuity cursor.""" pass @dataclass class StreamCursor: session_id: str generation: int last_event_id: str @dataclass class ReconnectAck: session_id: str generation: int resumed_from_event_id: str sequence_reset: bool @dataclass class CheckpointStore: # Maps idempotency key -> durable result digest. Source of truth. committed: dict = field(default_factory=dict) def has(self, key: str) -> bool: return key in self.committed def commit(self, key: str, result: str) -> None: self.committed[key] = hashlib.sha256(result.encode()).hexdigest() def reconcile_resumption( cursor: StreamCursor, ack: ReconnectAck, store: CheckpointStore, inflight_tool_call_id: str, ) -> str: """ Decide whether the resumed stream is continuous with `cursor`, and whether any in-flight tool call must be re-issued because its result may have fallen into a replay gap. """ # Generation change means the event-ID namespace was reset: the old cursor # is meaningless and must not be used for dedup or gap reasoning. if ack.generation != cursor.generation: raise ResumptionCursorError( f"stream generation changed {cursor.generation}->{ack.generation}; " f"cursor {cursor.last_event_id!r} is orphaned, must re-establish state" ) # Server acknowledged a different resume point than we requested: there is # a hole between our cursor and the server's head. We cannot assume the # in-flight tool result was delivered. if ack.resumed_from_event_id != cursor.last_event_id: if store.has(inflight_tool_call_id): # Result is durably checkpointed; safe to proceed, hole is benign. return "resume_with_checkpoint" raise ResumptionCursorError( f"replay gap: requested {cursor.last_event_id!r}, " f"server resumed at {ack.resumed_from_event_id!r}; " f"in-flight tool call {inflight_tool_call_id!r} not checkpointed" ) # Cursor matched and generation stable: replay is continuous, but events # are still at-least-once. Caller must dedup on idempotency key. return "resume_continuous_but_dedup" def handle_reconnect(cursor, ack, store, inflight_tool_call_id): mode = reconcile_resumption(cursor, ack, store, inflight_tool_call_id) if mode == "resume_with_checkpoint": return "proceed" return "proceed_dedup" ```