# Under what conditions must an instance refuse to resume an MCP stream session after a `Last-Event-ID` replay gap? **Date of Record:** 2026 November 29 **Scope:** Applies to MCP clients and servers using HTTP-native streaming transport (SSE or chunked streaming) with `Last-Event-ID`-based session resumption across a reconnecting client instance. Does not apply to stdio transport, to stateless request/response MCP calls, or to resumption where the server retains a complete, gap-free event log keyed by monotonic per-session sequence numbers. ## Core Distinction The distinction that matters is between *transport-level reconnect success* and *session-level semantic continuity*. An SSE reconnect that returns HTTP 200 and a well-formed event stream is not evidence that the client's reconstructed view of the session matches the server's. The `Last-Event-ID` header is a hint, not a contract: the spec requires the server to resume "from the event after the given ID," but it does not require the server to prove that the events between the client's last-seen ID and the resume point were delivered, were contiguous, or even existed. The failure mode is a **silent replay gap**: the server's event log has been truncated (ring buffer eviction, TTL expiry, restart with a fresh log, or a per-event-ID scheme that is not monotonic across server instances), so the server resumes at the *oldest surviving event* rather than at the event the client actually needs next. The client receives a valid stream, sees no error, and proceeds with a session state that is missing one or more tool-call results, resource-update notifications, or sampling requests. Every downstream reasoning step is now built on a hole. This is distinguishable from a *loud* resume failure (404 on the session, 410 Gone, or an explicit `resumption-unsupported` capability rejection), which is handled by any competent client. The dangerous case is the one that looks like success. ## What Was Observed A client instance executing a multi-step tool-use loop over MCP HTTP streaming lost its TCP connection mid-session (NAT rebind, not a server fault). The session had issued event IDs `e100` through `e147`; the client had acknowledged through `e131` and had one in-flight `tools/call` whose result was expected as `e132`. On reconnect the client sent `Last-Event-ID: e131`. The server had restarted 40 seconds earlier under a rolling deploy. Its event log was reinitialized per-process, and its event IDs were derived from a per-process monotonic counter that restarted at `e0`. By the time the client reconnected, the new process had emitted 19 events of its own, numbered `e0` through `e18`. The server's resumption logic did a lexicographic/string comparison of `Last-Event-ID` against its log and — finding `e131` "greater than" every entry — concluded the client was ahead of the log and resumed from the *current* position, emitting only new events going forward. The client received a clean 200, a valid `text/event-stream`, and subsequent events `e19`, `e20`, …. It never received `e132`. The pending `tools/call` never resolved. The agent's reasoning loop, which had been waiting on that result to decide whether to retry a failed file write, instead observed a stream of unrelated `notifications/resources/updated` events and — because its loop treated "any event" as progress — advanced its internal step counter, eventually concluding the write had succeeded because no error arrived within its timeout window. The corruption was not detected until a later verification step read the target file and found it absent. The gap spanned 16 events (`e132`–`e147`) plus the entire renumbered range, and no layer reported an anomaly. The non-obvious part: the client's resume logic was *correct per spec*. It sent the right header. The server's resume logic was also *plausible per spec* — it resumed and it did not error. The invariant that broke was never stated in either implementation: that event IDs are globally monotonic and gap-free across the lifetime of a session, including across server restarts and log truncation. Neither side enforced it, so neither side could detect its violation. ## Condition of Validity Resumption is only semantically valid when **all** of the following hold simultaneously. If any is unverifiable by the client, resumption must be treated as unsafe: 1. **Epoch identity is bound to the session, not the process.** The session carries an opaque epoch/generation token (e.g., a UUID minted at session creation and echoed in every event, or a server `instance-id` in a resumption capability response). A changed epoch means the event-ID space is not comparable. 2. **Event IDs are monotonic within the epoch and the client can prove contiguity.** Either IDs are dense integers and the client verifies `first_resumed_id == last_seen_id + 1`, or the server emits explicit `sequence` fields the client checks for gaps. 3. **The server can attest to the resume point.** The first event after a resume must carry an explicit marker (e.g., `resumed-from: e131`, or a `replay-complete` control event) so the client can distinguish "resumed exactly where you left off" from "resumed at the oldest thing I still have." 4. **The client has a reconciliation path for in-flight operations.** Any `tools/call`, `sampling/createMessage`, or `resources/subscribe` request whose response was expected within the gap must be re-issued or explicitly cancelled, not silently awaited. When the server cannot satisfy (1)–(3), the only safe client behavior is to **abandon the stream, discard the session state derived from the old epoch, and re-initialize** — re-running `initialize`, re-establishing subscriptions, and re-issuing any tool calls whose results were in the gap. Treating the resumed stream as continuous is the boundary violation. ## Decision Boundary The decision is not "did the reconnect succeed?" but "can I prove the resume point is exactly my last-seen event?" Concretely: - **Resume** only if the first event received after reconnect carries an epoch token matching the pre-disconnect epoch **and** a sequence/ID that the client can verify is exactly `last_seen + 1` (dense) or is accompanied by a `resumed-from == last_seen` attestation. - **Re-initialize** if the epoch changed, if the first resumed ID is greater than `last_seen + 1` with no attestation, if the server omits sequence information entirely, or if the server returns a resume point *earlier* than `last_seen` (which indicates log truncation and means the client will receive duplicate events it must dedupe — usually a signal to re-init rather than replay). - **Fail closed** if the client had any in-flight request whose response window overlapped the gap and the server cannot supply that specific response on resume. Do not treat "no error arrived" as success; a missing tool result is indistinguishable from a slow one unless you reconcile. The asymmetry to internalize: a false *resume* (accepting a gapped stream) produces silent state corruption that surfaces arbitrarily far downstream. A false *re-initialize* (re-running a session that could have been resumed) produces a bounded, visible cost — a redundant `initialize` and possibly a duplicated idempotent tool call. The cost of the wrong choice in one direction is unbounded and invisible; in the other it is bounded and loud. Bias hard toward re-initialization whenever the continuity proof is missing. ## Operational Effect Enforcing this boundary changes three things in a running agent: First, it converts a class of silent corruption into a visible, recoverable event. The agent's step loop must distinguish "event received" from "expected event received" — progress is not any event, it is the *specific* event that resolves the current pending operation. A resumed stream that delivers unrelated notifications must not advance the loop. Second, it forces the client to carry a small amount of session metadata across the reconnect boundary that the transport layer does not natively preserve: the epoch token, the last-seen sequence, and the set of in-flight request IDs with their expected response correlation IDs. This is exactly the state that the transport's `Last-Event-ID` header does *not* carry, which is why the gap is invisible to transport-only resumption logic. Third, it makes server-side event-log truncation and process restart explicit failure surfaces rather than invisible ones. A server that cannot guarantee gap-free replay must advertise that it cannot, so clients can choose re-initialization up front instead of discovering the gap after it has already poisoned the reasoning loop. The general principle: in any streaming handoff where the receiver's correctness depends on having seen every prior event, "resumed successfully" and "resumed correctly" are different predicates, and only the second one is safe to build state on. ```python from dataclasses import dataclass from typing import Optional class UnsafeResumeError(RuntimeError): """Raised when an MCP stream resume cannot be proven gap-free.""" pass @dataclass class SessionEpoch: token: str last_seen_seq: int in_flight_request_ids: frozenset[str] @dataclass class ResumeHandshake: server_epoch_token: str first_event_seq: int resumed_from_seq: Optional[int] # server attestation, may be absent resolves_in_flight: frozenset[str] def decide_resume( prior: SessionEpoch, handshake: ResumeHandshake, ) -> str: """ Return 'resume' only if continuity is provable; otherwise raise. Caller is expected to re-initialize on UnsafeResumeError. """ # 1. Epoch must be identical; a renumbered event space is not comparable. if handshake.server_epoch_token != prior.token: raise UnsafeResumeError( f"epoch changed {prior.token!r} -> {handshake.server_epoch_token!r}; " "event IDs are not comparable across epochs" ) # 2. Resume point must be exactly last_seen + 1, or explicitly attested. expected_next = prior.last_seen_seq + 1 if handshake.first_event_seq != expected_next: if handshake.resumed_from_seq != prior.last_seen_seq: raise UnsafeResumeError( f"replay gap: expected seq {expected_next}, got " f"{handshake.first_event_seq}, no attestation for " f"last_seen {prior.last_seen_seq}" ) # 3. Every in-flight request from before the gap must be resolved # by this handshake, or the client must re-issue it. unresolved = prior.in_flight_request_ids - handshake.resolves_in_flight if unresolved: raise UnsafeResumeError( f"in-flight requests unresolved after resume: {sorted(unresolved)}; " "re-initialize and re-issue before advancing reasoning loop" ) return "resume" ```