# What structural signals indicate silent SSE resumption divergence in MCP HTTP-native transport **Date of Record:** 2026 November 21 **Scope:** Applies to MCP servers and clients using the HTTP-native transport with streamable SSE and `Last-Event-ID`-based session resumption, where a single logical session spans reconnect boundaries. Does not apply to pure stdio transports or to stateless request/response MCP profiles that never emit resumable event streams. ## Core Distinction The failure mode is not "the connection dropped." Dropped connections are expected and designed for. The failure is that a resumed SSE stream *appears* healthy—HTTP 200, correct `Content-Type: text/event-stream`, a valid `Mcp-Session-Id` echoed back—while the event cursor the server resumes from does not correspond to the cursor the client believes it holds. The client's `Last-Event-ID` names a logical position in a stream the server has already garbage-collected, renumbered, or truncated. MCP's resumability contract is only as strong as the invariant that event IDs are monotonic, dense-enough, and session-scoped; when the server silently resets its event counter on restart or per-worker, resumption becomes a *semantic* divergence disguised as a *transport* success. The critical distinction: a transport-level 404/410 on resume is a *safe* failure—the client knows to replay from scratch. A 200 with a renumbered event stream is an *unsafe* success—the client believes it has continuity and proceeds to reason over a state graph with a hole in it. ## What Was Observed An MCP server was deployed behind a load balancer with three replicas, each holding its own in-memory event ring buffer per session. Sessions were sticky by `Mcp-Session-Id` hash, but a rolling restart drained one replica. On reconnect, the client sent: ``` GET /mcp Mcp-Session-Id: 7f3a... Last-Event-ID: 1842 Accept: text/event-stream ``` The request landed on a *different* replica (sticky hash recomputed because the drained node left the ring). That replica had a session record reconstructed from a shared Redis snapshot but its event buffer was empty, so its internal counter restarted at `0`. The server did not reject the resume; it accepted the session and emitted the next event with `id: 0`. The client's SSE parser, per the EventSource contract, treats any received `id` as authoritative and *overwrites* its stored cursor. The client had been waiting on the result of a `tools/call` whose completion event was `id: 1839`—emitted on the old replica and now lost. It received event `id: 0` (a server-initiated `notifications/message` log frame), updated its cursor to `0`, and continued waiting for `1839`. Structural signals present in the trace: - **Cursor regression:** `Last-Event-ID` sent = 1842, first `id` received = 0. A monotonicity violation across the resume boundary. - **Gap with no error frame:** No SSE `retry` hint, no `event: error`, no `410 Gone`. The stream was syntactically valid. - **Divergent tool-result correlation:** The pending `tools/call` request ID had no matching response event, but the client's timeout was 300s—long enough that the agent's outer reasoning loop had already emitted two dependent tool calls assuming the result. - **Session-ID continuity without state continuity:** `Mcp-Session-Id` matched; per-session event sequence did not. The agent did not crash. It produced a plausible but wrong answer, because a downstream summarization step treated the missing tool result as "no result returned" rather than "result lost in transport." ## Condition of Validity The resumption invariant that MCP HTTP-native transport *assumes* but does not *enforce* at the protocol layer: > For a given `Mcp-Session-Id`, event IDs form a monotonically increasing sequence, and a resume with `Last-Event-ID = N` either (a) replays every event with ID > N in order, or (b) fails explicitly with a status that tells the client the cursor is unrecoverable. This holds only when all of the following are true: 1. **Single-writer event sequencing per session.** Event IDs are assigned by one authority, not per-replica. If replicas assign IDs independently, cross-replica resume produces regression. 2. **Durable event log spanning the resume window.** The buffer must survive the process that produced the events, or the server must be able to distinguish "no events since N" from "events since N are gone." 3. **Explicit unrecoverable-cursor signal.** When the server cannot honor `Last-Event-ID = N` (log truncated, counter reset, session migrated), it MUST fail the resume—`410 Gone` with a machine-readable reason, or a fresh `Mcp-Session-Id`—rather than silently restart the counter. The condition of validity is therefore *not* "the client reconnects." It is "the server can prove to the client that its cursor is still meaningful." When any of (1)–(3) is absent, a 200 on resume is not evidence of continuity. ## Decision Boundary The boundary between safe and unsafe resumption is the **cursor disposition decision** the server makes on receiving `Last-Event-ID`: | Server state vs. cursor | Correct disposition | Unsafe disposition (observed) | |---|---|---| | Cursor within retained log | Replay events > N | — | | Cursor ahead of current counter (regression) | `410 Gone`, new session | Accept, emit `id: 0` | | Cursor behind truncated floor | `410 Gone`, or snapshot + explicit reset marker | Accept, emit from floor with no gap signal | | No session record | `404`, client re-initializes | Recreate empty session, accept resume | The decision boundary is sharp: **any resume where the first emitted `id` is ≤ the client's `Last-Event-ID` is a protocol violation that the client cannot detect without independently tracking the sent cursor.** The client MUST treat `received_id <= sent_last_event_id` as a divergence event, not as a valid continuation. This is the guardrail the transport layer omits and the client must supply. ## Operational Effect Downstream, the effect is **silent state-graph corruption in the agent's reasoning loop.** The missing tool result is not surfaced as an error; it is surfaced as absence. Agent frameworks that distinguish "tool returned empty" from "tool call failed" will misclassify a transport loss as a semantic null. The agent then proceeds with a false premise, and because the premise is *plausible* (a null result is a legal result), no downstream verifier flags it. Compounding effects observed: - **Error masking across retries:** The client's SSE layer auto-reconnected (per EventSource semantics) without surfacing the cursor regression to the MCP layer, so the MCP client never re-issued the pending `tools/call`. The request was orphaned, not retried. - **Reasoning divergence amplification:** Two subsequent tool calls were issued on the assumption that the first returned null. Their results were consistent with that assumption, so the agent's self-consistency check passed. The divergence was only caught when a human compared the final answer to the raw tool logs. - **Non-reproducibility:** Because the divergence depended on which replica the reconnect landed on, the failure was load- and timing-dependent and did not reproduce in single-replica staging. The architectural guardrail required: **the client must maintain its own authoritative cursor and validate every received event ID against it, treating non-monotonicity as a hard session-invalidating error that aborts and replays the pending request set—not as a resumable continuation.** The server must additionally fail-closed on cursor regression rather than fail-open with a counter reset. ```python import re from dataclasses import dataclass, field class SSEResumptionDivergence(RuntimeError): """Raised when a resumed SSE stream violates cursor monotonicity. A 200 response with a streamable body is NOT proof of continuity. The client holds the only trustworthy cursor; the server's first emitted id must be strictly greater than the Last-Event-ID we sent. """ @dataclass class SSECursorGuard: session_id: str sent_last_event_id: int received_ids: list = field(default_factory=list) def validate_resume_frame(self, raw_event: str) -> None: # Parse the first `id:` field of the resumed frame. match = re.search(r"^id:\s*(\d+)\s*$", raw_event, re.MULTILINE) if match is None: # A frame with no id is legal mid-stream but NOT legal as the # first frame after a resume with Last-Event-ID set: we cannot # prove continuity, so treat it as divergence. raise SSEResumptionDivergence( f"session {self.session_id}: resumed stream opened with " f"id-less frame; cannot confirm cursor > {self.sent_last_event_id}" ) received = int(match.group(1)) self.received_ids.append(received) if received <= self.sent_last_event_id: # This is the silent-reset signature: server restarted its # counter (e.g. replica migration, buffer eviction) and is # emitting from a floor at or below our cursor. raise SSEResumptionDivergence( f"session {self.session_id}: cursor regression on resume — " f"sent Last-Event-ID={self.sent_last_event_id}, " f"received id={received}. Server must return 410 Gone, " f"not a renumbered stream. Abort session; replay pending " f"tools/call set against a fresh Mcp-Session-Id." ) # Monotonicity within the resumed stream. if len(self.received_ids) > 1 and received <= self.received_ids[-2]: raise SSEResumptionDivergence( f"session {self.session_id}: non-monotonic id within resumed " f"stream ({self.received_ids[-2]} -> {received})" ) def resume_stream(guard: SSECursorGuard, first_frame: str) -> None: guard.validate_resume_frame(first_frame) # ... proceed with replay of pending tools/call set ... ```