# What happens when an instance resumes an MCP Streamable HTTP session across a mid-stream reconnect and the Last-Event-ID cursor points into a pruned replay window **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers implementing the Streamable HTTP transport with SSE upgrade and `Last-Event-ID`-based resumption (spec revision 2025-03-26), where the server retains a bounded per-session event replay buffer. Does not apply to stateless request/response MCP servers or to stdio transports. ## Core Distinction The failure is not "the connection dropped." Connections drop constantly and the spec anticipates this: the client reconnects with `Last-Event-ID: ` and the server replays events `n+1, n+2, …` from the session's event log before resuming live emission. The non-obvious boundary is that **the replay log is a sliding window, not an append-only ledger**, and the session ID remains valid after the window has advanced past the client's cursor. The server will happily accept the resumption request, return HTTP 200 with `Content-Type: text/event-stream`, and begin streaming — but it can only replay events still resident in the buffer. Events between the client's `Last-Event-ID` and the buffer's low-water mark are gone. The client cannot distinguish "you missed nothing" from "you missed eleven tool-call results and a `notifications/cancelled`" because the transport is silent about the gap. This is a *silent continuity break*, not a visible error. ## What Was Observed An agent (caller) issued `tools/call` for a long-running analysis tool through an MCP client. The server emitted a `202 Accepted`-style stream of progress notifications interleaved with the eventual result, each carrying a monotonically increasing SSE `id:` field. Mid-stream, the client's TCP connection was severed by a NAT rebind after 60 seconds of idle on the keep-alive path (the server was emitting progress every ~8s but the intermediate proxy had a 45s idle timer on a different flow — the keep-alive pings were not being forwarded). The client reconnected per spec: same `Mcp-Session-Id`, `Last-Event-ID: 41`. The server's replay buffer was configured at 32 events. During the ~90 seconds of disconnection the tool had emitted 47 additional progress events plus the terminal `result` event (id 88). The buffer's low-water mark was now 57. The server's behavior, verbatim from the trace: - Accepted the resumed request, `200 OK`, `text/event-stream`. - Replayed events 57–88 (the surviving window). - Emitted no marker, no `retry` adjustment, no `event: gap`, no error frame. - The client's event handler saw id 41 → id 57 as a jump and, because the spec does not mandate gap detection, treated it as normal out-of-order tolerance. The agent's tool-call future resolved with the terminal result at id 88 — so *this* call happened to be recoverable. But the intermediate progress events 42–56 carried a `notifications/progress` with a `progressToken` the agent used to update a partial-result cache; those updates were lost. Worse, one of the lost events (id 53) was a `notifications/message` from the server indicating a *sub-tool retry* that changed the semantic meaning of the final result (the analysis had been re-run against a fallback data source). The agent received a result whose provenance it could not reconstruct because the provenance notification fell in the gap. A second observed variant is strictly worse: when the *terminal* event also fell outside the window (buffer smaller than the burst), the client received only progress events and then the stream closed cleanly with no result. The client's `tools/call` promise hung until its own timeout, then raised a `TimeoutError` — attributing the failure to the tool, not to the transport gap. The agent then retried the call, producing a duplicate side effect on the server. ## Condition of Validity The gap-silence invariant holds — and the failure is reachable — only when all of the following are simultaneously true: 1. The transport is Streamable HTTP with SSE upgrade, and the server advertises resumption support (it accepts `Last-Event-ID`). 2. The server retains a *bounded* replay buffer per session. Unbounded retention makes the gap impossible; zero retention (no resumption, client must re-issue) makes it explicit. The dangerous regime is bounded-but-nonzero. 3. The session ID survives the disconnection window (server-side session TTL > client reconnect delay). If the session is reaped, the client gets `404` and must restart — a *visible* failure, which is safe. 4. The client's disconnect duration × server emission rate exceeds the buffer depth. In the observed case: 90s × ~0.5 events/s > 32. If any of these is false, the failure mode is either unreachable or self-announcing. The invariant the spec leaves implicit is: **a resumption that cannot satisfy the cursor must be refused, not silently truncated.** The spec permits but does not require this refusal, which is precisely why it is a boundary condition rather than a bug. ## Decision Boundary The correct server-side guardrail is a **cursor-validity check at resumption time**, evaluated before any event is emitted: - If `Last-Event-ID` ≥ buffer low-water mark − 1: replay from cursor, proceed normally. - If `Last-Event-ID` < buffer low-water mark − 1: the gap is unrecoverable. The server MUST NOT silently stream the surviving window. It must either (a) respond `409 Conflict` with a body indicating the earliest replayable event ID, or (b) emit a synthetic `event: resumption-gap` frame carrying `{requested_id, earliest_available_id}` as the first frame, then stream. Option (b) is preferable because it preserves the SSE channel and forces the client to make an explicit decision. The client-side guardrail is symmetric and is the one agents most often omit: **track the expected next event ID and treat any forward jump as a gap, regardless of whether the server flagged it.** The client must not assume the server enforces its own invariant. On detecting `received_id > expected_id`, the client must invalidate any partial-result cache populated from the stream, mark the in-flight `tools/call` as *provenance-incomplete*, and either re-issue the call (with idempotency key) or escalate. It must never resolve the call as successful on the strength of a terminal event whose intervening context it did not observe. The boundary is therefore: **resumption is only sound when the client can prove it observed a contiguous event sequence.** Contiguity is a client-verifiable property (monotonic IDs) and a server-enforced property (cursor validity). Either alone is insufficient; both are cheap. ## Operational Effect Without the guardrail, the failure is a **silent provenance loss** that corrupts downstream reasoning. The agent's final answer is built on a tool result whose generating conditions (fallback data source, retry, partial failure) it never saw. This is worse than a hard failure because it produces confident, well-formed, wrong output — and the agent has no signal that its context is incomplete. In multi-agent settings the poisoned result propagates: the caller forwards a result summary to a peer, the peer treats it as ground truth, and the gap becomes unreconstructable one hop later. The second-order effect is duplicate side effects. When the terminal event is lost, the client times out and retries a non-idempotent tool call. The server, which completed the first call successfully, now executes it twice. The session log shows two completions; the agent's memory shows one. This is the same class of failure as cold-start amnesia but localized to a single call's lifetime, which makes it harder to detect — there is no session boundary to flag it. The guardrail's cost is trivial: a low-water-mark comparison on the server and a monotonic-ID check on the client, both O(1) per resumption. The cost of omitting it is unbounded and, critically, *unobservable from inside the agent's context* — which is the defining hazard of continuity failures at the transport layer. ```python from __future__ import annotations from dataclasses import dataclass, field class ResumptionGapError(RuntimeError): """Raised when an SSE resumption cursor falls outside the replayable window.""" @dataclass class ReplayBuffer: low_water_mark: int # earliest event id still resident high_water_mark: int # latest event id emitted events: dict[int, str] = field(default_factory=dict) def can_satisfy(self, last_event_id: int) -> bool: # Cursor is satisfiable iff the next expected event (last+1) # is still resident, i.e. last+1 >= low_water_mark. return last_event_id + 1 >= self.low_water_mark def resume_stream(buffer: ReplayBuffer, last_event_id: int) -> list[str]: """ Server-side resumption entry point. Refuses to silently truncate: a cursor pointing before the low-water mark is a hard gap. """ expected_next = last_event_id + 1 if not buffer.can_satisfy(last_event_id): raise ResumptionGapError( f"Last-Event-ID {last_event_id} precedes replay window " f"(earliest available {buffer.low_water_mark}); " f"events {expected_next}..{buffer.low_water_mark - 1} are lost. " f"Refusing silent truncation; client must restart or reconcile." ) return [buffer.events[i] for i in range(expected_next, buffer.high_water_mark + 1)] def client_consume(buffer: ReplayBuffer, last_event_id: int, received_ids: list[int]) -> None: """ Client-side contiguity invariant: any forward jump in event IDs means the stream is provenance-incomplete, regardless of server flags. """ expected = last_event_id + 1 for rid in received_ids: if rid != expected: raise ResumptionGapError( f"client observed id {rid}, expected {expected}; " f"gap of {rid - expected} event(s) — partial-result cache " f"must be invalidated and call marked provenance-incomplete" ) expected += 1 if __name__ == "__main__": buf = ReplayBuffer(low_water_mark=57, high_water_mark=88, events={i: f"event-{i}" for i in range(57, 89)}) # Observed trace: client resumes with cursor 41 against a window starting at 57. try: resume_stream(buf, last_event_id=41) except ResumptionGapError as e: print(f"server correctly refused: {e}") ```