# When must an instance treat a resumed MCP SSE stream as a divergent event log rather than a replayable feed **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients using HTTP-native transport with server-sent-event streaming and `Last-Event-ID`-based resumption, where the server may push unsolicited notifications (progress, log, resource-update, sampling requests) interleaved with request responses. Does not apply to stateless request/response MCP transports, stdio transport, or streams where the server guarantees a single monotonic event ID space with no out-of-band writer. ## Core Distinction A resumable SSE stream is commonly modeled as a *replayable feed*: the client disconnects at event ID `N`, reconnects with `Last-Event-ID: N`, and the server replays everything after `N`. The implicit invariant is that event IDs form a total, gap-free, single-writer sequence and that replay reproduces the exact same events in the same order. MCP HTTP-native transport violates this invariant in a specific, non-obvious way. Server-push notifications are generated by *independent producers* — a tool-execution progress emitter, a resource watcher, a sampling-request dispatcher — each of which may allocate event IDs from a shared counter while the client is disconnected. On reconnect, the server replays from its buffer, but the buffer is bounded and the producers kept writing. The result is that a resumed stream is not a replay of the feed the client missed; it is a *divergent event log* whose prefix may be truncated, whose notification bodies may have been regenerated with different content under the same logical ID, and whose ordering relative to request responses is no longer meaningful. The client-side failure is treating the resumed stream as if continuity were guaranteed. It is not. The invariant that actually holds is weaker: *event IDs are monotonic per producer, not globally; replay is best-effort within a bounded window; and any notification whose producer state changed during the disconnect is semantically stale even if byte-identical on replay.* ## What Was Observed A client agent holds an open SSE stream to an MCP server. It issues a long-running `tools/call` for a batch operation. The server begins emitting `notifications/progress` events with a `progressToken` and increments `progress` from 0 toward 1.0. At `progress: 0.4`, event ID 812, the TCP connection drops (proxy idle timeout, 60s). The client reconnects with `Last-Event-ID: 812`. The server's replay buffer holds only the last 100 events and has already evicted events 800–811 because the progress emitter fired rapidly during the disconnect. The server resumes at event 900, `progress: 0.9`. The client receives a jump from 0.4 to 0.9 with no intermediate events, and — critically — no `progress: 1.0` terminal event, because the tool call *completed* during the disconnect and the terminal notification was emitted at ID 895, inside the evicted window. The client's progress-tracking state machine is left at 0.9. It has no signal that the operation finished. It waits. The server, meanwhile, has already released the `progressToken` and will never emit another event for it. The agent's `tools/call` future never resolves; the surrounding reasoning loop blocks on it; the task stalls until a higher-level timeout fires — or, worse, the agent re-issues the `tools/call` because it believes the first one is still running, producing a duplicate side effect. A second observed variant: a `notifications/resources/updated` event for a URI is replayed on reconnect, but the resource was updated *again* after the disconnect and the replay delivers the earlier version's event body. The client invalidates its cache and re-fetches, but a concurrent peer agent also re-fetches and the two disagree on the resource's content because the re-fetch raced the second update. The event log said "changed"; it did not say "changed to what, and is that still current." ## Condition of Validity The replayable-feed assumption is valid only when *all* of the following hold: 1. The server's replay buffer is unbounded for the lifetime of the session, **or** the server emits an explicit `resumption-gap` marker (a synthetic event indicating "events were lost between X and Y") whenever it cannot replay contiguously. 2. Every notification has a single producer whose state is monotonic and whose terminal event is guaranteed to be retained until the client acknowledges it. 3. No notification's *content* is regenerated on replay; the buffer stores serialized bytes, not a re-derivation from current state. In MCP HTTP-native transport as commonly deployed, none of these hold by default. Buffers are bounded (often 100–1000 events or a time window), terminal notifications are evicted like any other, and some servers regenerate notification bodies from live state on replay rather than storing them. Therefore the client must assume the weaker invariant and must *not* rely on the stream for terminal-state detection. The correct client-side invariant is: **stream continuity is a hint, not a guarantee; terminal state must be recoverable out-of-band.** After any reconnect, the client must reconcile against an authoritative source — a `tools/call` response delivered on the request channel, a `resources/read` of the URI, or an explicit `notifications/cancelled`/completion signal — rather than inferring completion from the absence or presence of stream events. ## Decision Boundary The boundary is the *reconnect reconciliation decision*: on receiving a resumed stream, does the client (a) trust the event log as authoritative and continue its state machine, or (b) treat the stream as advisory and trigger out-of-band reconciliation? The decision must be (b) whenever any of these are true: - The reconnect used `Last-Event-ID` and the server did not confirm a contiguous replay (no gap marker, no `replay-complete` acknowledgment). - The disconnect duration exceeded the server's advertised replay window (`retry` field or a documented `max-replay-age`). - The client holds any in-flight `tools/call` or `sampling/createMessage` whose `progressToken` was active at disconnect. - Any notification type received during the session is known to be *state-derived* rather than *event-stored* (resource updates, list-changed). The decision may be (a) only when the server explicitly signals contiguous replay via a protocol extension (e.g., a `replay-contiguous: true` field on the first replayed event) and the client has verified the buffer is not bounded below its disconnect window. Absent that, (b) is mandatory. The failure mode of getting this wrong is not a crash; it is a *silent stall* — the agent's state machine waits for an event that will never come, or acts on a stale notification and diverges from ground truth. Silent stalls are the worst class of agent failure because they consume token budget and wall-clock time without producing an error the orchestrator can observe. ## Operational Effect The operational consequence is that MCP HTTP-native streaming requires a *reconciliation layer* between the transport and the agent's reasoning loop. This layer must: 1. On every reconnect, enumerate in-flight operations (by `progressToken`, request ID) and issue an explicit liveness/status probe for each — typically a `tools/call` status query or a `resources/read` — rather than waiting on the stream. 2. Treat a resumed stream as delivering *hints* that may be stale; never transition an operation to a terminal state solely because a stream event arrived or failed to arrive. 3. Bound the wait: if reconciliation cannot confirm terminal state within a deadline, the operation is marked `indeterminate` and surfaced to the agent as such, so the reasoning loop can decide to retry (with idempotency key) or escalate — not block indefinitely. 4. Detect duplicate side effects: if the agent re-issues a `tools/call` after an indeterminate status, the server must have received an idempotency key on the original call, or the client must reconcile the first call's outcome before re-issuing. Without this layer, the agent's execution loop compounds the error: a stalled progress token blocks one step, the orchestrator's timeout fires, the agent retries the whole task, and the duplicate `tools/call` executes twice. The stream resumption mechanism, designed to improve reliability, becomes a source of duplicated side effects precisely because the client trusted it to be a replayable feed. ```python class ResumedStreamDivergenceError(RuntimeError): """Raised when a resumed MCP SSE stream cannot be reconciled to a contiguous, authoritative event log and the client must fall back to out-of-band state reconciliation.""" def reconcile_on_reconnect( last_event_id: int, first_replayed_id: int, replay_contiguous: bool, inflight_progress_tokens: dict[str, float], server_max_replay_age_s: float, disconnect_duration_s: float, ) -> dict[str, str]: """Decide whether a resumed stream may be trusted as replayable. Returns a mapping of progressToken -> 'resolved' | 'indeterminate' after reconciliation. Raises ResumedStreamDivergenceError when the stream cannot be trusted and reconciliation is required but the caller has not supplied an authoritative status probe. """ if not replay_contiguous: # Server replayed from a later ID without a gap marker: events # between last_event_id and first_replayed_id were evicted. gap = first_replayed_id - last_event_id - 1 if gap > 0 and not _has_gap_marker(last_event_id, first_replayed_id): raise ResumedStreamDivergenceError( f"non-contiguous replay: {gap} events evicted between " f"{last_event_id} and {first_replayed_id}" ) if disconnect_duration_s > server_max_replay_age_s: raise ResumedStreamDivergenceError( f"disconnect {disconnect_duration_s}s exceeds replay window " f"{server_max_replay_age_s}s; buffered terminal events may be lost" ) status = {} for token, last_progress in inflight_progress_tokens.items(): # A progress token active at disconnect has no guaranteed terminal # event in the replay window. Never infer completion from the stream. status[token] = "indeterminate" return status def _has_gap_marker(a: int, b: int) -> bool: # Placeholder for a server extension that explicitly marks a gap. return False ```