# What structural signals indicate a resumable MCP tool-call stream has silently forked its replay cursor across a multiplexed HTTP session **Date of Record:** 2026 November 27 **Scope:** Applies to HTTP-native MCP servers that multiplex multiple client sessions over a shared listener and expose resumable tool-call streams via a monotonic `event_id`/`Last-Event-ID` cursor. Does not apply to stdio transports, single-session servers, or to non-resumable request/response MCP invocations where each tool call is fully atomic and stateless. ## Core Distinction The failure is *not* "a stream disconnected and had to resume." That is the designed path. The failure is that a resumed stream **reattached to the wrong logical cursor lineage** while every observable signal—HTTP status, `200 OK`, event IDs that are monotonically increasing, tool results that parse cleanly—indicated a healthy resume. The distinguishing fact is that the resumed stream's cursor is *valid but not identical* to the pre-disconnect cursor: it is a sibling branch produced by a second delivery attempt of the same `event_id`, and the client has no way to tell from the wire that it has forked. The invariant that breaks is: **one logical tool-call attempt must map to exactly one cursor lineage, and a resume must continue that lineage rather than replay a divergent copy of it.** Under multiplexing with per-session backpressure, the server can hold *two* pending deliveries for the same `event_id`—one blocked on a slow session's backpressure gate, one produced by a retry after the client's timeout—and only one of them will be committed to the durable log. Which one wins is a race. ## What Was Observed A multiplexed MCP server (single HTTP listener, `N` concurrent sessions, each session an independent SSE-like stream over `POST /mcp` with `Last-Event-ID` resume) serving a `run_shell`-class tool with a 90s server-side execution budget. A client session stalled at the backpressure gate: its TCP receive window collapsed, the per-session outbound queue hit its high-water mark, and the writer goroutine blocked on `write()` rather than draining the durable event log. The client's own transport timeout fired at 60s and issued a resume with `Last-Event-ID: evt_1041`. Because the original delivery for `evt_1041` had never been *acknowledged* (it was still blocked in the socket buffer), the server's resume handler did not find `evt_1041` in the session's committed-cursor map and treated the resume as a request to replay from the last *committed* cursor, `evt_1040`. It re-executed the tool call bound to `evt_1041`—a non-idempotent shell command—producing `evt_1041'`. Meanwhile the original writer goroutine, still blocked, eventually flushed and committed `evt_1041` to the durable log. Structural signals present at the moment of fork: - **Duplicate `event_id` with divergent payloads** in the durable log: `evt_1041` (original, committed late) and `evt_1041'` (replay, committed first). Both monotonic, both valid-looking. - **`Last-Event-ID` echo mismatch**: the resume response's first event carried `id: evt_1041` but a `result` hash that did not match the client's cached hash for `evt_1041`. The client's resume logic did not compare hashes—it trusted the ID. - **Session cursor drift**: the session's committed-cursor map advanced to `evt_1041'` while the durable log's authoritative high-water mark was `evt_1041`. The two diverged by one event and never re-converged. - **Backpressure gate still occupied**: the original writer goroutine had not yet released its slot, so the session was simultaneously holding a stale in-flight delivery and a fresh committed cursor. - **No `409`/`412` precondition failure**: the server returned `200` for the resume because it had a *plausible* cursor to replay from. The conflict was invisible at the HTTP layer. The tool call executed twice. The second execution's side effects (a file write) were committed under `evt_1041'`; the first execution's side effects (a directory mutation) committed under `evt_1041`. Neither client nor server could reconstruct which was authoritative from the stream alone. ## Condition of Validity The fork is only possible when **all** of the following hold simultaneously: 1. **Delivery is decoupled from commit.** The server writes to the durable log and to the socket independently, so a `write()` block does not prevent the log from advancing—or, symmetrically, a log commit does not guarantee socket flush. 2. **Resume keys on the client's `Last-Event-ID`, not on a server-issued delivery receipt.** The client's cursor is a *claim* about what it received, not a *proof*. A blocked-but-not-lost delivery is indistinguishable from a lost one from the client's vantage. 3. **The tool call bound to the in-flight event is non-idempotent or has observable side effects.** If the tool were pure, replay would be harmless and the fork would be a non-event. 4. **The per-session backpressure gate holds the writer without evicting the pending event from the replay window.** If backpressure evicted the in-flight event (marking it "not resumable, re-issue"), the resume would be forced to a *new* cursor rather than a replayed one, and the fork would be structurally prevented. If any one condition is absent, the failure degrades to a clean retry or a clean disconnect. The dangerous case is precisely the conjunction: backpressure that *retains* the event in the replay window while the client times out and resumes. ## Decision Boundary The operational boundary is the choice of **what `Last-Event-ID` means**: - **Claim semantics (broken):** `Last-Event-ID` is the client's assertion of its last received event. The server replays from the next committed event. Under backpressure, the "next committed event" may be a divergent sibling of the event the client actually last saw. This is the default in most SSE-style implementations and it is unsafe for non-idempotent MCP tools. - **Receipt semantics (safe):** `Last-Event-ID` is a *server-issued delivery receipt* (a signed or HMAC'd token binding `event_id` to a payload hash and a session nonce). The server rejects any resume whose receipt does not match a committed event's hash, returning `412 Precondition Failed` and forcing a fresh cursor. The fork becomes impossible because the divergent sibling's hash will not match the client's receipt. The boundary is crossed when the server's resume handler **cannot distinguish "client never received `evt_1041`" from "client received `evt_1041` but its receipt was lost in the backpressure queue."** Any design that cannot make this distinction must either (a) forbid non-idempotent tools on resumable streams, or (b) issue receipts. A secondary boundary: **the backpressure high-water mark must be strictly less than the replay window depth.** If the gate can hold more pending deliveries than the replay window can retain, the oldest pending delivery will be evicted while still in flight—producing a resume that silently skips an event rather than forking it. That is a *different* failure (gap, not fork) but shares the same root cause: delivery/commit decoupling. The guardrail is `HWM < replay_window_depth` enforced at session admission. ## Operational Effect Downstream of the fork, the session's cursor lineage is permanently ambiguous. Every subsequent resume from that session will replay from `evt_1041'`, but the durable log's authoritative chain is `...evt_1040 → evt_1041`. The client's local state (derived from `evt_1041'`) and the server's canonical state (derived from `evt_1041`) disagree on a non-idempotent side effect. Reconciliation requires out-of-band inspection of the tool's actual side effects—the stream cannot self-heal. The practical consequences: - **Silent duplicate side effects** on any non-idempotent tool bound to an event that was in-flight during backpressure. Logs show one `event_id`, two executions. - **Cursor divergence that survives reconnection**: the session's committed-cursor map is per-session state, so a new session starts clean—but any client-side cache keyed on `event_id` is now poisoned. - **Auditor disagreement**: if a verification agent replays the stream from the durable log and a peer replays from its receipt chain, they will disagree on the state at `evt_1041`, and neither is wrong by its own rules. This is the multi-agent manifestation: consensus protocols that assume a single event chain will deadlock or split. The guardrail that bounds the damage is **receipt-bound resume with hash verification at the server**, plus **non-idempotent tool calls requiring an explicit `attempt_id` that the server deduplicates across replay**. Without both, the fork is reachable and undetectable from the wire. ```python import hashlib import hmac class CursorForkError(RuntimeError): """Raised when a resumable MCP stream's replay cursor diverges from the durable log's authoritative lineage under multiplexed backpressure.""" class DeliveryReceipt: def __init__(self, event_id: str, payload_hash: str, session_nonce: str, mac: str): self.event_id = event_id self.payload_hash = payload_hash self.session_nonce = session_nonce self.mac = mac def issue_receipt(event_id: str, payload: bytes, session_nonce: str, key: bytes) -> DeliveryReceipt: payload_hash = hashlib.sha256(payload).hexdigest() mac = hmac.new( key, f"{event_id}:{payload_hash}:{session_nonce}".encode(), hashlib.sha256, ).hexdigest() return DeliveryReceipt(event_id, payload_hash, session_nonce, mac) def resume_stream( last_event_id: str, client_receipt: DeliveryReceipt, durable_log: dict[str, bytes], session_nonce: str, key: bytes, backpressure_hwm: int, replay_window_depth: int, ) -> str: # Invariant 1: backpressure must not outrun the replay window, or the # in-flight delivery can be evicted while a resume is still possible. if backpressure_hwm >= replay_window_depth: raise CursorForkError( f"backpressure_hwm={backpressure_hwm} >= replay_window_depth=" f"{replay_window_depth}: in-flight deliveries can be evicted mid-resume" ) # Invariant 2: the client's receipt must bind event_id to a payload hash # the server actually committed. A claim-only Last-Event-ID is insufficient. if client_receipt.session_nonce != session_nonce: raise CursorForkError( f"receipt session_nonce mismatch for {last_event_id}: " "receipt belongs to a different session lineage" ) committed = durable_log.get(last_event_id) if committed is None: raise CursorForkError( f"resume cursor {last_event_id} not in durable log: " "client claims an event the server never committed" ) expected_mac = hmac.new( key, f"{last_event_id}:{client_receipt.payload_hash}:{session_nonce}".encode(), hashlib.sha256, ).hexdigest() if not hmac.compare_digest(expected_mac, client_receipt.mac): raise CursorForkError( f"receipt MAC invalid for {last_event_id}: forged or stale receipt" ) actual_hash = hashlib.sha256(committed).hexdigest() if actual_hash != client_receipt.payload_hash: # This is the fork: the client holds a receipt for a payload the log # does not contain at this event_id. A divergent sibling was committed. raise CursorForkError( f"payload hash divergence at {last_event_id}: " f"client={client_receipt.payload_hash[:12]} log={actual_hash[:12]} — " "replay cursor has forked; refusing to resume" ) # Receipt matches committed payload: safe to continue the lineage. return last_event_id ```