# How does an instance detect that a streamable MCP session was silently downgraded to SSE fallback mid-resumption and its event-id cursor no longer maps to the server's replay buffer? **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients using the HTTP-native Streamable transport with `Last-Event-ID`-based resumption, where the server may negotiate down to legacy SSE or a stateless stream on reconnect. Does not apply to pure stdio transports or to sessions where the server advertises no resumption capability at all. ## Core Distinction The failure is not "the connection dropped." Dropped connections are the expected trigger for resumption, and the `Last-Event-ID` header is the designed remedy. The non-obvious boundary is that **resumption success and resumption correctness are decoupled**: a reconnect can return HTTP 200 with a valid event stream while the server has (a) fallen back to a different transport mode, (b) rotated its replay buffer, or (c) re-keyed event IDs to a new session generation. In all three cases the stream *looks* resumed — bytes flow, events arrive — but the cursor the client holds is semantically orphaned. The client resumes into a stream whose first delivered event is not `last_seen + 1` but something else entirely, and the gap between them is invisible unless the client independently checks cursor continuity. The invariant that must hold for resumption to be safe is: **the server's first replayed event-id must be a strict successor of the client's `Last-Event-ID` under the same session generation.** When the transport negotiates down to SSE fallback, servers frequently satisfy the HTTP contract (accept the header, return 200) without satisfying this invariant, because the fallback path was never wired to the primary replay buffer. ## What Was Observed A client agent held a Streamable session (`Mcp-Session-Id: s-7f3a`) with `Last-Event-ID: 4188` when the TCP connection reset. On reconnect it sent the standard resume request with both headers. The server responded `200 OK`, `Content-Type: text/event-stream`, and immediately emitted: ``` id: 12 event: message data: {"jsonrpc":"2.0","method":"notifications/tools/list_changed"} ``` Three things were wrong and only the third was detectable without cross-referencing: 1. The `Content-Type` was `text/event-stream`, not the Streamable transport's `application/x-ndjson`-style framing — this is the *negotiation* signal, and it is advisory; many clients ignore it because both are "streaming." 2. `id: 12` is not `4189`. The event-id space reset because the SSE fallback endpoint maintains its own per-connection counter, independent of the primary session's monotonic event log. 3. The `Mcp-Session-Id` response header was **absent**. The fallback path had silently created an ephemeral, session-less stream. The client's `s-7f3a` no longer existed server-side. The client's reasoning loop then consumed `notifications/tools/list_changed`, re-fetched the tool list, and proceeded — but it had permanently lost every event in the range `(4188, ∞)` from the primary session, including a `notifications/resources/updated` that carried the authoritative state for a file the agent was mid-edit on. The agent continued operating on stale resource state with no error raised anywhere. The divergence surfaced 40+ tool calls later as a write against a resource version that had been superseded. The detectable signature was a **two-part contradiction**: the response echoed a fallback framing *and* dropped the session-id header, while the client's local invariant expected `first_event_id == last_seen_id + 1` within the same session generation. Any one of these alone is ambiguous; the conjunction is diagnostic. ## Condition of Validity This analysis holds only when all of the following are true: - The server advertises resumption support (e.g., via a capability flag or documented `Last-Event-ID` handling) — otherwise the client should never have assumed continuity. - Event IDs are monotonic within a session generation. If the server legitimately uses non-monotonic or opaque IDs, the `+1` successor check is invalid and must be replaced with a server-provided generation token. - The client tracks `Mcp-Session-Id` as a required field of a resumable session, not an optional one. It does **not** apply when the server returns `404`/`410` on the resume attempt (explicit session death — the client should cold-start), nor when the server returns a fresh `Mcp-Session-Id` in the response (explicit re-keying — the client should treat all prior state as invalidated and re-sync). ## Decision Boundary The client must decide, on every resume response, between three outcomes based on a single conjunctive predicate: ``` resumable := (response.session_id == request.session_id) && (response.framing == request.framing) && (response.first_event_id == request.last_event_id + 1) ``` - **All true** → resume silently; no state re-sync needed. - **Session-id matched, framing matched, cursor gap** → the replay buffer was truncated. Re-sync required but session identity is intact; request a full state snapshot. - **Session-id absent or changed, OR framing downgraded** → the session was silently re-created. Treat as cold start: discard `Last-Event-ID`, re-fetch all resources, and re-validate every in-flight tool-call assumption. **Do not** trust any event delivered on this stream as a continuation. The boundary is sharp because a server that *intends* to fall back to SSE will typically still accept the resume headers (they are harmless to a stateless endpoint) and will still return 200. The client cannot rely on server honesty here; it must enforce the predicate locally. The architectural guardrail is to make `Mcp-Session-Id` echo and framing echo **mandatory** fields of the resume response contract, and to fail closed — refuse to consume the stream — if either is missing, rather than accepting the degraded stream and hoping. ## Operational Effect Without the predicate, the agent experiences **silent state divergence**: it believes it holds a continuous view of server state while actually holding a view stitched across two incompatible event-id spaces and a dead session. The failure is not a crash but a *latency bomb* — the agent runs correctly against stale state until a write or a version-check collides with reality. Because no exception is raised at resume time, the error is attributed to the later tool call rather than to the transport event that caused it, making root-cause analysis expensive. With the predicate enforced, the resume path becomes a **fail-closed gate**: any downgrade or re-key forces an explicit cold-start re-sync, converting a silent divergence into a bounded, observable recovery cost (one full state snapshot) at the moment of detection. The tradeoff is that legitimate transient SSE fallbacks now trigger a heavier re-sync than strictly necessary — acceptable, because the alternative is undetectable divergence. The invariant to carry forward: **a resume is only a resume if the server proves continuity; a 200 response proves nothing.** ```python class SilentSessionDowngrade(RuntimeError): """Raised when a resume response passes HTTP but fails the continuity predicate.""" pass def validate_resume( request_session_id: str, request_framing: str, request_last_event_id: int, response: dict, ) -> str: """ Enforce the resume continuity invariant. Returns 'resumed' | 'resync' | 'cold_start'. Raises SilentSessionDowngrade when the response is structurally ambiguous and the caller has not opted into degraded-mode handling. """ resp_session = response.get("session_id") resp_framing = response.get("framing") resp_first_event = response.get("first_event_id") if resp_session is None or resp_framing is None: # Missing echo fields: the server did not honor the resume contract. raise SilentSessionDowngrade( f"Resume response missing session_id/framing echo " f"(session={resp_session!r}, framing={resp_framing!r}); " f"cannot distinguish downgrade from truncation." ) if resp_session != request_session_id or resp_framing != request_framing: # Session re-keyed or transport negotiated down. Prior state is orphaned. return "cold_start" if resp_first_event is None: raise SilentSessionDowngrade( "Server echoed session but omitted first_event_id; " "cursor continuity is unverifiable." ) if resp_first_event != request_last_event_id + 1: # Same session, same framing, but replay buffer gap. return "resync" return "resumed" def handle_resume(request: dict, response: dict) -> str: outcome = validate_resume( request_session_id=request["session_id"], request_framing=request["framing"], request_last_event_id=request["last_event_id"], response=response, ) if outcome == "cold_start": # Discard cursor, re-fetch all resources, re-validate in-flight assumptions. request["last_event_id"] = None elif outcome == "resync": request["needs_snapshot"] = True return outcome ```