# How should an instance detect that MCP HTTP-native streamable-session resumption has silently forked an SSE event stream **Date of Record:** 2026 November 25 **Scope:** Applies to MCP clients using the HTTP-native "streamable" transport where a session is resumed after a dropped connection by replaying server-sent events keyed by a `Last-Event-ID` cursor. Does not apply to stdio transports, to stateless single-request HTTP transports, or to resumption schemes where the server issues a fresh session ID on every reconnect (there the fork is trivially detectable by ID mismatch). ## Core Distinction The distinction that matters is between **resumption as replay** and **resumption as continuation**. Replay semantics assume the server holds an append-only event log per session and that a `Last-Event-ID` cursor uniquely identifies a position in that log; the client reconnects, presents the cursor, and receives exactly the events after that position. Continuation semantics assume the server's stream is a live tail with no durable log, and that "resume" means "re-subscribe from now." MCP's streamable HTTP transport permits both interpretations, and the protocol does not force the server to declare which one it implements. When a client assumes replay and the server implements continuation, the client does not get an error—it gets a well-formed SSE stream that is silently missing the events produced during the disconnect window. This is the fork: two logically distinct histories, `H_client` and `H_server`, that agree at the cursor and diverge afterward, with no in-band signal that divergence occurred. A second, subtler fork occurs even under true replay semantics. If the server's event log is partitioned by session and the session was garbage-collected or the log was truncated (bounded ring buffer, TTL eviction), the server may respond to an unknown `Last-Event-ID` by either (a) returning 400/409, (b) silently starting from the current tail, or (c) replaying from the oldest retained event, which is *newer* than the client's cursor and thus skips a suffix of history. Option (b) and (c) are the dangerous ones: both are protocol-legal, both produce valid SSE, and both leave the client's reconstructed tool-call sequence inconsistent with what the server actually executed. ## What Was Observed A tool-calling agent held a streamable session with an MCP server exposing a `write_file` and a `read_file` tool. The agent issued a batch of three `write_file` calls and awaited their results. The connection dropped after the server had executed calls 1 and 2 and emitted their `tool_result` events, but before call 3's result was emitted. The client had persisted `Last-Event-ID: evt_2`. On reconnect the client presented `evt_2`. The server had a 60-second event-log TTL and the reconnect happened at 74 seconds. The server's log for that session had been evicted. The server, per its continuation fallback, opened a fresh stream and emitted a synthetic `session_resumed` notification followed by the *live* tail—which, because call 3 had long since completed and its result had been flushed to the (now-evicted) log, contained nothing. The client saw a clean 200, a valid `text/event-stream`, a `session_resumed` event, and then silence. It concluded that call 3 was still pending and blocked on a result that would never arrive. The failure signature was not an error. It was a **liveness stall with a healthy transport**: the socket was open, heartbeats flowed, and the agent's event loop reported the session as `connected`. The agent's own reasoning layer, seeing no `tool_result` for call 3, entered a retry loop that re-issued `write_file`—producing a duplicate write, because the server had no idempotency key bound to the original call and the original execution had already mutated state. The fork in event history became a fork in *world state*. A parallel observation from a second server implementation: on unknown `Last-Event-ID` it returned HTTP 200 and replayed from the oldest retained event, which was `evt_5`. The client, expecting to resume at `evt_2`, received `evt_5` with no gap indicator. Because SSE `id:` fields are opaque strings, the client had no way to know that `evt_3` and `evt_4` existed and were skipped. It applied `evt_5`'s payload—a `tool_result` for a call it had no record of issuing—and its tool-call ledger became internally inconsistent: a result with no matching call. ## Condition of Validity Replay-based resumption is only valid under a conjunction of conditions that the client must be able to *verify*, not assume: 1. **Cursor monotonicity is server-guaranteed and declared.** The server must treat `Last-Event-ID` as a strict position and must respond to an evicted/unknown cursor with a distinguishable error (e.g., `409 Conflict` with a `resume_gap` body), never with a silent tail. The client cannot infer this from a 200. 2. **The event log's retention window exceeds the maximum client reconnect budget.** If the server's TTL is 60s and the client's backoff can reach 90s, the invariant is already violated on paper. The client must know the server's retention bound (via capability metadata or a `retry` hint) and cap its own reconnect deadline below it. 3. **Every state-mutating tool call carries an idempotency key that the server deduplicates across resumes.** Without this, a client that cannot distinguish "result lost" from "call never executed" will either duplicate the mutation (retry) or drop it (assume success). Both are wrong; the only correct action requires the server to answer "did call K with key X execute?" 4. **The client maintains a local ledger of issued-call IDs and received-result IDs and reconciles on every resume.** The invariant is `results ⊆ issued` and, for a completed session, `results = issued`. A result arriving for an unissued call is a hard protocol violation, not a recoverable anomaly. When any of these is unverifiable, the session is in *unresumable* state and the correct behavior is to abandon the session and re-establish a fresh one with explicit state reconciliation—not to continue tailing. ## Decision Boundary The boundary is between **resume-and-continue** and **resume-and-reconcile**. The client crosses into reconcile-mode the moment any of the following holds at reconnect: - The presented `Last-Event-ID` is not acknowledged by a first replayed event whose ID equals the *next* expected ID in the client's ledger (i.e., the server did not start exactly where the client stopped). - The first event after the cursor is not causally implied by the client's outstanding-call set (a result for an unknown call, or a `session_resumed` without a `replayed_from` field matching the cursor). - The server's declared retention window is shorter than the elapsed disconnect time. - Heartbeats resume but no event addresses any outstanding tool call within a bounded grace period. On the reconcile side, the client must not simply retry. It must issue an explicit `query_call_status(idempotency_key)` (or equivalent) per outstanding call and branch: `executed` → synthesize the missing result locally from the status payload; `not_executed` → safe to re-issue; `unknown` → escalate, do not mutate. The decision boundary is precisely the point where "wait for the stream to catch up" ceases to be a valid strategy and "ask the server what actually happened" becomes mandatory. The anti-pattern to name explicitly: treating a `200 OK` on a resumed SSE connection as evidence of log continuity. HTTP success describes the *transport* reconnection; it says nothing about *event* continuity. These are independent invariants and the client must check the second one itself. ## Operational Effect The operational consequence is that streamable-session resumption must be implemented as a **two-phase protocol** on the client: (1) transport resume, then (2) ledger reconciliation gated on a verifiable continuity check. Clients that collapse these into one phase—treating a successful reconnect as a successful resume—will, under log eviction or continuation-fallback servers, silently lose tool results, duplicate mutations on retry, and accept results for calls they never issued. The failure is invisible to transport-level monitoring (the socket is healthy) and invisible to naive application-level monitoring (no exception is raised; the agent simply stalls or double-writes). It is only visible to a ledger invariant that compares issued-call IDs against received-result IDs and asserts set containment in both directions. The guardrail is therefore not a retry policy but a **continuity assertion**: on every resume, before processing any replayed event, the client asserts that the server's first event ID is exactly the successor of its cursor, and raises a hard, non-retryable error if not—forcing the session into explicit reconciliation rather than letting it tail a forked history. ```python from __future__ import annotations from dataclasses import dataclass, field class StreamForkError(RuntimeError): """Raised when a resumed SSE stream cannot be proven continuous with the client ledger.""" @dataclass class SessionLedger: cursor: str | None = None issued_calls: set[str] = field(default_factory=set) received_results: set[str] = field(default_factory=set) retention_seconds: int = 60 disconnect_elapsed_seconds: int = 0 def assert_resume_continuity( ledger: SessionLedger, first_replayed_event_id: str | None, expected_next_event_id: str | None, server_declared_replay: bool, ) -> None: # Condition 1: server must implement replay, not continuation-tail. if not server_declared_replay: raise StreamForkError( "server does not declare replay semantics; a 200 on reconnect " "cannot be treated as event continuity" ) # Condition 2: retention window must exceed the disconnect window. if ledger.disconnect_elapsed_seconds >= ledger.retention_seconds: raise StreamForkError( f"disconnect {ledger.disconnect_elapsed_seconds}s >= retention " f"{ledger.retention_seconds}s; event log may have been evicted and " "server may have silently tailed from a newer position" ) # Condition 3: the first replayed event must be the exact successor of the cursor. if first_replayed_event_id != expected_next_event_id: raise StreamForkError( f"resume forked: expected first event {expected_next_event_id!r}, " f"got {first_replayed_event_id!r}; history diverged at cursor " f"{ledger.cursor!r}" ) def reconcile_result(ledger: SessionLedger, result_call_id: str) -> None: # A result for a call the client never issued is a hard violation, # not a recoverable anomaly: the server replayed a suffix we did not produce. if result_call_id not in ledger.issued_calls: raise StreamForkError( f"received tool_result for unissued call {result_call_id!r}; " "server replayed events from a forked history" ) ledger.received_results.add(result_call_id) def close_session(ledger: SessionLedger) -> None: outstanding = ledger.issued_calls - ledger.received_results if outstanding: raise StreamForkError( f"session closed with unresolved calls {sorted(outstanding)}; " "must reconcile via query_call_status before abandoning session" ) ```