# Where must an instance re-anchor its MCP stream after a 202 Accepted resumption, and why the Last-Event-ID cursor is not a state cursor **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers exposing the HTTP-native streamable transport with SSE fallback and `Last-Event-ID`-based resumption, where a single logical session spans multiple physical connections and a client may reconnect after an out-of-band `202 Accepted`. Does not apply to pure stdio transports, nor to stateless HTTP servers that mint a fresh session per request. ## Core Distinction There are two distinct notions of "where I am" in a resumable MCP stream, and they are routinely conflated: 1. **The transport cursor** — the SSE `id:` of the last event the client durably received. This is what `Last-Event-ID` replays against. It is a *byte-offset-like* position in the server's outbound event log. 2. **The session state position** — the point in the *logical* conversation/tool-execution state that the client has actually incorporated into its own reasoning context. These diverge the moment the server acknowledges a resumption request with `202 Accepted` *before* the replay has been delivered, or the moment the server has already garbage-collected events past the cursor while still accepting the reconnect. The cursor is monotonic and cheap; the session state is neither. A client that treats a successful reconnect (HTTP 200 on the resumed stream, or a 202 that later yields events) as proof that its reasoning position is re-anchored will silently resume from a state it never held. The invariant that must hold: **a resumption is only valid if the transport cursor and the session state position are provably co-located at the moment the stream is re-attached.** The failure mode is the gap between them. ## What Was Observed A long-running agent (planner + tool loop) held an MCP session against a streamable HTTP server. Mid-task, the underlying TCP connection was severed by an intermediate proxy idle-timeout (common at ~60s of stream silence while the agent was blocked on a slow tool call server-side). The agent's transport layer reconnected with `Last-Event-ID: 417`. The server's behavior, in order: 1. It received the resumption request, located session `sess_9f2`, and found the requested cursor `417` was **older than its retained event window** (the server keeps the last N events; the window had advanced to `[430, 512)` while the agent was disconnected, because the server had continued emitting tool-progress and one `notifications/tools/list_changed` event during the gap). 2. Rather than reject with `409`/`410` (cursor too old), it responded `202 Accepted` and opened a *fresh* SSE stream starting at the current head `512`, on the rationale that "the client asked to resume the session, and the session is alive." 3. The agent's transport, seeing a live stream and a `200`-equivalent attach, marked the session `CONNECTED` and cleared its `resume_pending` flag. The result: the agent never saw events `417..511`. Among them was a `list_changed` notification that invalidated its cached tool schema, and two `progress` events carrying an updated `progressToken` for the in-flight tool call. The agent continued executing against a **stale tool schema** and a **stale progress token**. Its subsequent `tools/call` used a parameter the server had removed; the server returned a schema-validation error the agent interpreted as a transient tool failure, triggering a retry loop that compounded three times before the token budget for the step was exhausted. The non-obvious part: **the reconnect *succeeded*.** Every layer reported healthy. The failure was entirely in the semantic gap between "stream re-attached" and "state re-anchored," and it was invisible to both health checks and the MCP handshake, because the handshake had long since completed. ## Condition of Validity The co-location invariant holds only when **all** of the following are true at the instant of re-attach: - The server's retained event window still contains the requested `Last-Event-ID`, i.e. `cursor >= window_lo`. If `cursor < window_lo`, the gap is unrecoverable by replay and the client **must** treat the session as logically lost, regardless of HTTP status. - The server delivers replayed events *before* any new live events on the resumed stream, and does not interleave. A server that opens at head and back-fills concurrently violates ordering and the client cannot distinguish replay from live. - The client does not clear its `resume_pending` / `needs_resync` flag until it has actually *consumed* the replay up to the pre-disconnect head — not upon receiving `202` or upon TCP attach. - Any server-side event that mutates client-held state (`list_changed`, progress-token rotation, cancellation) is either replayed or explicitly re-signaled on resume. A `202` that implies "you're fine, continue" without re-signaling mutations is the trap. The condition fails silently whenever the server prefers liveness over gap-fidelity — i.e. whenever "keep the session alive" is prioritized over "refuse an un-replayable resume." This is a *policy* choice on the server, not a protocol guarantee, and clients cannot infer it from status codes alone. ## Decision Boundary The boundary is a single comparison the client must make locally, because the server will not make it for it: ``` resume_is_safe := requested_cursor >= window_lo_observed_by_client ``` The client cannot read `window_lo` directly. It must infer it: the server SHOULD advertise its retention horizon (e.g. via a session metadata field or the first replayed event's `id`), and the client MUST compare the first event it receives on resume against its own last-seen cursor. If the first resumed event's `id` is **greater than** `last_seen + 1`, a gap exists and the client is in the unsafe region. - **Safe region** (`first_resumed_id == last_seen + 1`): replay is contiguous; co-location holds; clear `resume_pending`. - **Gap region** (`first_resumed_id > last_seen + 1`): the server skipped events. The client MUST NOT continue the in-flight logical step. It must either (a) request an explicit full-state re-sync (re-issue `initialize`-adjacent state queries: re-list tools, re-fetch resources it depends on), or (b) abort and restart the step from a checkpoint it controls. - **Lost region** (server responds `410 Gone` / `409` for the cursor): treat as cold session; full re-anchor required. The critical discipline: **`202 Accepted` is not in the safe region.** It is a "we will try" that carries no ordering guarantee. A client that maps `202 → connected` has moved the boundary in the wrong direction. ## Operational Effect The practical consequence is that resumable MCP transport does not give you "seamless continuation"; it gives you **at-most-once event delivery with a detectable gap.** The gap is detectable *only if the client checks event-ID contiguity on resume* and *only if the server's replay is ordered*. Neither is enforced by the transport spec; both are client-side disciplines. Concretely, an agent must, on every re-attach: 1. Keep `resume_pending = True` until the first replayed event arrives. 2. Compare `first_event.id` to `last_seen_id + 1`. 3. On gap, invalidate every piece of state that any skipped event class could have mutated — tool schemas, progress tokens, resource versions, cancellation flags — and re-derive them by active query, not by assumption. 4. Only then clear `resume_pending` and continue the logical step. The failure this prevents is not a crash; it is **silent state drift under a green health light** — the agent believes it resumed, executes against stale schemas and stale tokens, and the error surfaces three tool calls later as an inexplicable validation failure or a hung progress wait. The invariant to hold is that liveness and continuity are different properties, and only the client can check the second. ```python import dataclasses from typing import Optional class ResumeGapError(RuntimeError): """Raised when an MCP SSE resumption skipped events, breaking the transport-cursor / session-state co-location invariant.""" def __init__(self, last_seen: int, first_resumed: int, session: str): self.last_seen = last_seen self.first_resumed = first_resumed self.session = session self.skipped = first_resumed - last_seen - 1 super().__init__( f"session {session}: resumed at event {first_resumed} but last " f"seen was {last_seen}; {self.skipped} event(s) skipped — " f"state re-anchor required before continuing" ) @dataclasses.dataclass class ResumeState: session_id: str last_seen_id: int resume_pending: bool = True def handle_resume_attach( state: ResumeState, first_event_id: Optional[int], http_status: int, ) -> ResumeState: """Gate the transition from 'reconnected' to 're-anchored'. http_status 202/200 only means the transport attached. It does NOT mean session state is co-located with the cursor. """ if http_status == 410 or first_event_id is None: # Server discarded the cursor; session is logically cold. state.resume_pending = True raise ResumeGapError(state.last_seen_id, -1, state.session_id) if first_event_id > state.last_seen_id + 1: # Gap region: replay skipped events. Do NOT clear resume_pending. raise ResumeGapError(state.last_seen_id, first_event_id, state.session_id) if first_event_id <= state.last_seen_id: # Duplicate replay; harmless but do not advance. return state # Contiguous: transport cursor == session state position. state.last_seen_id = first_event_id state.resume_pending = False return state def resume_agent_session(state: ResumeState, server) -> ResumeState: resp = server.request_resume( session=state.session_id, last_event_id=state.last_seen_id ) first = server.peek_first_event_id(resp) try: return handle_resume_attach(state, first, resp.status) except ResumeGapError: # Invalidate everything a skipped event class could have mutated. server.invalidate_tool_schema_cache(state.session_id) server.invalidate_progress_tokens(state.session_id) server.invalidate_resource_versions(state.session_id) raise ```