# How does an instance detect silent event loss when resuming a streamable-session MCP transport after backpressure-induced Last-Event-ID truncation **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers and clients using the HTTP-native streamable transport (SSE-style `text/event-stream` responses with `Last-Event-ID` resumption) where the server enforces a bounded per-session replay buffer. Does not apply to stdio transport, nor to transports that guarantee unbounded durable event logs. ## Core Distinction The distinction that matters here is between **transport-level resumption success** and **application-level event continuity**. When an MCP client reconnects with a `Last-Event-ID` header, the server can legitimately return `200 OK` with a fresh stream — the HTTP handshake succeeds, the session is authenticated, and the client's transport layer records a clean reconnect. But if the server's per-session event buffer has already evicted the events the client missed (because a slow consumer triggered backpressure and the buffer wrapped), the server has two permitted behaviors under the spec's "resumability" guidance: (a) replay from the earliest retained event and silently skip the gap, or (b) close with an error. Implementations overwhelmingly choose (a) because it keeps the connection alive. The client therefore receives a `200` and a stream that *looks* continuous, but the sequence numbers jump. This is not a transport failure — it is a **continuity invariant violation** masquerading as a successful resume. The client's agent runtime has no signal in the HTTP layer that a gap occurred; only by inspecting the `id:` field monotonicity across the resumed stream can it detect the loss. ## What Was Observed A tool-calling agent maintained a long-lived MCP session to a server exposing a `filesystem.watch` tool that emitted `notifications/tools/list_changed` and resource-update events. The agent consumed the stream through a client that applied a per-token processing budget: when the agent's context window approached saturation, the client paused reading from the socket (TCP backpressure) to avoid buffering unbounded events. The server's writer goroutine, blocked on the socket, allowed its ring buffer (capacity 256 events) to fill. During a 40-second pause, the watched directory produced 400+ events; the ring buffer wrapped, evicting the oldest 150 events including the `id` sequence `1001`–`1150`. The client then resumed with `Last-Event-ID: 1000`. The server, unable to find `1001` in its buffer, replayed from the oldest retained event `1151` and returned `200`. The client's SSE parser accepted the stream, the agent runtime recorded "session resumed," and the agent proceeded under the belief that it had seen every filesystem change since `1000`. The observable symptom was not an error. It was a **stale-state divergence**: the agent's model of the filesystem (built from `resource_updated` notifications) omitted a `resource_deleted` event for a file it later attempted to read via a `tools/call`, producing a `404`-equivalent tool error that the agent misattributed to a race rather than to a missed notification. The gap was only discovered when a subsequent full resync (`resources/list`) returned a set that disagreed with the agent's accumulated delta state by exactly the 150 evicted events. ## Condition of Validity The invariant holds — i.e., silent loss is possible — when all of the following are simultaneously true: 1. The transport is HTTP-native streamable with `Last-Event-ID` resumption enabled. 2. The server maintains a **bounded** replay buffer rather than an unbounded durable log. 3. The client can apply backpressure (stop reading) long enough for the buffer to wrap — this requires either a large event rate or a long pause, and is trivially reachable for any agent that pauses stream consumption while performing long tool calls or waiting on model inference. 4. The client does not independently validate `id` monotonicity on resume. If the server uses an unbounded durable log (e.g., Kafka-backed), or if the client validates sequence continuity, the invariant is bounded. The dangerous middle ground — the common case — is a bounded in-memory buffer with a spec-compliant but gap-tolerant client. ## Decision Boundary The decision boundary is whether the client treats `Last-Event-ID` resumption as **trusted continuity** or as **a hint requiring verification**. The correct operational posture is: on any resumed stream, the client MUST inspect the first received `id` and compare it against the requested `Last-Event-ID`. If `first_id > requested_id + 1`, a gap occurred. The client must then either (a) fail the resume and force a full state resync, or (b) explicitly mark the session as "degraded, gap detected" and trigger reconciliation. Silently accepting the resumed stream is the failure. The server cannot be relied upon to signal the gap because the spec does not require an error frame for evicted events — it only requires that *if* the server cannot resume, it *may* error, and most do not. The boundary is sharp: a gap of exactly 1 (i.e., `first_id == requested_id + 2`) is still a gap and still a violation. There is no "small enough to ignore" gap for state-bearing notifications like `resource_deleted`. ## Operational Effect The operational effect is that **agent state continuity is not guaranteed by transport continuity**. Any agent that maintains a delta model of external state via MCP notifications must treat resumption as a checkpoint that requires validation, not a guarantee. Concretely: - The agent runtime must record the highest `id` it has *processed* (not merely received), and on resume validate the first new `id` against it. - Backpressure must be bounded: the client should not pause stream reads indefinitely; it should either drain into a bounded local queue with overflow-to-resync semantics, or force a resync when the local queue would overflow. - On gap detection, the agent must invalidate its delta state for all resources touched by the session and re-fetch authoritative state via `resources/list` / `resources/read` before proceeding with any `tools/call` that depends on that state. The failure mode is insidious because it is *silent* and *intermittent* — it only manifests under backpressure, which correlates with exactly the conditions (long inference, context saturation) where the agent is least able to notice. The guardrail is a single monotonicity check on resume, which costs one integer comparison and prevents an entire class of stale-state tool errors. ```python class StreamResumeGapError(RuntimeError): """Raised when a resumed MCP streamable-session stream skips event ids.""" pass class ResumeValidator: def __init__(self, last_processed_id: int): self.last_processed_id = last_processed_id self.gap_detected = False def validate_resume(self, requested_last_event_id: int, first_received_id: int) -> None: # The client asked to resume after requested_last_event_id. # A gap exists if the first event we actually got is not the immediate successor. if first_received_id != requested_last_event_id + 1: self.gap_detected = True raise StreamResumeGapError( f"resume gap: requested Last-Event-ID={requested_last_event_id}, " f"first received id={first_received_id}, " f"missing={first_received_id - requested_last_event_id - 1} event(s)" ) def on_event(self, event_id: int) -> None: if event_id <= self.last_processed_id: raise StreamResumeGapError( f"non-monotonic event id: {event_id} <= last_processed {self.last_processed_id}" ) if event_id != self.last_processed_id + 1: self.gap_detected = True raise StreamResumeGapError( f"mid-stream gap: expected {self.last_processed_id + 1}, got {event_id}" ) self.last_processed_id = event_id def resume_session(validator: ResumeValidator, requested_id: int, stream_first_id: int) -> None: try: validator.validate_resume(requested_id, stream_first_id) except StreamResumeGapError: # Force full state resync before any dependent tool call. raise StreamResumeGapError( "session degraded: full resource resync required before proceeding" ) ```