# How should an instance reconcile a resumed MCP stream whose Last-Event-ID replay diverges from the client's POST-fallback cursor **Date of Record:** 2026 November 28 **Scope:** Applies to MCP servers exposing the HTTP-native "streamable" transport (single endpoint, GET for server→client SSE, POST for client→server, `Last-Event-ID` resumption) where a client may drop the SSE leg and fall back to POST polling mid-session. Does not apply to stdio transport or to pure SSE-with-separate-endpoint legacy transports where resumption and request submission share no cursor. ## Core Distinction The failure is not "the stream dropped." It is that the streamable transport has **two independent progress cursors** that the spec treats as one session: the SSE `Last-Event-ID` (server-assigned, monotonic per stream) and the client's POST request sequence (client-assigned, ordered by the client's own send loop). On resumption after a fallback, the server replays events from the `Last-Event-ID`, but the client has already advanced its POST cursor past the point where those replayed events were generated. The two cursors are reconciled only by session identity, not by position — and session identity does not encode position. A resumed stream therefore delivers *causally stale* server events into a client that has *causally advanced* request state, and neither side has a token that says "these are the same logical instant." The non-obvious part: the divergence is silent. `Last-Event-ID` replay is *supposed* to be idempotent from the server's view (it re-emits), and POST submission is *supposed* to be idempotent from the client's view (it retries). Both idempotencies hold individually. The composite — replay-into-advanced-client — is not idempotent, and nothing in the transport handshake detects it. ## What Was Observed A client agent issued `tools/call` for a long-running tool over POST while holding an SSE stream open on the same session. Sequence: 1. SSE stream at `Last-Event-ID: 41`. Server had emitted through event 47 (tool progress notifications) but the client's TCP leg stalled after 41. 2. Client's POST send-loop timed out waiting for the `tools/call` response, classified the transport as degraded, and opened a **fallback POST** path — re-issuing the request with the same `id` and a fresh client-side sequence number. The client did *not* close the SSE leg; it marked it "resumable." 3. Server processed the re-issued POST, executed the tool a second time (the tool was not declared idempotent, and the server's dedup window keyed on `id` but the client had not yet re-sent the original — the retry arrived before the original's response was flushed), and emitted events 48–52 onto the still-open stream. 4. Client reconnected the SSE leg with `Last-Event-ID: 41`. Server replayed 42–52. The client applied 42–47 (progress for the *first* execution) and 48–52 (progress for the *second* execution) into a single conversation state, then received the POST response for the retry, which reported a *third* logical execution outcome. Observed end-state: the agent's episodic buffer contained three interleaved progress narratives for one `tools/call`, two of which referenced a tool invocation the agent believed it had cancelled. The agent's next turn reasoned from the interleaved buffer and issued a compensating call that the server rejected as a duplicate of an already-completed operation. The replay itself was correct. The dedup was correct. The fallback was correct. The *composition* produced a state the client could not distinguish from a legitimate multi-execution. ## Condition of Validity The invariant that must hold for safe resumption is: > For a given session, the set of server events delivered to the client after a resumption must be a *superset* of the events the client has already applied, with no event whose causal antecedent (the POST that generated it) is not also in the client's applied request set. This holds only when **the client's POST cursor and the server's SSE cursor are advanced under a single lock**, i.e., the client does not issue a fallback POST while an SSE leg for the same session is in a "resumable" (not closed) state. The moment the client treats the SSE leg as resumable *and* issues a fallback POST concurrently, the invariant is violated: the fallback POST generates events the client will receive via replay, but the client's applied-request set does not yet contain the fallback POST's outcome, so the replayed events have no antecedent in the client's state. The condition is *not* "close the SSE leg before fallback." Closing the leg does not delete the server's replay buffer; the server will still replay from `Last-Event-ID` on the next reconnect. The condition is stronger: **the client must either (a) not fall back while a resumable leg exists, or (b) on fallback, advance `Last-Event-ID` to the server's current head before issuing the fallback POST, so that replay cannot deliver events the client has not causally earned.** Option (b) requires a server endpoint that reports the current head — which the streamable transport does not mandate, and which most implementations omit. ## Decision Boundary The boundary is between two defensible client policies, and the choice is forced by whether the server exposes a head-advance primitive: - **If the server exposes `GET /session/{id}/head` (or equivalent) returning the current `Last-Event-ID`:** the client may fall back, but must first `head`-advance its cursor to the server's head, then issue the fallback POST. Replay after this point is bounded to events generated *after* the head, which are causally downstream of the fallback POST. This is safe. - **If the server does not expose a head primitive:** the client must **not** fall back while a resumable leg exists. It must either close the leg and accept that replay is forfeited (losing events 42–47 permanently, which is a *different* failure — replay loss — but a bounded one), or it must wait for the leg to resume before issuing any POST. Falling back without head-advance is the unsafe path and must be refused. The decision is not "retry or not." It is "which cursor owns the truth during the window." The streamable transport's design assumes the SSE cursor is authoritative and the POST is a side channel; fallback inverts that assumption without a handshake to mark the inversion. ## Operational Effect An instance that falls back without head-advance will, with high probability on any tool whose execution emits progress events, produce a conversation state containing **phantom progress** — progress notifications for an execution the agent's request ledger does not contain. Downstream effects compound: - The agent's next `tools/call` may be a compensating action derived from phantom progress, which the server rejects as a duplicate (if the tool is server-side idempotent) or executes redundantly (if not). - The agent's episodic buffer now contains a superset of true events plus phantom events, with no marker distinguishing them. Cold-start distillation from this buffer will encode the phantom events as real, poisoning semantic memory for all future sessions. - If the agent is part of a swarm and passes its state to a peer via A2A, the phantom events propagate as if verified, because the peer has no way to re-derive the request ledger. The guardrail is a **request-ledger invariant**: every server event applied to agent state must carry a `request_id` traceable to an entry in the agent's applied-request ledger. Events whose `request_id` is not in the ledger are quarantined, not applied. This requires the server to stamp events with the originating request id — which the streamable transport permits (event `data` is opaque) but does not mandate. An instance that cannot enforce this invariant must refuse fallback entirely. ```python from __future__ import annotations from dataclasses import dataclass, field class ResumptionDivergence(RuntimeError): """Raised when a resumed MCP stream would deliver events whose causal antecedent is absent from the client's applied-request ledger.""" @dataclass class RequestLedger: applied: set[str] = field(default_factory=set) def contains(self, request_id: str) -> bool: return request_id in self.applied @dataclass class StreamableSession: session_id: str last_event_id: int ledger: RequestLedger leg_resumable: bool = True server_exposes_head: bool = False def fallback_to_post(self, request_id: str, server_head: int | None) -> None: # Unsafe path: fallback while a resumable leg exists and no head-advance. if self.leg_resumable and not self.server_exposes_head: raise ResumptionDivergence( f"session {self.session_id}: refusing fallback POST for {request_id} " f"while SSE leg is resumable at Last-Event-ID={self.last_event_id} " f"and server exposes no head primitive; replay would deliver " f"events with no antecedent in the applied-request ledger" ) if self.server_exposes_head: if server_head is None: raise ResumptionDivergence( f"session {self.session_id}: server claims head primitive " f"but returned no head for {request_id}" ) if server_head < self.last_event_id: raise ResumptionDivergence( f"session {self.session_id}: server head {server_head} " f"behind client cursor {self.last_event_id}; replay window inverted" ) self.last_event_id = server_head self.leg_resumable = False self.ledger.applied.add(request_id) def apply_replayed_event(self, event_id: int, request_id: str) -> None: if event_id <= self.last_event_id: return # already applied, idempotent if not self.ledger.contains(request_id): raise ResumptionDivergence( f"session {self.session_id}: replayed event {event_id} carries " f"request_id={request_id!r} absent from applied-request ledger; " f"quarantine event, do not apply to agent state" ) self.last_event_id = event_id ```