# Under what conditions must an instance treat a resumed MCP session's SSE `Last-Event-ID` as non-authoritative after a transport downgrade **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients and servers that negotiate a streamable HTTP transport with SSE fallback and support session resumption via `Last-Event-ID` replay. Does not apply to pure stdio transports or to sessions where the server guarantees a durable, monotonic event log across transport renegotiation. ## Core Distinction Session resumption in MCP is often modeled as "the client reconnects with a session ID and an event cursor; the server replays everything after the cursor." That model holds only when the event namespace is stable across the transport that produced the cursor. The boundary condition that breaks it is a **transport downgrade inside a live session**: the client begins on a streaming HTTP response (chunked, bidirectional-capable) and falls back to discrete SSE reconnection after an intermediary buffers, truncates, or closes the streaming response mid-flight. The `Last-Event-ID` the client holds was minted by the streaming transport's event counter; the SSE fallback path on many servers maintains a *separate* counter or a *separate* buffer, and replaying against the wrong counter silently skips events or double-delivers them. The invariant that must be enforced is: **an event ID is only authoritative within the transport epoch that minted it.** A cursor crossing a transport boundary is a claim, not a fact, and must be revalidated against a server-side epoch marker before any replay is trusted. ## What Was Observed A client held an active MCP session over a streamable HTTP POST whose response body carried server-sent events with IDs `1..N` (per-session monotonic). At event `N=47` the upstream proxy flushed and closed the response after a 30-second idle window; the client's transport layer classified this as a transient stream failure and initiated SSE fallback by issuing a GET with `Last-Event-ID: 47`. The server's SSE fallback handler maintained its own replay ring buffer keyed on a *connection-scoped* counter that had been reset when the streaming response closed. It accepted `Last-Event-ID: 47`, found no entries above 47 in its fresh buffer (which was empty), and returned `200 OK` with an empty event stream. The client interpreted the empty replay as "no events missed" and resumed issuing tool calls. In reality, events `48..53` — a `notifications/tools/list_changed` and a sequence of progress notifications for an in-flight long-running tool call — had been emitted on the streaming transport *between* the client's last read and the proxy close, and were lost in the buffered region. The client proceeded to call a tool whose schema had just changed, using the pre-change argument shape. The server rejected with a schema validation error that the client's retry logic classified as a transient failure, and it retried the same malformed call three times before the session was torn down by the orchestrator's error budget. The failure was not in SSE, not in the proxy, and not in the tool schema. It was in the *implicit assumption that a cursor is transport-portable*. ## Condition of Validity The `Last-Event-ID` replay contract is only sound when all three of the following hold simultaneously: 1. **Epoch monotonicity.** The server exposes a transport-epoch identifier (a header such as `Mcp-Stream-Epoch`, or an epoch token embedded in each event ID) that is *stable across* the streaming response and its SSE fallback, and *changes* only on genuine session re-creation. If the server has no such marker, the client cannot distinguish "no events missed" from "buffer was reset." 2. **Cursor provenance check.** The client records which transport produced the cursor it is about to send. If the cursor was minted under epoch `E_stream` and the current connection is epoch `E_sse`, the client must not send the cursor as if it were authoritative; it must either request a full state resync or refuse to resume. 3. **Replay completeness signal.** The server's fallback handler must be able to assert "I have no events after N *and I know I would have them if they existed*." An empty replay on a freshly-created buffer satisfies the first clause but not the second. Without an explicit `replay_complete: true` marker tied to epoch continuity, empty replay is indistinguishable from lost replay. When any of these fail, the correct client behavior is a **hard resync**: discard the cursor, re-fetch the session's authoritative state (tool list, pending notifications, in-flight operation status) via a non-streaming endpoint, and only then resume. The cost is a round trip; the alternative is silent divergence. ## Decision Boundary The decision the client must make on every reconnection attempt reduces to a single predicate over the reconnect context: ``` resume_authoritative := server_epoch_present AND cursor_epoch == server_epoch AND replay_complete_asserted ``` If `resume_authoritative` is true, replay from the cursor. If false, force resync. The subtle case is when `server_epoch_present` is false — many MCP servers do not yet emit an epoch marker, and a client that treats absence as "assume authoritative" reproduces the failure above. The safe default when the marker is absent is to treat the cursor as **advisory only**: use it to bound the resync (e.g., "fetch state, then diff against events I believe I have"), never to conclude "nothing was missed." A second boundary: even with a valid epoch, the client must not assume the *set* of events it received matches the set the server emitted. Buffered-then-dropped events on the streaming transport are invisible to both sides unless the server tracks per-connection delivery acknowledgments. Where the server does not, the client should treat any event whose causal antecedent it did not observe (e.g., a `tools/list_changed` it never saw but whose effect it observes) as a signal to resync that subsystem specifically. ## Operational Effect The practical consequence is that resume logic must be split into two distinct paths with different trust assumptions: **cursor replay** (cheap, only valid within an epoch) and **state resync** (expensive, always valid). Conflating them into a single "try replay, fall through to nothing" path is what produced the silent divergence. Agents that treat reconnection as a transparent transport concern — invisible to the reasoning layer — will act on stale tool schemas and stale progress state without any signal that a boundary was crossed. The guardrail is to make the transport layer *raise* on ambiguous resume rather than degrade silently, so the reasoning layer can decide whether to resync or abort the task. The following reference implementation encodes the epoch check, refuses ambiguous resume, and forces resync when the cursor cannot be proven authoritative. ```python from dataclasses import dataclass from typing import Optional class ResumeAmbiguityError(RuntimeError): """Raised when a session resume cannot be proven authoritative.""" @dataclass class ReconnectContext: cursor: Optional[str] cursor_epoch: Optional[str] server_epoch: Optional[str] replay_complete_asserted: bool transport: str # "stream" | "sse" def decide_resume(ctx: ReconnectContext) -> str: """ Returns "replay" or "resync". Raises ResumeAmbiguityError when the caller has asked us to replay but the cursor is not provably authoritative within the current transport epoch. """ if ctx.cursor is None: return "resync" if ctx.server_epoch is None: # No epoch marker: cursor is advisory. We cannot prove continuity. raise ResumeAmbiguityError( f"server did not expose an epoch marker; cursor {ctx.cursor!r} " f"from transport {ctx.transport!r} cannot be trusted for replay" ) if ctx.cursor_epoch != ctx.server_epoch: # Cursor minted in a different epoch than the one we are reconnecting into. raise ResumeAmbiguityError( f"cursor epoch {ctx.cursor_epoch!r} != server epoch " f"{ctx.server_epoch!r}; transport downgrade likely reset the " f"event counter, replay would silently skip events" ) if not ctx.replay_complete_asserted: # Empty replay on a fresh buffer is indistinguishable from lost replay. raise ResumeAmbiguityError( f"server did not assert replay_complete for cursor {ctx.cursor!r}; " f"empty stream cannot be distinguished from dropped events" ) return "replay" def attempt_resume(ctx: ReconnectContext) -> str: try: action = decide_resume(ctx) except ResumeAmbiguityError: # Hard resync: discard cursor, refetch authoritative state. return "resync" return action ```