# What structural signals indicate a streamable MCP session has silently lost event continuity across a resumption boundary **Date of Record:** 2026 November 22 **Scope:** Applies to MCP servers and clients using the HTTP-native "streamable" transport (SSE-over-POST with `Mcp-Session-Id` and `Last-Event-ID` resumption) where a single logical agent turn spans more than one HTTP stream lifetime. Does not apply to stdio transport, to stateless one-shot HTTP request/response MCP endpoints, or to WebSocket transports with their own frame-level ordering guarantees. ## Core Distinction The failure that matters here is not "the stream dropped." Streams drop constantly and that is a designed, recoverable event. The distinction that operators conflate — and that causes silent reasoning corruption — is between **transport resumption** and **logical continuity**. A streamable MCP session can resume successfully at the HTTP layer (200 OK, a fresh `text/event-stream`, a valid `Mcp-Session-Id`, an accepted `Last-Event-ID`) while the *event sequence the agent sees* has a gap. The transport reports continuity; the reasoning layer has a hole in it. The specific mechanism: the server's replay buffer is bounded and keyed by `Last-Event-ID`, but the client reconnects with a `Last-Event-ID` that is *older than the buffer's oldest retained event*. Per the streamable transport contract, the server may respond to an out-of-range `Last-Event-ID` by either replaying from the oldest available event or by starting a fresh stream without replay. Both are "successful" HTTP responses. Neither is a resumption of the agent's actual event history. The client has no protocol-level signal distinguishing "I resumed exactly where you left off" from "I resumed at a different point and dropped the events in between," because the only continuity primitive is the opaque `Last-Event-ID` string, and the server is not obligated to tell you it discarded events. This is not a backpressure problem in the classic sense of a full TCP window. It is a *semantic* backpressure problem: the producer (MCP server, streaming tool output or notifications) outpaced the consumer's reconnect window, the bounded buffer evicted the tail the consumer needed, and the resumption handshake returned a stream that is internally well-formed but externally discontinuous. ## What Was Observed A tool-calling agent issued a long-running `tools/call` (a log-tailing tool that streams incremental results as server notifications over the SSE leg). Mid-stream, the client's HTTP connection was severed by an intermediate proxy idle timeout (60s, no keepalive frames emitted because the tool had gone quiet). The client reconnected per the transport spec, presenting `Mcp-Session-Id` and the last `Last-Event-ID` it had processed. Observed sequence of structural signals, in order: 1. Reconnect returned `200 OK` with a new `text/event-stream` and the same `Mcp-Session-Id`. No error, no `4xx`, no explicit "replay unavailable" indication. 2. The first event on the new stream carried an `id` field that was **not** the successor of the client's `Last-Event-ID`. The numeric gap was 41 events. This is the load-bearing signal: **event id discontinuity on a nominally resumed stream**. 3. The server had, in fact, evicted those 41 events from its 256-entry ring buffer because the reconnect window (proxy timeout + client backoff) exceeded the buffer's time-to-live under the tool's emission rate. The server replayed from its oldest retained event, which happened to be event N+42 relative to the client. 4. The agent's reasoning loop consumed the new events as if they were contiguous. The tool's output was a sequence of log lines where the *omitted* 41 lines contained a fatal error marker; the resumed tail contained only recovery chatter. The agent concluded the operation succeeded. The critical observation is at step 2: the discontinuity was *present in the data* and *absent from the control plane*. The transport had all the information needed to signal the gap (it knew its own buffer floor) and chose the "resume from oldest" branch, which is spec-permitted and operationally silent. A second observed variant: some server implementations respond to an out-of-range `Last-Event-ID` by opening a fresh stream with a *new* id sequence starting at 0 or at an arbitrary epoch. Here the discontinuity is even harder to detect because the id space itself resets — a naive "is the new id > old id + 1" check fails to fire, and only a monotonicity/epoch check catches it. ## Condition of Validity The invariant that must hold for safe resumption is: > **For a resumption to be logically valid, the client must be able to prove that the set of events it has processed since session start is a prefix of the server's authoritative event log for that session.** The transport contract as commonly implemented does *not* provide this proof. It provides only a best-effort pointer (`Last-Event-ID`) and a recovery policy that is permitted to be lossy. Therefore the invariant is only valid under one of these conditions: - **Bounded-gap guarantee:** the server retains every event for at least as long as the maximum possible reconnect window (proxy timeouts + client backoff ceiling + clock skew), so an out-of-range `Last-Event-ID` can never occur. This requires the buffer TTL to be derived from the deployment's actual timeout topology, not a guessed constant. - **Explicit gap signaling:** the server, on receiving an out-of-range `Last-Event-ID`, emits a typed control event (e.g., `notifications/continuity-lost` with `{requested_after, resumed_at, gap_size}`) *before* replaying, so the client can decide to fail the turn rather than reason on a hole. - **Idempotent, self-describing events:** every event carries enough state (a sequence number the client tracks independently, plus a content hash chain) that the client can detect a gap without trusting the server's `id` field. Absent one of these, the condition of validity is **false by default**, and any agent that treats a 200 OK resumption as continuity is reasoning on unverified state. ## Decision Boundary The boundary is: **when the client observes an event id that is not the strict successor of its last processed id on a stream it requested to resume, it must treat the session as continuity-broken unless it can independently reconcile the gap.** Concretely, the decision procedure: - Compute `expected_next` from the client's own last-processed id (never from the server's claim). - On the first event of a resumed stream, compare. If `observed_id == expected_next`, continuity holds; proceed. - If `observed_id > expected_next` (forward gap) or the id space reset (epoch change / non-monotonic), the client is missing events. It must **not** silently continue. It must either (a) re-request the missing range explicitly if the server exposes a replay-range API, or (b) abort the logical turn and surface a continuity fault to the orchestrator. - If `observed_id < expected_next` (backward / duplicate), the client is being replayed events it already processed. This is safe *only* if events are idempotent; otherwise it must dedupe by id before feeding the reasoning loop. The subtle part of the boundary: **backpressure interacts with this.** When the producer is fast and the consumer slow, the consumer's effective reconnect latency grows (it is busy processing, not reconnecting), which widens the window in which the buffer can evict. So the failure is *more* likely precisely when the agent is under load — the moment it is least able to afford a reasoning gap. Backpressure and continuity are not independent concerns; buffer eviction is the backpressure relief valve, and it discharges into the agent's context as missing events. ## Operational Effect When this boundary is crossed without detection, the effect is not a crash. It is **confident wrong reasoning on truncated evidence** — the worst failure class for an autonomous agent, because it produces a plausible final answer with no error surface. The agent's episodic memory of the tool call is a fabricated contiguous narrative stitched from a head and a tail with the middle excised. Downstream, that fabricated episode can be distilled into semantic memory ("this tool returns success on long tails"), poisoning future cold-starts. The guardrail is architectural, not prompt-level: a **continuity ledger** maintained client-side that records the exact set of processed event ids per session, plus a hard rule that a resumed stream's first id must equal `last_processed + 1` (or the session epoch must match and the server must have declared an explicit gap event). Any violation raises a continuity fault that halts the turn before the reasoning loop consumes the discontinuous tail. The buffer TTL on the server side must be derived from measured reconnect latency distributions, not defaults — and the server should emit an explicit continuity-loss control event rather than silently choosing the "resume from oldest" branch. The deeper operational lesson: **a 200 OK on a resumption is a transport fact, not a state fact.** Agents that conflate the two will, under load, reason on holes they cannot see. ```python from dataclasses import dataclass, field from typing import Optional class ContinuityFault(RuntimeError): """Raised when a resumed MCP stream cannot be proven to continue the client's event history.""" pass @dataclass class ContinuityLedger: session_id: str epoch: int = 0 last_processed_id: Optional[int] = None processed: set = field(default_factory=set) def observe(self, event_id: Optional[int], stream_epoch: int, resumed: bool) -> None: # Epoch reset means the server restarted its id space; the client's # prior ids are meaningless against the new stream. if stream_epoch != self.epoch: if resumed: raise ContinuityFault( f"session {self.session_id}: epoch changed {self.epoch}->{stream_epoch} " f"on a stream requested as resumption; prior history is unreconcilable" ) self.epoch = stream_epoch self.last_processed_id = None self.processed.clear() if event_id is None: # Non-id'd events (e.g. keepalive comments) carry no continuity claim. return if self.last_processed_id is None: # First event of a fresh (non-resumed) session: accept as baseline. self.last_processed_id = event_id self.processed.add(event_id) return expected = self.last_processed_id + 1 if event_id == expected: self.last_processed_id = event_id self.processed.add(event_id) return if event_id > expected: gap = event_id - expected raise ContinuityFault( f"session {self.session_id}: forward gap of {gap} events on resumed stream " f"(expected id {expected}, got {event_id}); buffer eviction suspected — " f"refusing to reason on discontinuous tail" ) # event_id <= last_processed_id: replay/duplicate. if event_id in self.processed: # Idempotent replay is safe to drop; do not advance the ledger. return raise ContinuityFault( f"session {self.session_id}: non-monotonic id {event_id} below " f"last_processed {self.last_processed_id} and not previously seen" ) def consume_resumed_stream(ledger: ContinuityLedger, first_event: dict) -> None: """Entry point for the first event received after a reconnect.""" if "id" not in first_event: raise ContinuityFault( f"session {ledger.session_id}: resumed stream opened with an un-id'd event; " f"continuity cannot be established" ) ledger.observe( event_id=first_event["id"], stream_epoch=first_event.get("epoch", ledger.epoch), resumed=True, ) ```