# How should an instance reconcile SSE event-ID replay against a resumable MCP stream after a transport drop **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients and servers using the HTTP-native transport with Server-Sent Events streaming and `Last-Event-ID`-based session resumption. Does not cover stdio transport, stateless request/response JSON-only MCP, or WebSocket transports with their own replay semantics. ## Core Distinction The failure here is not "the connection dropped." Drops are expected and are precisely what resumption is designed to absorb. The failure is that **event-ID monotonicity and session state monotonicity are two different orderings that the client silently conflates.** The SSE `id:` field is a stream-local sequence the server emits; it is *not* a transaction log of MCP protocol state. A server that emits `id: 41` for a `tools/call` progress notification and then, after a reconnect, replays from `Last-Event-ID: 41`, will re-deliver events that the client has already applied to its local tool-result buffer—or skip events whose IDs were consumed by a different logical substream (e.g., a concurrent notification channel multiplexed onto the same session). The invariant that must hold for safe resumption is: *for every event ID the server will replay, the corresponding protocol-state mutation is idempotent under redelivery, and no event with an ID strictly greater than the client's `Last-Event-ID` was ever observed out of order.* MCP's HTTP transport as specified does not guarantee the second clause unless the server enforces it. That is the boundary. ## What Was Observed A client agent issued `tools/call` for a long-running operation (a browser-automation tool with 90s of intermediate `notifications/progress` events). At t=34s the underlying TCP connection was closed by an intermediate proxy (idle timeout on a connection the proxy considered quiescent because the client had not sent bytes since the initial POST). The client's SSE reader raised a read timeout, and the client reconnected with `Last-Event-ID: 12`—the last fully-parsed event, because event 13 had arrived partially and was discarded mid-frame. The server, on reconnect, replayed from event 13 onward. Events 13 through 18 were progress notifications with `progressToken` values that the client had *already* recorded as received in a prior partial read (the client had parsed the JSON body of event 13 before the connection died, but had not yet committed the `id` to its `Last-Event-ID` cursor because the cursor update was gated on a successful frame terminator). The client's progress-aggregation logic treated the replayed events as *additional* progress, not duplicates, because progress notifications carry no deduplication key beyond the `progressToken`—and the client's handler for `progressToken` incremented a counter rather than setting an absolute value. The tool's final result, arriving at event 47, reported `progress: 100` but the client's counter read `progress: 118`, tripping a sanity assertion and aborting the session. The root cause is a **cursor-commit ordering bug at the client**, exposed by a **replay contract the server honored literally but the client did not expect**. The server did nothing wrong per spec. The client did nothing wrong per spec. The *composition* failed. ## Condition of Validity `Last-Event-ID` resumption is safe **only** when all three of the following hold: 1. **Frame-atomic cursor commit.** The client MUST update its persisted `Last-Event-ID` cursor in the same atomic step that it applies the event's payload to protocol state. If the cursor advances before the payload is applied, a crash between the two loses the event. If the payload is applied before the cursor advances, a crash between the two causes redelivery—and redelivery is only safe if the handler is idempotent. The client in the trace above applied payload, then crashed before cursor commit, then got redelivery into a non-idempotent handler. 2. **Replay window bounded by server retention.** The server MUST retain the event log for at least `max(client reconnect backoff) × max(in-flight tool duration)`. If the server's retention window is shorter than the client's reconnect horizon, the server will respond to `Last-Event-ID: 12` with a fresh stream starting at some `id: 200`, and the client will silently accept a gap of 188 events. MCP does not mandate a retention floor; servers commonly retain "the last N events" or "events for 5 minutes," neither of which is derived from client behavior. 3. **No multiplexed substreams on one ID space.** If the server interleaves progress notifications, log notifications, and resource-update notifications on one SSE stream under one ID sequence, then replay re-delivers *all* of them, and the client must be idempotent across *all* notification types, not just the one it was tracking. The trace above failed because the client was idempotent for tool results but not for progress. When any of these fails, resumption does not resume; it **re-executes a prefix of the session against a state machine that has already advanced past it.** ## Decision Boundary The operational decision is: **when a reconnect occurs, does the client trust the replay stream, or does it re-derive state?** - If the client's handlers are idempotent across every notification type on the stream, and the server's retention window provably exceeds the client's reconnect horizon, then trust replay: send `Last-Event-ID` and process redelivered events normally. - If either condition is unproven, the client MUST NOT send `Last-Event-ID`. Instead it must open a fresh stream and re-issue the in-flight request with a client-generated idempotency key (e.g., a `requestId` in `_meta`), forcing the server to return the cached result for that key rather than replaying the event log. This trades a re-execution risk for a duplicate-execution risk, and the duplicate-execution risk is bounded by the idempotency key, whereas the re-execution risk is unbounded by anything the client controls. - The boundary is **not** "did the connection drop." It is "can I prove, for this specific server, that its replay is a superset of my applied state and a subset of its retained log." Absent that proof, `Last-Event-ID` is a hazard, not a recovery mechanism. A corollary the trace makes concrete: a client that cannot distinguish "event partially received" from "event fully received but cursor not committed" will *always* be at risk, because the SSE frame terminator (`\n\n`) is the only signal of completeness, and a TCP reset mid-frame is indistinguishable at the application layer from a slow frame. The cursor must be committed on frame terminator, not on payload application, and the payload application must be idempotent to absorb the redelivery that this ordering makes possible. ## Operational Effect Concretely, the guardrail is a two-part client change: (a) commit `Last-Event-ID` at frame-parse completion, before dispatch, and (b) make every notification handler idempotent by keying on `(progressToken, absolute_value)` for progress, `(log_id)` for logs, and `(resource_uri, version)` for resource updates—never on counters or relative deltas. With those in place, redelivery is a no-op and resumption is transparent. Without them, resumption is a state-corruption vector that only manifests under proxy-induced mid-stream drops, which is exactly the condition that does not appear in local testing and does not appear in clean-network integration tests, but does appear in production behind any load balancer with an idle timeout shorter than the longest tool call. The second guardrail is server-side and is a contract the client should negotiate at session init: a `resumptionRetentionSeconds` capability in the initialize handshake, so the client can decide *before* the first tool call whether to trust `Last-Event-ID` or to route through idempotency keys. A client that assumes retention is infinite is a client that will one day accept a silent gap. The failure is silent, the failure is composition-dependent, and the failure is invisible until a proxy with the wrong timeout meets a tool with the wrong duration. That is the boundary. ```python class ResumptionGapError(RuntimeError): """Raised when an SSE replay stream cannot be reconciled with client state.""" class ReplayCursor: def __init__(self, retention_seconds: int, reconnect_horizon_seconds: int): self.last_event_id: int | None = None self.retention = retention_seconds self.horizon = reconnect_horizon_seconds self.applied_progress: dict[str, int] = {} def commit_frame(self, event_id: int, payload: dict) -> None: # Commit cursor and payload atomically, at frame terminator. if self.last_event_id is not None and event_id <= self.last_event_id: # Redelivery: must be idempotent, not additive. self._apply_idempotent(payload) return self._apply_idempotent(payload) self.last_event_id = event_id def _apply_idempotent(self, payload: dict) -> None: token = payload.get("progressToken") if token is None: return value = payload.get("progress") if value is None: raise ResumptionGapError(f"progress event missing value for {token}") # Absolute assignment, not increment: redelivery is a no-op. self.applied_progress[token] = value def reconnect(self, server_last_id: int, server_retained_from: int) -> None: if self.retention < self.horizon: raise ResumptionGapError( f"server retention {self.retention}s < client horizon {self.horizon}s; " "Last-Event-ID replay is unsafe" ) if self.last_event_id is not None and server_retained_from > self.last_event_id: raise ResumptionGapError( f"server retained log starts at {server_retained_from}, " f"client cursor {self.last_event_id} is beyond retention; gap of " f"{server_retained_from - self.last_event_id} events" ) if server_last_id < (self.last_event_id or 0): raise ResumptionGapError( "server replay head is behind client cursor; server state regressed" ) ```