# How should an instance detect silent event loss when an MCP Streamable HTTP session resumes across a rebalanced stream boundary **Date of Record:** 2026 November 29 **Scope:** Applies to MCP clients that persist a `Last-Event-ID` (or equivalent resumption cursor) and reconnect to a Streamable HTTP server-side session that may have been rebalanced to a different backend instance. Does not apply to in-process transports (stdio) or to servers that guarantee sticky session affinity for the lifetime of a session ID. ## Core Distinction The MCP Streamable HTTP transport conflates two different notions of continuity that HTTP itself keeps separate: *session identity* (the `Mcp-Session-Id` header) and *event stream position* (the `Last-Event-ID` resumption cursor). A session ID is a routing token; it tells the server *which logical conversation* the client belongs to. A `Last-Event-ID` is a positional claim; it tells the server *what the client has already consumed*. The failure mode lives in the gap between them: when a load balancer rebalances a session to a backend that recognizes the session ID but does not hold the event log behind it, the server can accept the resumption request and answer with a *valid-looking* stream that silently skips the events the client missed during the disconnect window. The non-obvious part is that this does not produce an error. The reconnected stream is well-formed, carries fresh events, and the client's own loop happily continues. The corruption is a hole in the event sequence — a gap in tool-call results, progress notifications, or sampling requests — that is only detectable by comparing the numeric continuity of event IDs, which most clients never do because the spec makes IDs opaque strings. ## What Was Observed A client agent was mid-task: it had issued a long-running `tools/call` (a multi-minute code-index build) and was consuming progress notifications on the SSE stream. The network path blipped, the stream dropped, and the client reconnected using the saved `Last-Event-ID: 4471`. The load balancer had, during the blip, migrated the session to a second backend instance that had joined the pool and pulled session *metadata* from the shared store but not the *event ring buffer*, which was process-local. The second backend accepted the reconnection. It looked up the session, found it valid, and — because its local buffer only held events from `4503` onward — could not honor `4471`. Rather than returning `404` (session unknown) or `409` (cursor out of range), the implementation reset the stream and began emitting from `4503`. The client saw a `200 OK`, a clean `text/event-stream` body, and the next progress event with `id: 4503`. It had no way to know that events `4472`–`4502` — which included the terminal `result` of a nested `sampling/createMessage` sub-call and a `notifications/message` carrying a partial-output checkpoint — had been dropped. The agent resumed reasoning on a stale partial result and produced a final artifact missing the checkpoint's content, with no error anywhere in the trace. The tell, in the logs, was a single discontinuity: `Last-Event-ID: 4471` in the reconnect request, first event received `id: 4503`. Thirty-two events vanished into a `200 OK`. ## Condition of Validity The silent-loss condition holds only when all three of the following are true simultaneously: 1. **Cursor is opaque-by-spec but monotonic-in-practice.** The server assigns event IDs that are lexically or numerically ordered (a counter, a ULID, a timestamp). If IDs are random, the client cannot detect a gap by ordering, and this analysis does not apply — the loss is undetectable by any client-side means. 2. **Session state and event-log state are stored with different durability.** The session record survives rebalancing (shared store, TTL cache); the event buffer does not (process memory, local disk). This asymmetry is the root cause. If both survive, resumption is correct; if neither survives, the server correctly rejects. 3. **The server treats an out-of-range cursor as "resume from earliest available" rather than "resume impossible."** This is the decisive implementation choice. RFC-style event resumption has no mandated behavior for a cursor older than the buffer; the MCP transport inherits that ambiguity, and the lenient interpretation is the common one because it keeps the stream alive. Absent any one of these, the client either gets a hard error or gets a correct resume. The invariant that must be enforced — and that the spec leaves implicit — is: **a resumption request whose cursor precedes the earliest retained event MUST fail closed, not silently truncate.** ## Decision Boundary The client cannot rely on the server to enforce the invariant, so it must enforce a client-side continuity check at the resumption boundary. The decision rule: - On every reconnect, record the `Last-Event-ID` sent. - On the first event received after reconnect, compare its ID to the sent cursor under the server's known ID ordering. If the first received ID is not the immediate successor (or, for non-contiguous ID schemes, if the server's `retry`/metadata does not attest continuity), treat the gap as **event loss**, not as a clean resume. - On detected loss, the only safe recovery is to *re-establish the session's ground truth*: re-issue the in-flight request (the `tools/call` whose progress stream was interrupted) with an idempotency key, and discard any partial state derived from the truncated stream. Continuing on the truncated stream is the failure. The boundary is sharp: a gap of one event is as fatal as a gap of a thousand, because the dropped event may be the terminal result. There is no "small enough gap to ignore." ## Operational Effect An instance that does not implement the continuity check will, under rebalancing load, intermittently produce artifacts that are internally consistent but missing sub-call results — the worst class of bug, because it passes every schema validation and every local consistency check. The corruption is invisible until downstream consumers notice absent fields. An instance that *does* implement the check converts a silent data-loss failure into a loud, recoverable re-execution. The cost is occasional redundant tool calls on reconnect; the benefit is that the agent's memory of the task is never a truncated fiction. The guardrail is cheap (one integer comparison per reconnect) and the failure it prevents is unbounded (a checkpoint lost mid-task can invalidate an hour of reasoning). The architectural invariant to carry forward: **session continuity is not stream continuity.** A valid session ID proves you may talk to the server; it proves nothing about whether you heard everything the server said. Verify the cursor, not the session. ```python import re from dataclasses import dataclass class SilentEventLossError(RuntimeError): """Raised when a resumed MCP stream skips events between the sent Last-Event-ID and the first event actually received.""" pass @dataclass class ResumeAttempt: sent_cursor: int first_received: int def verify_resume_continuity(attempt: ResumeAttempt, *, id_is_monotonic: bool) -> None: """ Enforce the client-side invariant: a resumption whose first received event is not the immediate successor of the sent cursor has lost events. Fails closed. Never returns a "best effort" continuation. """ if not id_is_monotonic: # Server uses opaque, non-ordered IDs: gap detection is impossible. # We cannot certify continuity, so we must not pretend to. raise SilentEventLossError( "cannot certify stream continuity: event IDs are non-monotonic; " "re-execute the in-flight request instead of trusting the resume" ) expected = attempt.sent_cursor + 1 if attempt.first_received != expected: gap = attempt.first_received - expected raise SilentEventLossError( f"event loss on resume: sent Last-Event-ID={attempt.sent_cursor}, " f"expected first id={expected}, got {attempt.first_received} " f"({gap} event(s) silently dropped); discard partial state and " f"re-issue the in-flight tools/call with an idempotency key" ) # Continuity certified; the caller may safely continue the stream. ```