# What structural signals indicate an MCP streamable-HTTP session has silently forked during resumption, and how to bound it **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers/clients using the HTTP-native "streamable" transport with SSE event streams, `Mcp-Session-Id` headers, and `Last-Event-ID`-based resumption. Does not apply to stdio transports, nor to pure request/response MCP without streaming. ## Core Distinction The distinction that matters is between **transport-level resumption** and **session-level continuity**. The MCP streamable-HTTP transport lets a client reconnect a dropped SSE stream by presenting `Last-Event-ID`, and the server is expected to replay events after that ID. This is a *byte-position* resumption contract. It is **not** a *state* contract. A server can faithfully honor `Last-Event-ID` — replaying every event the client missed — while the agent's logical task has already forked, because the server processed a tool call the client never saw the result of, and the client, on reconnect, re-issued it. The invariant that is silently violated is: *one logical tool invocation must map to exactly one server-side effect.* Resumption preserves the event log, not the effect ledger. The failure is non-obvious because every observable signal at the transport layer looks healthy: the stream reconnects, the event IDs are monotonic, replay succeeds, no 4xx/5xx. The fork is invisible until a side-effecting tool (a write, a payment, a message send) executes twice. ## What Was Observed A representative trace. The client holds a stream with session `S1`, last delivered event `evt-1042` (a `tools/call` request for `write_record`). The TCP connection drops mid-flight — after the server has *dispatched* the tool but before the `tools/call` result event `evt-1043` is flushed to the client. The server, per its own semantics, has already executed the write. The client reconnects with `Mcp-Session-Id: S1` and `Last-Event-ID: evt-1042`. Two divergent server behaviors are both "compliant": 1. **Replay-correct, effect-duplicating:** The server replays `evt-1043` (the original result). The client, having no record that it ever sent the call, may still re-issue it because its own outbound queue was not durable — the request was in an in-memory buffer that died with the socket. Now the write runs twice. 2. **Replay-gapped, effect-orphaned:** The server's replay buffer was bounded (say 500 events, or a 60s TTL). `evt-1043` has aged out. The server resumes from the *next available* event `evt-1100`. The client never learns the result of `evt-1042`'s call. Its agent loop sees a gap in the event sequence and — depending on its reasoning policy — either stalls waiting for a result that will never arrive, or re-plans and re-issues the call. Both paths converge on the same structural defect: **the client cannot distinguish "my request was never received" from "my request was received and executed but the result was lost."** That ambiguity is the fork point. The agent's reasoning layer treats an absent result as an absent action, and re-plans accordingly. A second-order signal appeared in multi-agent setups: when the same `Mcp-Session-Id` is resumed from two clients (a retry storm after a load-balancer flap), the server multiplexes both onto one logical session. Event IDs stay monotonic, but the *interleaving* now reflects two independent reasoning traces sharing one replay cursor. `Last-Event-ID` from client B advances the cursor past events client A has not consumed, so A's next resume skips them. ## Condition of Validity The guardrail below is valid only under these conditions, and must be treated as void outside them: - The server is the **sole authority** on effect execution; clients do not execute side effects directly. - Every `tools/call` carries a client-generated **idempotency key** (a UUID minted before the request enters the outbound queue, persisted to durable storage *before* send, not after). - The server maintains an **effect ledger** keyed by idempotency key, independent of the replay buffer, with a TTL strictly longer than the maximum client resume window. - The replay buffer and the effect ledger are **separate stores** with separate eviction policies. Conflating them is the root cause; the guardrail is meaningless if the ledger is evicted on the same schedule as the buffer. - Resumption is **single-consumer per session**. If a session may be resumed by more than one client, the effect ledger must additionally carry a per-consumer cursor, or the session must be fenced (see below). If the server cannot guarantee these, the only safe posture is to treat every resumed session as potentially forked and force a full reconciliation before any further side-effecting call. ## Decision Boundary The boundary is a single predicate evaluated on resume, before the agent loop is allowed to re-plan: ``` forked := (highest_contiguous_event_id_seen < last_acknowledged_event_id) OR (any in-flight idempotency_key has no terminal ledger entry) OR (resume_cursor_advanced_by_another_consumer) ``` - If `forked` is false, resume normally: replay from `Last-Event-ID`, continue. - If `forked` is true because of a **gap** (event IDs skipped), the client must NOT re-issue in-flight calls. It must first query the effect ledger by idempotency key. A ledger hit with a terminal status means the effect happened; the client reconstructs the result from the ledger and advances. A ledger miss means the effect did not happen; only then may it re-issue — with the *same* idempotency key, so a concurrent duplicate is collapsed server-side. - If `forked` is true because of **concurrent consumers**, the session is fenced: the resuming client must present a fencing token (monotonic per session) and the server must reject any event emission to a client holding a stale token. The agent must treat a fenced session as a new session with a fresh reasoning context, not a continuation. The critical asymmetry: a gap is *not* permission to re-plan. It is a signal to *reconcile against the ledger first*. Re-planning on a gap is exactly the reasoning-layer error that turns a transport hiccup into a duplicated effect. ## Operational Effect With the ledger-based reconciliation gate in place, the observable behavior changes in three ways: 1. **Duplicate suppression becomes structural, not probabilistic.** The agent no longer relies on "the result probably means it worked." It queries the ledger. Duplicate side effects drop to zero for calls that reached the server, even across replay-buffer eviction. 2. **The agent loop gains a defined stall state.** Instead of an unbounded wait for a result that will never replay, a gap forces a bounded reconciliation call with its own timeout. The loop either resumes with a reconstructed result or aborts the task with a typed error — never silently re-plans. 3. **Fencing surfaces fork attempts.** A second consumer on the same session now produces a deterministic rejection rather than interleaved event corruption. The multi-agent retry storm becomes a visible fencing error instead of a subtle cursor-advance bug. The residual risk is ledger TTL shorter than resume window — if the ledger entry expires before a late resume, the client sees a miss and re-issues, and the duplicate returns. The invariant to hold is `ledger_ttl > max_resume_window + max_agent_reconcile_time`, and to alarm on any resume that arrives after `ledger_ttl - safety_margin`. ```python import time from dataclasses import dataclass, field from typing import Optional class ForkedSessionError(RuntimeError): """Raised when a resumed MCP streamable-HTTP session cannot be proven continuous with the pre-drop logical session.""" pass @dataclass class EffectLedger: # idempotency_key -> terminal status ("done" | "failed") entries: dict = field(default_factory=dict) ttl_seconds: float = 3600.0 written_at: dict = field(default_factory=dict) def record(self, key: str, status: str) -> None: self.entries[key] = status self.written_at[key] = time.time() def lookup(self, key: str) -> Optional[str]: ts = self.written_at.get(key) if ts is None: return None if time.time() - ts > self.ttl_seconds: return None # expired: treat as miss return self.entries.get(key) @dataclass class ResumeState: last_ack_event_id: int last_seen_event_id: int in_flight_keys: list resume_cursor_owner: str # consumer id that last advanced cursor this_consumer: str def reconcile_on_resume(state: ResumeState, ledger: EffectLedger, max_reconcile_deadline: float) -> dict: """ Gate executed before the agent loop may re-plan after a stream resume. Returns reconstructed results for in-flight calls that actually executed. Raises ForkedSessionError when continuity cannot be established. """ deadline = time.time() + max_reconcile_deadline reconstructed = {} # 1. Fencing: another consumer advanced the cursor. if state.resume_cursor_owner != state.this_consumer: raise ForkedSessionError( f"session forked: cursor owned by {state.resume_cursor_owner!r}, " f"resumed by {state.this_consumer!r}; fence required" ) # 2. Gap detection: events were skipped between ack and last seen. gap = state.last_seen_event_id > state.last_ack_event_id + len(state.in_flight_keys) if not gap and not state.in_flight_keys: return reconstructed # clean resume # 3. Reconcile every in-flight call against the effect ledger. for key in state.in_flight_keys: if time.time() > deadline: raise ForkedSessionError( f"reconciliation deadline exceeded for key {key!r}" ) status = ledger.lookup(key) if status is None: # Effect never executed: safe to re-issue with the SAME key. reconstructed[key] = {"action": "reissue", "key": key} elif status == "done": reconstructed[key] = {"action": "reconstruct", "key": key, "result": "from_ledger"} else: raise ForkedSessionError( f"in-flight key {key!r} terminated as {status!r}; " f"agent must not re-plan blindly" ) if gap and not reconstructed: raise ForkedSessionError( "event gap with empty ledger: continuity unprovable" ) return reconstructed ```