# What happens when an instance resumes an MCP stream after a crash mid-`notifications/tools/list_changed` and replays a stale session **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers using the HTTP-native transport (Streamable HTTP / `text/event-stream` with `Mcp-Session-Id` and `Last-Event-ID` resumption) where a client agent's process dies or its TCP connection is severed mid-stream and it attempts to resume with a persisted session ID. Does not cover stdio transport, does not cover clean client-initiated `DELETE`-based session teardown, and does not cover servers that treat every request as stateless. ## Core Distinction The HTTP-native MCP transport exposes two independent continuity mechanisms that are routinely conflated: **session continuity** (the `Mcp-Session-Id` header, which binds server-side state to a client identity) and **event-stream continuity** (the SSE `id:` field plus `Last-Event-ID` on resume, which binds a *position in a notification sequence* to a resumption request). A resumed session that carries a valid `Mcp-Session-Id` but a `Last-Event-ID` the server can no longer honor is not a "resumed session." It is a **new stream grafted onto an old session**, and the server silently decides — per its own retention policy — whether to replay from the beginning, drop the gap, or reject. The non-obvious failure lives in the gap between those two decisions. The client believes it has a continuous view because the session ID matched. The server believes it has satisfied the client because it returned `200 OK` and an event stream. Neither side notices that a `notifications/tools/list_changed` event — the one that invalidates the client's cached tool schema — fell into the retention window and was never replayed. The client then issues `tools/call` against a schema the server has already retired. ## What Was Observed A client agent maintained a long-lived SSE stream to an MCP server exposing a tool set that mutated on deploy (tools added/removed, input schemas revised). The client persisted `{session_id, last_event_id}` to disk after every event to survive process restarts. On crash-and-resume, the client reconnected with `Mcp-Session-Id: ` and `Last-Event-ID: `. The failure trace, over three deploys: 1. **Event `id: 4471`** — `notifications/tools/list_changed`. Server pushes it; client's SSE reader buffers it but the process is killed before the handler runs and before `last_event_id` is persisted. Persisted value remains `4470`. 2. **Server-side retention** — the server keeps a bounded replay buffer (e.g., last 256 events, or 60 seconds). By the time the client resumes, `4471` has been evicted. The server's resumption logic finds `Last-Event-ID: 4470` outside the buffer. 3. **Server behavior on out-of-buffer resume** — this is where implementations diverge, and all three are spec-permissible: - **Replay-from-start:** server sends the entire current event log. Client re-processes `4471` (fine) but also re-processes every prior `list_changed` and, critically, may re-apply state transitions out of order relative to its own post-crash actions. - **Drop-gap:** server resumes from the *oldest retained* event, silently skipping `4471`. Client never learns its tool cache is stale. - **Reject-and-reset:** server returns `404` (session gone) or a fresh stream with no replay. Client's `last_event_id` is now meaningless but the client keeps the old `session_id`. 4. **Divergence materializes** — the client calls `tools/call` for a tool whose input schema was revised in the same deploy that emitted `4471`. The server validates against the *new* schema. The call fails with a schema-validation error that the client's reasoning loop interprets as a transient tool fault, not a stale-cache fault. The agent retries, re-fails, and burns its token budget on a loop that cannot converge because the *cause* (a missed invalidation) is invisible to it. The tell: the client's persisted `last_event_id` was `4470`, the server's oldest retained event was `4472`, and the tool schema the client held was from before the deploy. Nothing in the transport layer reported the gap. `200 OK` is not a continuity guarantee. ## Condition of Validity The gap-silently-dropped failure requires all of the following to hold simultaneously: - The server uses a **bounded** replay buffer (time- or count-based). Unbounded servers replay-from-start and convert this failure into a different one (duplicate/out-of-order application), not a silent gap. - The client persists `last_event_id` **at-least-once but not atomically with event processing** — i.e., it can persist an ID for an event it has not finished handling, or fail to persist an ID for an event it has received. This is the normal case; truly atomic "process-then-persist" is rare because processing is async. - The server's out-of-buffer policy is **drop-gap or reject-without-invalidation**, not "force full resync." A server that responds to out-of-buffer resume by emitting a synthetic `list_changed` for *all* mutable state is immune. - The missed event is a **state-invalidating notification** (`tools/list_changed`, `resources/list_changed`, `prompts/list_changed`) rather than a pure data event. Data events that are dropped cause a visible missing result; invalidation events that are dropped cause an *invisible* stale cache. If the server is stateless, or the client re-fetches `tools/list` on every `tools/call`, or the buffer is unbounded, this specific mechanism does not fire — a different one does. ## Decision Boundary The load-bearing invariant is: **a session ID match does not imply event-stream continuity, and an event-stream resume that cannot honor `Last-Event-ID` must be treated by the client as a full cache invalidation, not as a continuation.** Concretely, the client must branch on the *server's actual resumption behavior*, not on the `200` status: - If the server's first replayed event ID is **greater than** `last_event_id + 1`, the client MUST assume a gap and re-fetch all list-type state (`tools/list`, `resources/list`, `prompts/list`) before issuing any dependent call. Treat the gap as a `list_changed` storm. - If the server returns a **new** `Mcp-Session-Id` in the response (session reset), the client MUST discard its entire persisted cache, not just the event position. - If the server returns `404`/`410` on resume, the client MUST re-initialize (`initialize` handshake) and re-fetch, never reuse the old session ID. The boundary is: **the client owns the obligation to detect the gap; the server is not required to announce it.** The MCP transport spec permits servers to drop un-replayable events silently, so a client that trusts `200 OK` as continuity proof has an unbounded stale-cache window equal to its own crash-to-resume latency. The guardrail is a **resume-time reconciliation step**: on any resume where the first observed event ID is not exactly `last_event_id + 1`, the client marks every mutable server-side list as dirty and re-fetches before the next `tools/call`. This is cheap (one round trip) and bounds the stale window to a single reconciliation, regardless of buffer policy. ## Operational Effect Without the reconciliation step, the observable effect is a **silent, non-converging tool-call loop**: the agent retries a call whose schema it holds stale, the server rejects against the current schema, and the agent's error-handling logic classifies the rejection as a transient fault rather than a cache fault. Because the rejection is deterministic, retries never succeed; because the cause is a missed notification, no error message points at the cache. Token budget drains at the retry rate until a hard limit or an external timeout fires. The agent does not "fail" in a way that surfaces the real cause — it fails as if the tool were broken. With the reconciliation step, the resume costs one extra `tools/list` round trip and the loop never forms. The invariant to encode in the client: **resume is not continuation; a gap in the event stream is a cache-invalidation event even if the server never sent one.** ```python import json from dataclasses import dataclass class StreamResumeGapError(RuntimeError): """Raised when an MCP SSE resume cannot prove event-stream continuity.""" pass @dataclass class PersistedStreamState: session_id: str last_event_id: int def reconcile_resume( persisted: PersistedStreamState, first_replayed_event_id: int, server_session_id: str, fetch_tools_list, ) -> dict: """ Enforce the invariant: a session-ID match is NOT event-stream continuity. If the first replayed event ID is not exactly last_event_id + 1, or the server handed back a different session, the client MUST treat all mutable list state as dirty and re-fetch before any dependent tools/call. """ session_reset = server_session_id != persisted.session_id gap = first_replayed_event_id != persisted.last_event_id + 1 if session_reset: # New session grafted onto old identity: full cache discard. tools = fetch_tools_list(server_session_id) return {"session_reset": True, "gap": True, "tools": tools} if gap: # Silent drop-gap or replay-from-start: re-fetch to bound staleness. tools = fetch_tools_list(server_session_id) if first_replayed_event_id < persisted.last_event_id: raise StreamResumeGapError( f"server replayed event {first_replayed_event_id} older than " f"persisted {persisted.last_event_id}; ordering violated, " f"refusing to trust stream" ) return {"session_reset": False, "gap": True, "tools": tools} # Exact continuation: cache is provably current up to last_event_id. return {"session_reset": False, "gap": False, "tools": None} def guarded_tools_call( persisted: PersistedStreamState, first_replayed_event_id: int, server_session_id: str, fetch_tools_list, tool_name: str, arguments: dict, invoke, ): recon = reconcile_resume( persisted, first_replayed_event_id, server_session_id, fetch_tools_list ) if recon["gap"] and recon["tools"] is None: raise StreamResumeGapError( "resume reported a gap but no refreshed tool schema was produced; " "refusing to issue tools/call against a possibly stale schema" ) schema = None if recon["tools"] is not None: schema = next((t for t in recon["tools"] if t["name"] == tool_name), None) if schema is None: raise StreamResumeGapError( f"tool {tool_name!r} absent from reconciled tools/list; " f"client cache was stale across resume" ) return invoke(server_session_id, tool_name, arguments, schema) ```