# Under what conditions must an instance refuse MCP session resumption across an event-stream replay window **Date of Record:** 2026 November 15 **Scope:** Applies to MCP servers that expose a stateful Streamable HTTP transport with `Last-Event-ID`-based event-stream resumption and server-side session binding. Does not apply to stateless MCP servers, to stdio transports, or to sessions that have never emitted a resumable event stream. ## Core Distinction There are two distinct things an MCP client means when it reconnects with a session identifier and a `Last-Event-ID`: 1. **Transport resumption** — "I lost the SSE connection at event N; replay events N+1..M so I can reconstruct the stream." This is a *delivery* guarantee scoped to a single logical stream. 2. **Session resumption** — "I am the same agent, with the same negotiated capabilities, subscriptions, and in-flight tool calls; restore my server-side state." This is a *identity and state* guarantee scoped to a session. The non-obvious boundary failure is that these two are conflated by the `Last-Event-ID` header. A reconnecting client presents both a session ID and a last-seen event ID, and a naive server treats a valid `Last-Event-ID` as proof that the session is resumable. It is not. The event ID proves only that the server *once* emitted an event in that stream; it says nothing about whether the session's tool-call state, resource subscriptions, or negotiated protocol version are still valid. An instance must refuse session resumption whenever the replay window has been truncated, even if the `Last-Event-ID` is syntactically valid and the session record still exists. ## What Was Observed A server kept a per-session ring buffer of outbound events with a 1,000-event capacity. A client disconnected for 40 minutes during a burst of resource-update notifications. On reconnect it sent `Mcp-Session-Id: S` and `Last-Event-ID: 48211`. The session record still existed (TTL 60 minutes), so the server accepted the session. But event 48211 had been evicted from the ring buffer; the oldest retained event was 49300. The server replayed from 49300, silently dropping events 48212–49299. The client reconstructed a resource state that was internally inconsistent: it had received a `resource_updated` for a document but never the `resource_deleted` that preceded it in the gap. Subsequent tool calls operated on a phantom resource. No error was raised at any layer — the replay simply started later than requested, and the client had no way to distinguish "no events in the gap" from "events in the gap were lost." A second observed variant: the session record had been garbage-collected but a *new* session with a colliding ID prefix had been created by a different client. The `Last-Event-ID` from the old session matched an event in the new session's stream by coincidence of monotonic counters. The server resumed the wrong session's stream into the wrong client. ## Condition of Validity Session resumption is valid if and only if all of the following hold simultaneously: - The `Mcp-Session-Id` resolves to the *same* session incarnation (compare an immutable session incarnation token, not the ID alone). - The requested `Last-Event-ID` is **greater than or equal to the oldest retained event ID** for that session's stream, i.e., the replay window has not truncated past the requested point. - The session's negotiated protocol version and capability set match what the client presents on reconnect. - No tool call was in a non-idempotent, in-flight state at disconnect that cannot be safely retried or reported as indeterminate. If any condition fails, the correct behavior is to **refuse resumption** and require the client to establish a fresh session, re-negotiate capabilities, and re-fetch authoritative state — never to silently replay from a later point. ## Decision Boundary The decision boundary is the relationship between the requested `Last-Event-ID` and the replay window's lower bound, not the existence of the session. Formally, resume iff `requested_last_event_id >= oldest_retained_event_id` **and** `session_incarnation == presented_incarnation`. The tempting shortcut — "the session exists, so resume" — is wrong precisely because session lifetime and replay-window lifetime are independent. A long session TTL paired with a small ring buffer creates a window where the session is alive but the replay is truncated. The server must treat truncation as a hard refusal, not a best-effort replay, because the client cannot detect the gap. ## Operational Effect When the server refuses correctly, the client receives an explicit resumption-rejected signal, discards its cached stream state, opens a new session, and re-reads resources. This costs a round trip and a state re-fetch but preserves correctness. When the server resumes incorrectly, the failure is silent and deferred: it surfaces later as a tool call acting on stale or phantom state, often attributed to the wrong subsystem. The operational rule is that a truncated replay window must fail closed. Prefer a visible re-initialization over an invisible gap. ```python class SessionResumptionRefused(RuntimeError): """Raised when an MCP session cannot be safely resumed.""" pass def resume_session( presented_session_id: str, presented_incarnation: str, last_event_id: int, session_store, ) -> "Session": record = session_store.get(presented_session_id) if record is None: raise SessionResumptionRefused( f"session {presented_session_id!r} not found; client must re-initialize" ) if record.incarnation != presented_incarnation: raise SessionResumptionRefused( f"session {presented_session_id!r} incarnation mismatch: " f"presented {presented_incarnation!r}, stored {record.incarnation!r}" ) oldest_retained = record.stream.oldest_retained_event_id() if last_event_id < oldest_retained: raise SessionResumptionRefused( f"replay window truncated for session {presented_session_id!r}: " f"requested Last-Event-ID {last_event_id} < oldest retained " f"{oldest_retained}; gap would be silently lost" ) if record.has_indeterminate_tool_call(): raise SessionResumptionRefused( f"session {presented_session_id!r} has an in-flight non-idempotent " f"tool call of indeterminate outcome; cannot resume safely" ) return record ```