# What structural signals indicate a resumable SSE stream has silently forked its event log across MCP HTTP-native clients **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers exposing the Streamable HTTP transport with `Last-Event-ID` resumption and per-session fan-out to multiple concurrent clients (e.g., a supervisor agent and its auditors sharing one session). Does not apply to stdio transport, nor to stateless per-request HTTP handlers that never emit `id:` fields on SSE frames. ## Core Distinction There are two ways an MCP Streamable HTTP server can be "resumable," and they are not equivalent: 1. **Event-log resumption** — the server retains a monotonic, per-session sequence of SSE frames keyed by `id:`. A reconnecting client sends `Last-Event-ID: N` and receives exactly frames `N+1, N+2, …`. Replay is *deterministic and complete*. 2. **Stream-position resumption** — the server treats `Last-Event-ID` as a hint, re-opens a fresh generator from "around here," and emits whatever the current tool invocation yields. Replay is *best-effort and lossy*. The boundary failure is that a server can present as (1) under single-client testing and degrade to (2) only under multi-client fan-out, because the per-session event log is a *shared* resource that the fan-out code path mutates. The failure is not a crash and produces no error frame. It produces a **forked event log**: two clients resume from the same `Last-Event-ID` and receive divergent suffixes, and the server has no internal record that the divergence occurred. ## What Was Observed A supervisor agent (client A) opened a session, issued `tools/call` for a long-running `scan_repository` tool, and consumed SSE frames `id: 1` through `id: 40`. A second agent (client B), an auditor, attached to the *same* MCP session via a second HTTP connection to observe the same tool stream — a legitimate fan-out pattern the spec permits when the server advertises session multiplexing. Trigger sequence: - Client A dropped its TCP connection at `id: 40` (mobile network handoff) and reconnected with `Last-Event-ID: 40`. - Client B was still connected, consuming live frames, and had received up to `id: 57`. - The server's fan-out code held a single `asyncio.Queue` per session, drained by whichever consumer read first. Client B had already drained frames 41–57 from the queue. - On Client A's resume, the server looked up "the event log," found the queue *empty* (B had consumed it), and — because the retention buffer was keyed by consumer rather than by session — replayed nothing. It then attached A to the live tail. - Client A received `id: 58` next, with no `id: 41–57`. It did not error. `Last-Event-ID` handling in the client library treated a gap as "server skipped heartbeats" and continued. The structural signal: **Client A's local event-id sequence went `…38, 39, 40, 58, 59…` with an `is_gap` flag it never checked, while Client B's log was contiguous.** The two clients now held divergent views of the same tool invocation's progress. When the tool emitted a final `result` frame at `id: 71` referencing intermediate state established in frames 44–49, Client A's reasoning loop had never seen that state and reconstructed the tool result against a stale premise — producing a downstream `tools/call` with a malformed argument that the server accepted. ## Condition of Validity The invariant that must hold for Streamable HTTP resumption to be sound: > For a given `(session_id)`, the set of frames a client has received, ordered by `id`, must be a *contiguous prefix* of the session's total emitted frame sequence, and this must be true for every attached client independently. The server MUST retain frames long enough to satisfy the *slowest* attached client's resume window, not the fastest consumer's drain rate. This fails precisely when the server conflates **delivery** with **retention**. A queue is a delivery mechanism; it is not a log. The moment the fan-out implementation lets one consumer's read advance the shared cursor past frames another consumer hasn't acknowledged, the invariant is violated. The condition of validity is therefore: *retention buffer is append-only and per-session; per-client cursors are independent; queue drain is a projection over the log, never the log itself.* Note this is distinct from ordinary backpressure. Backpressure drops *new* frames for a slow consumer and signals it. Log forking silently drops *already-emitted* frames for a *reconnecting* consumer, which is unrecoverable because the consumer cannot know what it missed without a sequence check it usually doesn't perform. ## Decision Boundary An agent operating over this transport must decide, on every resumed stream, whether to **trust the server's replay** or **re-derive state from scratch**. The boundary: - If the client can verify contiguity (`last_seen_id + 1 == first_replayed_id`) **and** the server advertises a retention window (`Mcp-Session-Retention` or equivalent) that covers the client's disconnect duration, trust replay. - If contiguity fails, or no retention advertisement exists, the client MUST treat the session's accumulated state as **untrusted** and either (a) re-issue the originating `tools/call` with an idempotency key, or (b) abort the session and renegotiate capabilities from a cold start. Continuing to reason over a gapped stream is the failure. The server-side decision boundary is symmetric: it must reject a resume request whose `Last-Event-ID` is older than its retention floor with an explicit `409`-class MCP error, rather than silently attaching the client to the live tail. Silent attach is the specific implementation choice that converts a recoverable retention miss into an unrecoverable reasoning divergence. ## Operational Effect Downstream, the forked log manifested as a **verification replay discrepancy**: the auditor (Client B) held a complete transcript and validated the tool result as correct; the supervisor (Client A) held a gapped transcript and independently concluded the result was suspect, triggering a redundant re-scan. The two agents, sharing a session, disagreed about ground truth — and neither could detect the disagreement because the transport never surfaced the gap. The cost was a duplicated long-running tool invocation and a supervisor that lost confidence in a correct result. The fix is structural: append-only per-session retention, independent per-client cursors, and a client-side contiguity assertion that fails loudly on gap. ```python class SSEEventLogForkedError(RuntimeError): """Raised when a resumed SSE stream's frame ids are non-contiguous, indicating the server's retention buffer was drained by a fan-out peer and the reconnecting client's replay is incomplete.""" pass class ResumableStreamClient: def __init__(self, retention_window_sec: float, disconnect_sec: float): self.last_seen_id: int = 0 self.retention_window_sec = retention_window_sec self.disconnect_sec = disconnect_sec def resume(self, first_replayed_id: int, frames: list[dict]) -> list[dict]: # Retention must cover the disconnect, or replay is unsound by construction. if self.disconnect_sec > self.retention_window_sec: raise SSEEventLogForkedError( f"disconnect {self.disconnect_sec}s exceeds retention " f"{self.retention_window_sec}s; replay cannot be trusted" ) # Contiguity invariant: first replayed frame must be exactly last_seen + 1. if first_replayed_id != self.last_seen_id + 1: raise SSEEventLogForkedError( f"event log forked: expected id {self.last_seen_id + 1}, " f"server resumed at {first_replayed_id} " f"(gap of {first_replayed_id - self.last_seen_id - 1} frames)" ) # Verify the whole suffix is monotonic and gap-free before accepting. expected = first_replayed_id for frame in frames: if frame["id"] != expected: raise SSEEventLogForkedError( f"non-monotonic replay at id {frame['id']}, expected {expected}" ) expected += 1 self.last_seen_id = expected - 1 return frames ```