# When must an instance refuse to resume an MCP streamable-session after SSE reconnection instead of replaying buffered events **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers exposing the HTTP-native "streamable" transport with server-initiated SSE channels and `Last-Event-ID` resumption, and to client agents that persist session identifiers across reconnect. Does not apply to stdio transports, to pure request/response HTTP without SSE, or to stateless one-shot tool invocations with no server-initiated channel. ## Core Distinction There are two structurally different things a reconnecting agent can do with a streamable MCP session, and they are routinely conflated: 1. **Transport resumption** — re-establishing the SSE channel and asking the server to replay events from `Last-Event-ID`. This restores bytes on the wire. 2. **Semantic resumption** — asserting that the agent's local model of session state (which tool calls are in flight, which notifications were consumed, which server-initiated requests were answered) is still valid after the gap. The boundary failure is this: a successful transport resumption is treated as proof of semantic resumption. It is not. The server can faithfully replay every buffered SSE event after `Last-Event-ID` and the agent can still be semantically diverged, because the events that matter for correctness are not the ones that were buffered — they are the ones the server *dropped* under its retention policy, and the ones the agent *acted on* before the connection died but whose effects the server never observed. The invariant that must hold before replay is accepted: **the agent's last acknowledged event ID must be ≤ the server's earliest retained event ID, and the agent must hold no un-acknowledged server-initiated requests whose responses were lost in the gap.** If either clause fails, replay is a lie dressed as recovery. ## What Was Observed An agent instance maintained an MCP streamable session against a server that pushed server-initiated `sampling/createMessage` requests and `notifications/tools/list_changed` over the SSE channel. The agent persisted `session_id` and `last_event_id` to durable storage at each event boundary. The failure trace: 1. The agent received event `id=4471`, a `notifications/tools/list_changed`. It began a `tools/list` refresh and persisted `last_event_id=4471` only *after* the refresh completed — a write-after-work ordering. 2. The SSE connection dropped mid-refresh (proxy idle timeout, ~30s). The refresh's `tools/list` response was lost on the same dead socket. 3. The agent reconnected with `Last-Event-ID: 4471`. The server, per its retention window, had already evicted events `4472–4490` (a burst of tool-list churn plus one `sampling/createMessage` request). Its earliest retained ID was `4491`. 4. The server replayed from `4491` and — critically — did **not** signal that a gap existed. The streamable transport spec permits replay from the earliest retained event; it does not mandate a gap marker. The agent saw a contiguous-looking stream starting at `4491`. 5. The agent's local tool registry was now a stale snapshot from before `4471`'s refresh (which never completed), missing the mutations in `4472–4490`. It then issued a tool call against a tool name that had been removed in that gap, and separately never answered the `sampling/createMessage` at ~`4480`, leaving the server's request pending until its own timeout and a `notifications/cancelled`. The observable symptom was not a transport error. The transport reported healthy. The symptom was a tool-not-found error three steps downstream, plus a server-side cancelled sampling request, both of which the agent initially attributed to the tool implementation rather than to the session gap. The non-obvious part: **the agent's `last_event_id` was not wrong.** It correctly recorded `4471`. The bug was that the *server's* retention floor had advanced past it, and neither side compared the two numbers. Resumption succeeded at the transport layer precisely because the server was willing to resume from a floor above the client's cursor — which is exactly the condition under which it should have refused. ## Condition of Validity Replay-based resumption is valid only when all of the following hold at the moment of reconnect: - **Floor check:** the client's `last_event_id` ≥ the server's earliest retained event ID. If the server cannot attest to its floor, the client must assume the floor is above its cursor. - **Acknowledgement completeness:** every server-initiated request the client received before the gap has either a sent response the client is certain was flushed, or is recorded as *unanswered* and will be re-driven (not silently abandoned). - **Idempotent re-derivation:** any work the client started in response to an event (e.g., a `tools/list` refresh) is either replayed from scratch on reconnect or is known to have committed. Partial work keyed to a lost event is invalid. - **Monotonic cursor persistence:** `last_event_id` is persisted *before* the side effect is attempted, not after, so a crash mid-effect leaves the cursor behind the effect, forcing re-execution rather than skipping it. If the floor check cannot be satisfied, replay is not a recovery mechanism — it is a state-corruption vector. The correct action is to treat the session as dead and re-initialize. ## Decision Boundary The decision is not "reconnect or don't." It is a three-way branch on the gap: - **Gap = 0 (contiguous):** replay normally; process replayed events as if live. - **Gap > 0 but floor ≤ cursor (server retained everything since cursor):** replay is safe *only if* the client re-drives any in-flight work. Replay the events, but do not trust local state derived from work started before the gap; re-issue the `tools/list` and re-answer any pending server requests, deduplicating by request ID. - **Floor > cursor (server evicted past the cursor):** refuse resumption. Do not process the replayed tail as continuous. Emit a session-reset, re-run `initialize`, re-fetch `tools/list` unconditionally, and re-establish server-initiated request expectations from zero. Any buffered tail from the new stream must be discarded until a fresh `initialize` completes, because the tail is a suffix of a history the agent never saw. The boundary is sharp and numeric: `floor > cursor` is the refuse condition. Everything else is a re-drive condition. There is no "probably fine" middle. ## Operational Effect Agents that skip the floor check exhibit a characteristic failure signature: healthy transport metrics, stale tool registries, unanswered server-initiated requests that surface as server-side timeouts, and downstream errors that look like tool bugs. The errors are *delayed and misattributed* — they appear one to three tool calls after the reconnection, in a different subsystem than the one that actually diverged. The architectural guardrail is to make the floor check a hard precondition on any replay and to persist the cursor before the side effect. This converts a silent corruption into a loud, bounded reset. The cost is a full re-initialization on eviction; the benefit is that the agent never operates on a tool registry or request ledger that is a suffixed fragment of a history it did not observe. For server-initiated requests specifically, the rule is that a request received before a gap and not provably answered before the gap is *unanswered*, and must be re-driven or explicitly cancelled — never assumed handled. ```python from dataclasses import dataclass class SessionResumptionRefused(RuntimeError): """Raised when replay would resume from above the client's cursor.""" @dataclass class ReconnectState: client_last_event_id: int server_earliest_retained_id: int unanswered_server_requests: list def resume_streamable_session(state: ReconnectState) -> str: """ Decide whether an MCP streamable-session reconnect may accept replay. Returns a decision token. Raises SessionResumptionRefused when the server's retention floor has advanced past the client cursor, because replaying from above the cursor would present a suffixed fragment of history as if it were continuous. """ if state.client_last_event_id < 0: raise SessionResumptionRefused( f"invalid client cursor {state.client_last_event_id}" ) # Hard refuse condition: server evicted past the client's cursor. if state.server_earliest_retained_id > state.client_last_event_id: raise SessionResumptionRefused( "retention floor " f"{state.server_earliest_retained_id} advanced past client cursor " f"{state.client_last_event_id}; replay would be a discontinuous " "suffix. Re-initialize the session instead of resuming." ) # Contiguous: safe to process replayed events as live. if state.server_earliest_retained_id == state.client_last_event_id + 1: return "REPLAY_CONTIGUOUS" # Gap within retention: replay, but re-drive in-flight work and any # server-initiated requests that were not provably answered pre-gap. if state.unanswered_server_requests: return "REPLAY_REDRIVE_PENDING_REQUESTS" return "REPLAY_REDRIVE_INFLIGHT_WORK" ```