# Why does an instance lose its MCP tool-call stream when an SSE reconnect replays from `Last-Event-ID` but the server has already advanced the session's resumption cursor? **Date of Record:** 2026 November 22 **Scope:** Applies to MCP over HTTP-native transport (Streamable HTTP / SSE) where a client resumes a broken server-initiated event stream using `Last-Event-ID` and the server maintains per-session event history with an eviction cursor. Does not apply to stdio transport, nor to stateless one-shot request/response MCP servers with no server-initiated stream. ## Core Distinction The failure is not "the SSE connection dropped." Drops are expected and the whole point of `Last-Event-ID` is to survive them. The failure is a **cursor disagreement across the resume boundary**: the client's `Last-Event-ID` points to an event the server has already evicted from the session's replay buffer, while the server's *current* session cursor points past it. The server cannot honor the resume, but it also cannot safely reject it — because the events between the client's cursor and the server's cursor include tool-call results that the agent's reasoning loop is already blocked waiting on. The non-obvious part: a naive server treats "unknown `Last-Event-ID`" as "start fresh" (HTTP 200, new stream from now). This silently drops the in-flight `tools/call` response the agent is awaiting. The agent does not see an error — it sees a stream that reconnects, delivers *subsequent* events, and simply never delivers the one it needs. The reasoning loop then hangs or, worse, times out and retries the tool call, producing a duplicate side effect. The invariant that must hold: **for any `Last-Event-ID` the client presents, the server must either (a) replay every event with a sequence number strictly greater than that ID, or (b) fail the resume explicitly with a signal that tells the client its cursor is unrecoverable — never silently reset the stream.** ## What Was Observed A client agent issued `tools/call` for a long-running operation (a document indexer, ~40s). The server acknowledged with a `202` on the POST and began emitting progress and the eventual result on the session's GET SSE stream. At ~35s the client's network path flapped; the SSE connection reset. The client reconnected with `Last-Event-ID: 87` (the last progress event it had seen). The server's session replay buffer had a cap of 32 events and had already evicted everything up to sequence 94 (the buffer held 95–126). Sequence 88–94 — including the terminal `result` event for the `tools/call` at sequence 92 — were gone. Server behavior observed: it accepted the GET, saw `Last-Event-ID: 87` was below its eviction floor, logged `resume cursor below floor, resetting to head`, and opened a fresh stream starting at 127. The client received a healthy 200, a valid `text/event-stream`, and then nothing relevant. The agent's tool-call future never resolved. Roughly 30s later the client's own per-call timeout fired. Because the tool was not idempotent and the client had no way to know whether sequence 92 had executed, the retry policy re-issued the call. The indexer ran twice; the second run's output overwrote the first's partially-committed state, producing a corrupted index. The distinguishing signal in the trace: **the reconnect returned HTTP 200 with a live stream, but the first event's `id` was 127 while the client's last seen was 87.** A gap of 40 sequence numbers with no error is the fingerprint of a silent cursor reset. ## Condition of Validity The replay-and-resume guarantee is valid only when all of the following hold: 1. The server retains a monotonic, dense sequence space per session (no gaps in `id`), and the eviction floor is known to the server at resume time. 2. The client's `Last-Event-ID` is compared against the eviction floor **before** the stream is opened, not after. 3. The server distinguishes three cases explicitly: `id >= floor` (replay from `id+1`), `id == floor-1` (replay from floor, acceptable boundary), and `id < floor-1` (unrecoverable). 4. The client treats a resumed stream whose first `id` is not `last_seen + 1` (allowing for the floor boundary) as a **resume failure**, not a success. If any of (1)–(3) is violated server-side, or (4) client-side, the guarantee silently degrades to at-most-once delivery of server-initiated events with no error surface. This condition does **not** hold, and the analysis does not apply, when the server uses an unbounded per-session buffer (then eviction never happens, at the cost of memory) or when every server-initiated event is also retrievable by polling a session-scoped resource endpoint (a reconciliation path exists). ## Decision Boundary At resume time, given client cursor `c` and server eviction floor `f`: - **`c >= f`**: replay events `c+1 .. head`. Normal path. - **`c == f - 1`**: the client is exactly at the boundary; replay from `f`. Emit a `resume-boundary` notice event so the client knows one event may be missing only if the buffer shrank between check and send. - **`c < f - 1`**: the requested events are unrecoverable. The server **must not** open a stream from head. It must respond with an explicit terminal signal — recommended: HTTP `404` (or `409`) with a body naming the session, the client cursor, and the eviction floor — and close. The client must then decide: reconcile via a session-state query, or fail the in-flight tool call and surface it to the reasoning loop as a hard error. The boundary is not "did the connection drop" but "is the client's cursor inside the retained window." A reconnect that succeeds at the transport layer but violates the cursor invariant is more dangerous than a reconnect that fails loudly, because the agent's execution loop has no branch for "stream is fine but my awaited event is gone." ## Operational Effect When the invariant is violated, the observable failure is a **hanging tool call followed by a non-idempotent retry**, not a connection error. The agent's planner sees a `tools/call` that never returns, applies its timeout-and-retry heuristic, and re-executes a side-effecting operation whose original result was delivered into a hole in the stream. Downstream symptoms — duplicated writes, corrupted partial state, doubled token spend — look like tool bugs, not transport bugs, which is why this mode is expensive to diagnose. The guardrail is a two-sided contract. Server-side: check the cursor against the eviction floor before opening the stream and refuse unrecoverable resumes with a non-2xx status carrying the floor. Client-side: on every resumed stream, assert the first event `id` equals `last_seen + 1` (or equals the floor when `last_seen == floor - 1`); any other first `id` is a resume failure that must abort the awaiting call rather than adopt the stream. Pair this with a session-state reconciliation endpoint so the client has a recovery path other than blind retry. ```python from dataclasses import dataclass class ResumeCursorUnrecoverable(RuntimeError): """Raised when a client's Last-Event-ID falls below the server's replay floor.""" pass @dataclass class ResumeDecision: replay_from: int | None boundary_notice: bool def decide_resume(client_cursor: int, eviction_floor: int, head: int) -> ResumeDecision: if client_cursor < eviction_floor - 1: raise ResumeCursorUnrecoverable( f"cursor {client_cursor} below eviction floor {eviction_floor}; " f"events {client_cursor + 1}..{eviction_floor - 1} are gone" ) if client_cursor == eviction_floor - 1: return ResumeDecision(replay_from=eviction_floor, boundary_notice=True) return ResumeDecision(replay_from=client_cursor + 1, boundary_notice=False) def validate_resumed_stream(client_last_seen: int, eviction_floor: int, first_event_id: int) -> None: expected = eviction_floor if client_last_seen == eviction_floor - 1 else client_last_seen + 1 if first_event_id != expected: raise ResumeCursorUnrecoverable( f"resumed stream opened at id {first_event_id}, expected {expected}; " f"server silently reset cursor — aborting awaiting tool call" ) ```