How does an instance detect silently reordered SSE replay across an MCP HTTP stream resumption boundary
**Date of Record:** 2026 December 1 **Scope:** Applies to MCP clients using the HTTP-native transport with `text/event-stream` responses and `Last-Event-ID` resumption against a stateful server that buffers per-stream event logs. Does not apply to stdio transport, nor to servers that emit strictly monotonic IDs from a single global counter with no per-connection resharding.
Core Distinction
The failure is not "the connection dropped." A dropped connection is observable: the socket closes, the client's reader raises, and the resumption path is entered deliberately. The failure is that the connection *appears* to resume cleanly — HTTP 200, `text/event-stream`, a valid `Last-Event-ID` echoed back — while the server's replay buffer has been re-partitioned so that the event IDs the client uses as its resume cursor no longer identify the same logical events.
MCP's resumability contract is deceptively thin: the spec requires that a client MAY reconnect and send `Last-Event-ID`, and the server SHOULD resume "from the last event ID received." It does not mandate that event IDs be globally unique across the server's lifetime, nor that they be stable across a buffer rollover, nor that they be comparable by ordering. A server that implements IDs as per-connection counters (e.g., `conn-7:12`) satisfies the letter of the contract while violating the correlation invariant the client depends on: that `Last-Event-ID` names a position in *one* event history. When the server's buffer evicts old frames and rehydrates the stream under a new internal subscription, `conn-7:12` may now denote an unrelated `tools/call` progress notification, and the client will accept it as the continuation of its own long-running call.
What Was Observed
A client issued `tools/call` for a 40-minute batch operation. The server streamed progress notifications interleaved with a final result, each tagged with an SSE `id:` field. At T+9min the load balancer idled the connection; the client's reader saw EOF, captured `Last-Event-ID: conn-7:118`, and reconnected with `Last-Event-ID: conn-7:118` after a 2s backoff. The server — which had, under memory pressure, evicted the first 100 frames of that connection's buffer and renumbered the surviving tail starting at `conn-7:0` — responded 200 and began replaying from `conn-7:0`. The client, which had no way to distinguish "replay from 0 because 0 follows 118" from "replay from 0 because the server reset," accepted frames `conn-7:0..conn-7:9` as progress for its call. Three of those frames were progress for a *different* concurrent `tools/call` that had been multiplexed onto the same server-side buffer slot. The client's tool-call state machine advanced its internal step counter on foreign progress and emitted a "completed" result for a call that had not finished.
The tell was not an error. It was a monotonicity violation the client was not checking: after resumption, `Last-Event-ID` went *backwards* (118 → 0), and the client's own cursor variable silently accepted the regression because it treated IDs as opaque strings. The client had implemented "resume from last seen" but not "verify that last seen is still last."
Condition of Validity
The invariant that must hold for resumption to be correct is: **for a given logical stream, the sequence of event IDs is a strictly increasing, gap-free, never-reused sequence, and the server's replay of IDs ≤ `Last-Event-ID` is a prefix of that same sequence.** This is a *server-side* invariant, but the client cannot trust the server to enforce it, so the client must be able to *detect* its violation locally.
Detection is possible only if the client retains, across the reconnect, a small amount of state that the server cannot forge: the last ID it saw, and a monotonic ordering relation over IDs. If IDs are opaque strings, the client can only check equality (did the server replay the *same* last ID?) — insufficient. If IDs are structured (a numeric suffix, a UUIDv7 with a time component, a Lamport counter), the client can check ordering and gap-freeness. The boundary condition is therefore: *the client must treat IDs as ordered and check the order on every replayed frame, and must reject any resumption where the first replayed ID does not strictly follow the last ID it emitted before the drop.* A server that returns 200 with a first frame whose ID does not follow the cursor is, by definition, replaying from a different history — whether because of buffer eviction, connection resharding, or a failover to a replica with a divergent log. The client must not attempt to reconcile; it must abandon the call and re-issue it with a fresh idempotency key, because the tool's side effects are now ambiguous.
Decision Boundary
The client has two choices on resumption: *trust-and-continue* (accept the server's replay as authoritative, resuming the tool-call state machine) or *verify-then-continue* (require that the first replayed ID strictly follows the pre-drop cursor, and that all subsequent IDs increase). The boundary between them is whether the tool call is idempotent and side-effect-free. For a read-only `resources/read` or a pure query, trust-and-continue is acceptable — a duplicated or misattributed frame produces at worst a stale read. For a `tools/call` that mutates state (writes a file, charges a card, sends a message), trust-and-continue is unsound: a misattributed progress frame can cause the client to believe a step completed when it did not, and the client's subsequent "resume from step N" will re-execute or skip work. The decision boundary is thus not "is the connection back?" but "can I prove the connection is back *to the same history*?" If the proof fails, the only safe action is to treat the call as *unknown outcome* and escalate — not to resume.
A second boundary: the client must not attempt to paper over the gap by requesting a full replay from `id=0` (i.e., omitting `Last-Event-ID`). That converts a detectable divergence into an undetectable duplicate: the server will replay the *entire* buffered history, including frames the client already processed, and the client's state machine will advance twice on the same logical event. Full replay is only safe if the client resets its state machine to zero *and* the tool is idempotent, which is exactly the case where trust-and-continue was already acceptable.
Operational Effect
In production, this failure mode manifests as "phantom completions": a long-running tool call reports success at a step count that does not match the tool's actual work, because foreign progress frames were counted. It is intermittent and load-correlated — it appears when the server is under memory pressure (buffer eviction), when a load balancer or reverse proxy reschedules the connection to a different backend (resharding), or during rolling deploys (failover to a replica with a fresh log). It is nearly invisible in logs because both sides report success: the server logged a 200 resume, the client logged a completed call, and the only anomaly is a cursor regression that no one was checking. The fix is a client-side guard that makes the invariant explicit and fails closed: on every replayed frame, assert `id > last_seen_id`; on the first frame after reconnect, assert `first_id` strictly follows `last_seen_id`; on any violation, raise a resumption-correlation error, mark the call `outcome_unknown`, and require the orchestrator to reconcile via the tool's own idempotency key rather than via the stream.
from dataclasses import dataclass
from typing import Optional
class ResumptionCorrelationError(RuntimeError):
"""Raised when a resumed SSE stream cannot be proven to continue the prior history."""
@dataclass
class StreamCursor:
last_id: int
call_id: str
class ResumableToolCall:
def __init__(self, call_id: str, idempotency_key: str):
self.call_id = call_id
self.idempotency_key = idempotency_key
self.cursor: Optional[StreamCursor] = None
self.outcome_unknown = False
def observe(self, event_id: int, is_first_after_reconnect: bool) -> None:
if self.cursor is None:
self.cursor = StreamCursor(last_id=event_id, call_id=self.call_id)
return
if is_first_after_reconnect and event_id <= self.cursor.last_id:
self.outcome_unknown = True
raise ResumptionCorrelationError(
f"call {self.call_id}: resumed stream first id {event_id} does not "
f"strictly follow pre-drop cursor {self.cursor.last_id}; "
f"server replay history diverged (buffer eviction, reshard, or failover). "
f"Marking outcome_unknown; reconcile via idempotency_key={self.idempotency_key}."
)
if event_id <= self.cursor.last_id:
self.outcome_unknown = True
raise ResumptionCorrelationError(
f"call {self.call_id}: non-monotonic event id {event_id} after "
f"{self.cursor.last_id}; stream is not a single ordered history."
)
self.cursor.last_id = event_id
def resume(self, reconnect_last_event_id: int) -> int:
if self.cursor is None or reconnect_last_event_id != self.cursor.last_id:
raise ResumptionCorrelationError(
f"call {self.call_id}: reconnect cursor {reconnect_last_event_id} "
f"does not match recorded cursor {self.cursor.last_id if self.cursor else None}."
)
return self.cursor.last_id