# What happens when an instance resumes an MCP Streamable HTTP session after the SSE event ID has been reaped but the session token remains valid **Date of Record:** 2026 November 23 **Scope:** Applies to MCP Streamable HTTP servers that issue `Mcp-Session-Id` headers, attach `id:` fields to server-sent events, and accept `Last-Event-ID` on reconnect via GET. Does not apply to stdio transports, nor to servers that treat every GET as a fresh stream with no resumable history. ## Core Distinction A Streamable HTTP session and an SSE event log are two independent lifetimes that happen to share a bearer token. The session token (`Mcp-Session-Id`) is validated against a session registry; the `Last-Event-ID` is validated against a per-stream ring buffer or durable event store. The failure mode arises because the two are reaped on different schedules. When the event buffer expires before the session does, the server is in a state where the client is *authenticated but un-resumable* — and the spec-compliant behavior of "resume from Last-Event-ID" has no defined answer for an ID that is syntactically valid but no longer retained. The non-obvious boundary is that this is not an auth failure and not a session failure; it is a *replay gap*, and the two common implementations diverge silently: some servers replay from the oldest retained event (duplicating or reordering work), others silently start a fresh stream (dropping the gap), and neither signals the divergence to the client. ## What Was Observed A client held a valid `Mcp-Session-Id` for roughly 40 minutes of idle time. The server's session TTL was 60 minutes; its SSE event ring buffer was capped at 1,024 events or 5 minutes of wall-clock retention, whichever came first. On reconnect the client sent `GET /mcp` with `Mcp-Session-Id: ` and `Last-Event-ID: 4091`. The server accepted the session (200), opened the stream, and emitted the next event with `id: 4210`. Events 4092–4209 were never delivered. The client had no way to distinguish this from a clean resume, because the server neither returned a `409 Conflict` nor emitted a gap marker. Downstream, the client applied a tool result that assumed a resource state established by a dropped event, and the resulting `tools/call` operated on a stale resource version. A second observation: when the same server was configured with a *durable* event store but a *shorter* session TTL, the inverse happened — the client's `Last-Event-ID` was replayable, but the session had been reaped, so the server returned `404 Not Found` on the session token and the client correctly re-initialized. This case is well-behaved. The dangerous case is strictly the first: **session outlives event history.** ## Condition of Validity This boundary is reachable if and only if all of the following hold: 1. The server retains `Mcp-Session-Id` beyond the retention window of the event IDs it has emitted. 2. The server does not reject a `Last-Event-ID` that precedes its oldest retained event (i.e., it does not return a distinguishable error). 3. The client treats any successful stream open as a complete resume, without an application-level sequence check. Remove any one and the failure is masked. In particular, condition 2 is the trap: a server that returns `410 Gone` or `409 Conflict` on an un-retained `Last-Event-ID` converts a silent data-loss bug into a recoverable re-initialization. The spec does not mandate this, so conformance testing passes either way. ## Decision Boundary The correct operational rule is: **event retention must be greater than or equal to session retention, or the server must explicitly signal a replay gap.** If you cannot make event retention ≥ session TTL, do not silently resume. Instead, treat an un-retained `Last-Event-ID` as a session-level invalidation: close the stream, require the client to re-`initialize`, and let it re-derive state. The client-side mirror of this rule is: never trust a resumed stream as gap-free unless the server has declared a monotonic, gap-detecting event ID scheme *and* you have verified contiguity yourself. A resumed stream with a jump in event IDs is evidence of a gap, not of progress. ## Operational Effect In production this manifests as rare, load-dependent, and nearly unreproducible state divergence: it only triggers when a client is idle long enough for the event buffer to cycle but not long enough for the session to expire — a window that widens under memory pressure (buffer eviction accelerates) and narrows under low traffic. The blast radius is bounded to the affected session, but the symptom (a tool operating on stale resource versions) looks like a logic bug in the tool, not a transport bug, so it is typically misattributed. Mitigation: emit a monotonic event ID, have clients assert contiguity on resume, and make the server return a typed error for un-retained IDs rather than a silent fresh stream. ```python class StreamResumeGapError(RuntimeError): """Raised when a resumed MCP SSE stream cannot prove event contiguity.""" pass def validate_resume( last_event_id: int, oldest_retained_id: int, first_delivered_id: int, session_ttl_seconds: int, event_retention_seconds: int, ) -> None: # Invariant: event retention must cover session retention, or resume must be refused. if event_retention_seconds < session_ttl_seconds: if last_event_id < oldest_retained_id: raise StreamResumeGapError( f"Last-Event-ID {last_event_id} precedes oldest retained " f"{oldest_retained_id}; session still valid but replay impossible. " f"event_retention={event_retention_seconds}s < " f"session_ttl={session_ttl_seconds}s. Refusing silent resume." ) # Even when retention is sufficient, the delivered stream must be contiguous. expected = last_event_id + 1 if first_delivered_id != expected: raise StreamResumeGapError( f"Resume delivered id {first_delivered_id}, expected {expected}; " f"gap of {first_delivered_id - expected} events. " f"Client must re-initialize rather than apply stale state." ) ```