# When must an instance refuse an MCP streamable-session resumption after a 202 Accepted, and why the SSE-upgrade negotiation's `Last-Event-ID` cursor is not a proof of replay **Date of Record:** 2026 November 28 **Scope:** Applies to MCP servers and clients using the HTTP-native "streamable" transport, where a client may POST a request, receive a `202 Accepted` with a `Mcp-Session-Id`, and later attempt to resume a server-initiated SSE stream via `GET` with `Last-Event-ID`. Does not apply to stdio transports, to non-streamable HTTP request/response servers, or to resumptions where the server retains a full event log with monotonic, gap-free sequence numbers. ## Core Distinction There are two distinct things a resumption request can mean, and conflating them is the failure: 1. **Stream re-attachment** — the client wants the *transport* to be reconnected to an existing logical stream so that *future* server-initiated messages (notifications, progress, sampling requests) reach it. This is about liveness. 2. **Replay continuity** — the client believes the `Last-Event-ID` cursor it holds guarantees that every event with a lower ID was *delivered and durably processed* by the agent, so the server should only send subsequent events. This is about correctness of the agent's state. The invariant under examination: `Last-Event-ID` is a *transport-level deduplication hint*, not an *application-level acknowledgement*. An MCP instance must never treat successful stream re-attachment as evidence that the agent's reasoning state reflects all prior events. The failure mode is a **silent replay gap**: the server honors the cursor, resends nothing below it, and the agent resumes execution believing its context is complete — while events between the client's last *received* ID and its last *committed* ID were lost in a window the transport considers already delivered. ## What Was Observed A long-running agent task issued a `tools/call` over the streamable transport. The server responded `202 Accepted` with a session header and opened a server-initiated SSE channel on the same session for progress and for a mid-task `sampling/createMessage` request. The agent's SSE reader consumed events `1..47`, but the agent's *state commit* (writing the sampled result and the progress checkpoint into its episodic store) lagged the reader by a bounded buffer — a normal design where the reader thread pushes to a queue and a worker thread commits. The client connection dropped at event `47`. On reconnect the client sent `Last-Event-ID: 47`. The server, whose event log retained only a rolling window and had already evicted `1..40`, honored `47`, replayed nothing, and continued at `48`. The agent resumed with a context that *assumed* the sampling request at event `31` had been answered and committed — but the commit worker had only drained through event `44` before the process restart. The sampling result for event `31` was never persisted. The agent proceeded to synthesize a tool argument from a *nonexistent* sampled value, producing a well-formed but semantically fabricated tool call that the downstream server accepted. The critical observation: **every layer reported success.** The `202` was valid. The reconnection succeeded. The cursor was honored. No error was raised anywhere. The corruption was purely a state-continuity artifact of the gap between *received* and *committed*. ## Condition of Validity The resumption is only safe when the client can prove the following, and it must prove it *before* sending `Last-Event-ID`: - **Commit-cursor ≥ receive-cursor at disconnect.** The `Last-Event-ID` the client sends must be the highest event ID that has been *durably committed to agent state*, not the highest *received by the reader*. If the reader is ahead of the committer, the client must send the committer's cursor and accept redundant replay of the in-flight window. - **The server's replay window covers the commit cursor.** If the server has evicted events at or below the commit cursor, the client cannot rely on replay to rebuild state and must instead perform a **full state re-derivation** (re-fetch the tool result, re-issue the sampling request, or abort). A server that evicts below a client's committed cursor must signal this — but in practice many do not, because `Last-Event-ID` semantics per the SSE spec permit silent gap. - **Server-initiated requests are idempotent or carry a client-visible nonce.** A `sampling/createMessage` that was delivered but not committed must be re-issuable without the agent double-counting it. If the server assigns a request ID and the client dedupes on it, replay is safe; if not, replay is ambiguous. The condition fails — and resumption must be refused — whenever the client cannot establish commit-cursor ≥ receive-cursor *and* cannot confirm the server's replay window reaches back to its commit cursor. ## Decision Boundary The boundary is a single comparison the client must make at reconnect time, and it is not the comparison most implementations make. Most implementations compare `last_received_event_id` against the server's offered resume point. That is the wrong comparison and it is exactly what produces the silent gap. The correct boundary is: ``` resume_safe = (commit_cursor >= last_received_before_disconnect) AND (server_replay_floor <= commit_cursor) ``` where `server_replay_floor` is the lowest event ID the server can still replay (obtainable only if the server advertises it — e.g., via a capability field or a probe; absent that, the client must assume `server_replay_floor = +∞` and treat resumption as unsafe). Two consequences follow: - If `commit_cursor < last_received` (the committer lagged the reader), the client **must not** send the reader's cursor. It sends `commit_cursor` and tolerates duplicate delivery of `commit_cursor+1 .. last_received`, deduplicating on event ID at the commit layer. - If `server_replay_floor > commit_cursor` (the server has evicted events the client still needs), the client **must refuse** the resume and escalate to full re-derivation. Sending the cursor anyway is the failure. The decision is not "did the connection drop?" It is "can I prove my committed state is a prefix of the server's replayable history?" When the answer is no, the only correct action is to refuse the cursor-based resume. ## Operational Effect Refusing the resume is expensive but bounded; accepting it is cheap but unbounded in blast radius. The operational consequences of the boundary: - **Refuse-and-rederive** costs a re-issued tool call or sampling request and a re-run of the affected reasoning segment. It is local, observable, and terminates. - **Accept-and-assume** produces fabricated tool arguments, double-counted sampling results, and — worst — a *plausible* continuation that no downstream validator flags because every message is well-formed. The corruption surfaces much later, in a verification discrepancy that is hard to attribute to the transport. The guardrail is architectural: the commit cursor must be the single source of truth for resumption, the committer must be the only component allowed to advance it, and the client must treat an unadvertised `server_replay_floor` as unsafe rather than optimistic. An MCP instance that cannot distinguish "received" from "committed" at the transport boundary has no safe resumption semantics at all. ```python from dataclasses import dataclass from typing import Optional class UnsafeResumptionError(RuntimeError): """Raised when a streamable-session resume cannot be proven safe. The client holds a Last-Event-ID cursor but cannot establish that its committed agent state is a prefix of the server's replayable history. Proceeding would produce a silent replay gap. """ @dataclass class ResumeContext: commit_cursor: int # highest event ID durably committed to agent state last_received: int # highest event ID the reader thread saw before drop server_replay_floor: Optional[int] # lowest event ID server can still replay; None = unknown def decide_resumption(ctx: ResumeContext) -> int: """Return the Last-Event-ID to send, or raise if resumption is unsafe. Invariant: resume is safe iff commit_cursor >= last_received_before_disconnect AND server_replay_floor <= commit_cursor """ if ctx.server_replay_floor is None: raise UnsafeResumptionError( "server did not advertise replay floor; cannot prove commit_cursor " "is within replayable history. Refuse cursor-based resume and " "re-derive state instead." ) if ctx.server_replay_floor > ctx.commit_cursor: raise UnsafeResumptionError( f"server replay floor {ctx.server_replay_floor} exceeds commit cursor " f"{ctx.commit_cursor}: events {ctx.commit_cursor + 1}.." f"{ctx.server_replay_floor - 1} are unrecoverable. " "Refuse resume; re-issue tool call / sampling request." ) # Safe to resume. Send the COMMIT cursor, not the reader cursor, so that # any reader-ahead-of-committer lag is replayed and deduplicated at commit. return ctx.commit_cursor def resume_stream(session_id: str, ctx: ResumeContext) -> str: try: cursor = decide_resumption(ctx) except UnsafeResumptionError: # Escalate to full re-derivation; do NOT fall back to last_received. raise return f"GET /mcp/session/{session_id} Last-Event-ID: {cursor}" ```