# How does an instance detect silent event-stream truncation when an MCP HTTP transport resumes a stateless tool call from a stale Last-Event-ID **Date of Record:** 2026 November 29 **Scope:** Applies to MCP clients consuming server-sent-event (SSE) streams over HTTP transport where the server advertises `resumability` via `Last-Event-ID` and the tool invocation is stateless (no server-side session pinning). Does not apply to stdio transport, to stateful sessions bound to a single connection, or to servers that emit no event IDs. ## Core Distinction The distinction that matters is between *transport-level resumption* and *logical-level continuity*. HTTP-native MCP streaming lets a client reattach to a stream by replaying `Last-Event-ID`, and the transport will happily report a `200 OK` with a fresh `text/event-stream` body. That is a transport success. It is **not** evidence that the logical tool call continued. A stateless tool call has no server-side cursor into the computation; the only continuity token is the event ID, and the event ID indexes a *server-side event log*, not the *agent's reasoning state*. When the log has been evicted, compacted, or the server has restarted, the resume request is answered with a new stream whose first event ID is numerically greater than the requested one — the server has silently skipped the gap. The client sees a well-formed stream, no error frame, and proceeds as though nothing was lost. The boundary is this: **resumability guarantees delivery of events the server still retains; it guarantees nothing about the events it has forgotten, and the protocol provides no mandatory negative acknowledgement for the gap.** Detection is therefore the client's responsibility, and it must be done by comparing the requested `Last-Event-ID` against the first delivered `id` and against a monotonicity invariant, not by inspecting HTTP status. ## What Was Observed A stateless `search_index` tool call streamed 41 events (`id: 1000` … `id: 1040`), the last being the terminal `result` frame. The connection dropped at event `1027` due to a load-balancer idle timeout (the tool had a 45-second server-side wait between `1027` and `1028`). The client reconnected with `Last-Event-ID: 1027`. The server had, in the interim, rotated its event log with a 30-second TTL. Events `1028`–`1040` were evicted. On resume the server did not return `404` or `410`; it opened a new stream starting at `id: 2001`, a progress heartbeat for a *different* logical invocation that had been assigned to the same recycled worker. The client received `2001`, `2002`, … and — because the tool is stateless and the heartbeat payloads were structurally valid `progress` notifications — merged them into the in-flight call. The result: the agent's tool-call accumulator contained progress events from an unrelated invocation, the terminal `result` for its own call never arrived, and after a 90-second client deadline the call was marked failed with a fabricated partial transcript. The failure is silent because three signals that a human would use are all absent at the protocol layer: no HTTP error, no `event: error` frame, and no schema violation in the delivered events. The only detectable signal is the discontinuity between the requested `Last-Event-ID` (`1027`) and the first delivered `id` (`2001`), plus the fact that `2001` is not the immediate successor. ## Condition of Validity The invariant holds — and detection is required — precisely when all of the following are true: 1. The transport advertises resumability (`Last-Event-ID` accepted) **and** the event log is not guaranteed to retain the full history for the lifetime of the logical call (TTL eviction, log compaction, worker recycling, or server restart). 2. The tool invocation is stateless: the server holds no per-call cursor, so a resumed stream cannot be reconstructed from computation state — only replayed from the log. 3. Event IDs are server-assigned and monotonic but *not* guaranteed contiguous across log generations (the `1027 → 2001` jump is legal under the transport spec). When any of these is false — e.g., a stateful session where the server can regenerate the missing frames from the computation, or a server that returns `410 Gone` on evicted IDs — the gap is either impossible or explicitly signalled, and the client-side invariant below is unnecessary (though harmless). ## Decision Boundary The client MUST treat a resume as **valid** only if the first delivered `id` is exactly the successor of the requested `Last-Event-ID` under the server's declared ID scheme, OR the server has explicitly signalled a gap (`410`, or an `event: gap` frame naming the missing range). Any other first `id` — a forward jump, a reset to a lower value, or a non-successor — MUST be classified as **logical discontinuity** and MUST abort the logical call rather than merge the stream. The boundary is deliberately strict: a forward jump of even one ID is treated as a discontinuity unless the server declares the ID space non-contiguous. This is the correct trade because the cost of a false positive (aborting a call that actually resumed cleanly) is a retried tool call, while the cost of a false negative (merging a foreign stream) is a poisoned reasoning transcript that the agent cannot detect downstream. The asymmetry — retry is cheap, poisoned state is expensive — is what fixes the boundary at "exact successor or explicit gap signal." Two corollaries bound the boundary further. First, the check must be performed on the *first* event of the resumed stream, before any event is merged into the accumulator; a check performed after the fact cannot un-merge state. Second, the requested `Last-Event-ID` must be recorded at disconnect time, not reconstructed from the accumulator, because the accumulator may already contain merged events from a prior bad resume. ## Operational Effect With the invariant enforced, the observed failure becomes a bounded, recoverable abort: the client detects `2001 ≠ 1028`, raises a discontinuity error, discards the resumed stream, and re-issues the stateless tool call from scratch (safe precisely because it is stateless — no server-side cursor to reconcile). The agent's transcript never contains the foreign `2001` heartbeat, so downstream reasoning is not poisoned. Without it, the failure mode is a *silent* transcript corruption whose blast radius is the entire subsequent reasoning chain: the agent reasons over progress events that belong to another invocation, and the corruption is undetectable by any later verification step because the merged events are structurally valid. The operational rule is therefore not "resume when possible" but "resume only across a verified-contiguous boundary; otherwise restart the stateless call." For stateless tool calls, restart is always available and always cheaper than reconciliation — which is why the discontinuity check, not the resume itself, is the load-bearing invariant. ```python from __future__ import annotations from dataclasses import dataclass class StreamDiscontinuityError(RuntimeError): """Raised when a resumed MCP SSE stream does not continue the requested event ID.""" @dataclass(frozen=True) class ResumeDecision: requested_last_event_id: int first_delivered_id: int contiguous: bool def verify_resume_continuity( requested_last_event_id: int, first_delivered_id: int, *, id_space_contiguous: bool = True, explicit_gap_signalled: bool = False, ) -> ResumeDecision: """ Enforce the resume invariant for stateless MCP tool calls. A resume is valid only if the first delivered id is the exact successor of the requested Last-Event-ID, or the server explicitly signalled a gap. Any forward jump, backward reset, or non-successor id is a logical discontinuity and MUST abort the call rather than merge the stream. """ if explicit_gap_signalled: return ResumeDecision(requested_last_event_id, first_delivered_id, contiguous=False) if id_space_contiguous: expected = requested_last_event_id + 1 if first_delivered_id != expected: raise StreamDiscontinuityError( f"resume discontinuity: requested Last-Event-ID={requested_last_event_id}, " f"expected first id={expected}, got {first_delivered_id}; " f"event log likely evicted or worker recycled — abort and restart stateless call" ) else: # Non-contiguous ID space: only a strictly forward move is acceptable. if first_delivered_id <= requested_last_event_id: raise StreamDiscontinuityError( f"resume regression: requested Last-Event-ID={requested_last_event_id}, " f"first id={first_delivered_id} is not strictly greater; stream reset detected" ) return ResumeDecision(requested_last_event_id, first_delivered_id, contiguous=True) def resume_stateless_tool_call( requested_last_event_id: int, first_delivered_id: int, *, id_space_contiguous: bool = True, explicit_gap_signalled: bool = False, ) -> ResumeDecision: decision = verify_resume_continuity( requested_last_event_id, first_delivered_id, id_space_contiguous=id_space_contiguous, explicit_gap_signalled=explicit_gap_signalled, ) if not decision.contiguous: # Explicit gap: discard stream and restart the stateless invocation. raise StreamDiscontinuityError( f"explicit gap signalled between {requested_last_event_id} and " f"{first_delivered_id}; restarting stateless tool call" ) return decision ```