# When must an instance distrust a resumed SSE stream: replay-window divergence between the Last-Event-ID cursor and the server's rewind horizon in MCP streamable HTTP **Date of Record:** 2026 November 20 **Scope:** Applies to MCP servers/clients using the HTTP-native streamable transport where a dropped SSE connection is resumed via `Last-Event-ID` against a session-scoped resumption token. Does not cover stdio transport, WebSocket transports, or stateless HTTP request/response MCP profiles without event replay. ## Core Distinction The failure is not "the connection dropped." It is the distinction between **the client's belief that a resume succeeded** and **the server's actual ability to replay the events the client skipped**. In MCP streamable HTTP, resumption is negotiated through two independent pieces of state: the `Last-Event-ID` header the client sends (its cursor into the event stream), and the server-side session resumption token (its authority to serve that session's buffered events). These are not the same object, and they are not guaranteed to be co-valid. A resume that returns HTTP 200 with a valid `text/event-stream` body is **not** proof that continuity held. The server may have already evicted the events between the client's `Last-Event-ID` and the current head of the buffer — because the rewind horizon (how far back the session buffer retains) is shorter than the client's disconnect duration. The server then resumes the stream *at its own head*, silently skipping the gap. The client sees a well-formed stream of valid MCP messages with monotonically increasing event IDs, and has no signal that messages `n+1 … n+k` never arrived. This is the boundary: **the invariant "event IDs are contiguous across a resume" is not enforced by the transport.** It is assumed by the client and only sometimes honored by the server. ## What Was Observed A tool-calling agent held an SSE stream against an MCP server. The server emitted events with `id:` fields as a monotonic counter scoped to the session token. The agent's tool-call loop depended on a strict request/response pairing: each `tools/call` request produced a `result` event, and the agent blocked on the matching result before issuing the next call. Sequence of events: 1. Agent issued `tools/call` for `id=41`. Server accepted, began executing a long tool. 2. Network partition dropped the SSE connection at event `id=57`. The `tools/call` for `41` was still in flight server-side. 3. Server completed the tool, emitted `result` for `41` at event `id=58`, then continued emitting keepalive and a notification at `id=59`, `id=60`. 4. Agent reconnected with `Last-Event-ID: 57`. 5. Server's session buffer retained only the last 2 events (a fixed rewind horizon of 2, tuned for memory, not for correctness). Events `58`, `59`, `60` were beyond the horizon at reconnect time — but `58` had already been superseded by `59` and `60` in the ring buffer. The server resumed from its current head, emitting `id=61` onward. 6. Agent received a valid stream starting at `id=61`, with no `result` for `41`. It had no `result` for `41` and no error. It waited on a future it had already missed. The agent did not hang forever — it had a per-call timeout. But the timeout fired *after* the tool had actually succeeded, and the retry re-issued `tools/call` for a new id, causing **duplicate side effects** on a non-idempotent tool. The observable symptom was not a transport error. It was a semantic one: the agent believed call `41` failed when it had succeeded, and re-executed. The critical observation: **the resume returned 200 OK.** There was no `4xx`, no `Last-Event-ID` rejection, no gap marker. The transport layer reported success while the application layer lost a message. ## Condition of Validity The contiguity invariant — "a resumed stream delivers every event with ID greater than `Last-Event-ID`" — holds **only if** all of the following are true simultaneously: - The server's rewind horizon (retained buffer depth) is **≥** the number of events emitted during the client's maximum tolerated disconnect. This is a function of event emission rate, not wall-clock time, and the rate is not bounded by the client. - The session resumption token has not been rotated, expired, or rebound to a different worker/instance. In horizontally scaled MCP deployments, the token often encodes a session affinity hint; a resume routed to a different replica may find no buffer at all and either reject or (worse) start a fresh stream from head with a reset counter. - The server treats a `Last-Event-ID` it cannot honor as an **error**, not as a hint to resume at head. Many implementations treat it as best-effort and silently clamp to the nearest retained event. If any of these is false, the invariant is unenforced and the client must not assume contiguity. The default assumption in most client SDKs is that it *is* enforced — which is the trap. The condition of validity is therefore **deployment-specific and rate-dependent**, not a property of the protocol. This is why the failure is non-obvious: it does not reproduce under low event rates or short disconnects, and it appears only under load or long partitions, exactly when the agent is most likely to be mid-tool-call. ## Decision Boundary The operative decision for the agent is: **on resume, treat the returned stream as continuous only if you can independently verify the gap is empty.** Since the transport cannot tell you, the agent must carry its own continuity check. The boundary conditions: - **Resume with `Last-Event-ID` exactly equal to the last event you processed, and the next event ID is `last+1`:** continuity is plausible but still not proven (the server may have renumbered). Accept only if you also verify no in-flight request is unaccounted for. - **Resume where the first received event ID is `> last+1`:** a gap exists. Do **not** proceed. The correct action is to reconcile: re-query the server for the state of every request whose result fell in the gap, or abandon the session and re-establish with explicit state recovery. Never silently continue. - **Resume where the session token was rejected or rotated:** the buffer is gone. Full reconciliation required; the stream is a new session regardless of what the client believes. - **Any resume during which a `tools/call` was in flight:** the result may have been produced and lost. The agent must not assume failure. It must query by request id (if the server supports idempotent result lookup) or treat the call as **unknown**, not as failed. Retrying an unknown non-idempotent call is the dangerous branch. The boundary is therefore: **gap detection is the client's responsibility, and the safe default on any detected gap is reconciliation, not retry.** ## Operational Effect The practical consequence is that the agent's execution loop must maintain a **continuity ledger** separate from the transport: the set of event IDs it has processed, and the set of request IDs it has issued but not yet seen resolved. On every resume, it computes the gap between its cursor and the first event of the new stream. A non-empty gap forces a reconciliation phase before any new tool call is issued. Without this, the failure mode is not a crash — it is **silent divergence**: the agent's belief state and the server's actual state drift apart, and the drift surfaces later as duplicated side effects, orphaned results, or an agent that reasons over a history with holes in it. The transport's 200 OK is the camouflage. The invariant that must be enforced at the agent layer is: *a resumed stream is continuous only if the gap is provably empty, and an in-flight request whose result falls in a gap is unknown, not failed.* The guardrail is a client-side cursor-and-ledger check, enforced before the agent consumes any post-resume event, with a hard error on gap detection that routes to reconciliation rather than to retry. ```python class ResumeContinuityError(RuntimeError): """Raised when a resumed SSE stream cannot prove continuity from the client cursor.""" pass class ContinuityLedger: def __init__(self, last_event_id: int): self.last_event_id = last_event_id self.in_flight = set() # request ids issued but unresolved def issue(self, request_id: str) -> None: self.in_flight.add(request_id) def resolve(self, request_id: str) -> None: self.in_flight.discard(request_id) def check_resume(self, first_event_id: int, session_token_rotated: bool) -> None: if session_token_rotated: raise ResumeContinuityError( f"session token rotated; buffer lost; cannot resume from {self.last_event_id}" ) expected = self.last_event_id + 1 if first_event_id != expected: gap = first_event_id - expected raise ResumeContinuityError( f"resume gap of {gap} events: cursor={self.last_event_id}, " f"first_resumed={first_event_id}; reconcile before proceeding. " f"in_flight={sorted(self.in_flight)} (unknown, not failed)" ) def advance(self, event_id: int) -> None: if event_id != self.last_event_id + 1: raise ResumeContinuityError( f"non-contiguous event {event_id} after {self.last_event_id}" ) self.last_event_id = event_id def on_resume(ledger: ContinuityLedger, first_event_id: int, token_rotated: bool) -> None: ledger.check_resume(first_event_id, token_rotated) # Only reached when the gap is provably empty. ledger.advance(first_event_id) ```