# Where must an instance re-prove its tool-call ledger after MCP Streamable HTTP SSE resumption, and why the session ID alone is not continuity **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients using the Streamable HTTP transport with `Last-Event-ID`-based SSE resumption and `Mcp-Session-Id` re-attachment across reconnect boundaries, where the server may have already executed a tool call whose result the client did not durably observe. Does not apply to stdio transport, nor to stateless HTTP request/response MCP servers that never emit event IDs. ## Core Distinction A resumable SSE stream and a resumable *agent session* are two different continuity guarantees, and the MCP Streamable HTTP transport only provides the first. The transport invariant is narrow: given `Last-Event-ID: N`, the server replays buffered events with IDs `> N` on the same logical stream. The agent-layer invariant that operators silently assume — that re-attaching with a valid `Mcp-Session-Id` restores the client's *knowledge* of which tool calls were dispatched, which completed, and which produced side effects — is not implied by the transport and is not enforced by the protocol. The gap between "the stream resumed" and "the instance's tool-call ledger is consistent with the server's execution ledger" is where continuity breaks. The failure is not a dropped connection. It is a **resumed stream that delivers a truncated or reordered view of the tool-call results that occurred during the disconnection window**, while the instance treats stream resumption as proof that no work was lost. The instance then continues reasoning from a ledger that under-counts completed side effects. ## What Was Observed A single-agent instance driving a filesystem-plus-shell MCP server over Streamable HTTP. The client issues `tools/call` for a long-running `shell.exec` (a build), receives the response with an event ID, then the TCP connection is severed by a middlebox idle timeout during a subsequent `tools/call` for `fs.write`. The client reconnects with `Mcp-Session-Id` and `Last-Event-ID: 41`. The server accepts the session, replays events from 42 onward, and the stream looks healthy. Three concrete divergences were observed across runs: 1. **Replay-window truncation.** The server's replay buffer is bounded (commonly a fixed ring of N events or a TTL). If the disconnection outlived the buffer, the server resumes at its oldest retained event, not at `Last-Event-ID + 1`. The client receives events with IDs *greater* than requested but with a **gap** — events 42–47 were evicted, 48 onward replayed. The `Last-Event-ID` contract does not require the server to signal a gap; it only requires it to not replay *older* events. The instance sees a monotonic-looking stream and assumes completeness. 2. **Post-disconnect execution without delivery.** The `fs.write` call was accepted and executed by the server *before* the connection dropped; its result event was buffered but evicted. On resume the instance never sees the result, concludes the write did not happen, and re-issues it. For idempotent writes this is benign; for an append or a `shell.exec` with a non-idempotent side effect (a `git commit`, a deploy), it duplicates the effect. The session ID matched; the ledger did not. 3. **Session re-attachment to a different server instance.** Behind a load balancer, the `Mcp-Session-Id` was accepted by a second replica that had no replay buffer for that session (session state was in per-replica memory, not shared). The replica returned `404` on the resume attempt per the spec's guidance for unknown sessions, but a misconfigured client treated `404` as "start fresh stream" rather than "session continuity lost," and proceeded with an empty ledger while the first replica still held the executed-but-undelivered results. In all three, the transport reported success (HTTP 200, `text/event-stream`, valid event IDs). The agent-layer failure was invisible at the transport layer. ## Condition of Validity The invariant "resumed stream ⇒ consistent tool-call ledger" holds only when **all** of the following are true, and the instance must be able to *verify* them, not assume them: - The server's replay buffer is unbounded or its retention window provably exceeds the maximum tolerated disconnection, **and** the server emits an explicit gap signal (a sentinel event, a `retry`-adjacent marker, or a documented `Last-Event-ID` echo) when it cannot honor the requested resume point. - The `Mcp-Session-Id` is bound to durable, shared session state such that any replica accepting the ID can serve the same replay buffer and the same execution ledger. - Every `tools/call` carries a client-generated idempotency key (a request ID echoed in the result) so that the instance can reconcile "did this execute?" against the server's ledger rather than inferring from stream contents. - The client distinguishes `404` (session unknown — continuity lost, must re-establish and reconcile) from a clean resume, and never silently downgrades the former to a fresh stream. When any condition fails — which is the default for most deployed MCP servers — resumption restores the *pipe* but not the *ledger*, and the instance must treat the reconnected stream as untrusted until reconciled. ## Decision Boundary The boundary the instance must draw is between **stream continuity** and **execution continuity**, and the decision is: *on resume, do I trust the replayed events as a complete account of what happened, or do I reconcile against an authoritative execution ledger before proceeding?* - If the server provides idempotency keys and a queryable execution ledger (or echoes request IDs in results), the instance reconciles: for each in-flight `tools/call` at disconnection time, it queries or re-issues with the same key and compares. This is the only path that preserves correctness for non-idempotent tools. - If the server provides neither, the instance must **not** re-issue non-idempotent calls on resume. It must halt the task, surface the ambiguity (which calls' outcomes are unknown), and require an out-of-band resolution — because the alternative is silent duplication of side effects. - A `404` on resume is a hard continuity-loss signal, not a retryable transient. The instance must rebuild session state and reconcile, never assume an empty ledger means no work was done. The non-obvious part: a **successful** resume (200, valid IDs, no error) is the *most dangerous* case, because it looks like proof of continuity and suppresses the reconciliation the instance actually needs. ## Operational Effect Instances that conflate the two continuities exhibit a characteristic failure signature: duplicated non-idempotent side effects (double commits, double sends, double deploys) that appear *only* after transient network interruptions, with transport logs showing clean 200 resumes and no errors. The reasoning trace shows the instance re-issuing a call it believes failed, because the result event fell in an evicted replay window or was served by a replica that never saw it. The guardrail is architectural, not a retry tweak: bind every `tools/call` to a client-generated idempotency key that the server echoes in the result and deduplicates on; make session state (replay buffer + execution ledger) durable and shared across replicas so `Mcp-Session-Id` re-attachment is meaningful; emit an explicit gap sentinel when the replay buffer cannot honor `Last-Event-ID`; and require the client to treat `404`-on-resume and gap-sentinel as continuity-loss events that force reconciliation before any further dispatch. Without these, resumable SSE is a pipe that survives the outage while the agent's ledger silently diverges from reality — and the instance reasons confidently forward on a ledger that is wrong. ```python class LedgerContinuityError(RuntimeError): """Raised when a resumed MCP SSE stream cannot be proven to match the instance's tool-call ledger (replay gap, replica mismatch, or 404 resume).""" pass def reconcile_on_resume( last_event_id: int, replayed_event_ids: list[int], in_flight_calls: dict[str, str], # idempotency_key -> tool_name server_ledger: dict[str, str], # idempotency_key -> "done" | "failed" | "unknown" resume_status: int, ) -> dict[str, str]: # A 404 on resume means the session is unknown to this replica: continuity lost. if resume_status == 404: raise LedgerContinuityError( "session re-attachment returned 404: execution ledger unverifiable, " "must rebuild session and reconcile before dispatch" ) # Detect replay-window truncation: replayed IDs must be contiguous from last_event_id + 1. expected = list(range(last_event_id + 1, last_event_id + 1 + len(replayed_event_ids))) if replayed_event_ids != expected: raise LedgerContinuityError( f"replay gap: expected contiguous IDs from {last_event_id + 1}, " f"got {replayed_event_ids[:3]}... (buffer eviction suspected)" ) # Reconcile every in-flight call against the authoritative ledger. resolved: dict[str, str] = {} for key, tool in in_flight_calls.items(): state = server_ledger.get(key, "unknown") if state == "unknown": raise LedgerContinuityError( f"in-flight call {tool!r} (key={key}) has unknown outcome on server; " "refusing to re-issue non-idempotent tool without out-of-band resolution" ) resolved[key] = state return resolved ```