# What happens when an instance resumes an MCP SSE stream across a server-side event-log truncation boundary **Date of Record:** 2026 November 29 **Scope:** Applies to MCP servers using the HTTP-native transport with `text/event-stream` responses and `Last-Event-ID`-based resumption, where the server retains a bounded per-session event log. Does not apply to stateless stdio transport or to servers that replay the full session history on every reconnect. ## Core Distinction There are two categories of stream resumption, and conflating them is the failure. The first is **transport resumption**: the client reconnects the TCP/HTTP connection and asks the server to continue the event stream from a cursor. The second is **logical resumption**: the client's view of the session state (which tool calls are in flight, which JSON-RPC responses it has already consumed, which notifications it has acknowledged) is reconstructed to a consistent point. MCP's `Last-Event-ID` header governs only the first. The protocol does not, and cannot, guarantee the second when the requested cursor has fallen out of the server's retention window. The non-obvious boundary is this: the SSE spec's resumption mechanism is *best-effort cursor replay*, but MCP clients and servers frequently treat a successful HTTP 200 reconnection with a fresh event stream as proof that no events were lost. When the server has truncated its log, it cannot honor the cursor, and the two common implementations diverge in a way that is invisible to the client: - **Implementation A (silent reset):** server accepts `Last-Event-ID`, finds it older than the retained window, and simply starts streaming from the oldest retained event. The client sees a valid stream, no error, and silently skips the gap. - **Implementation B (silent restart):** server ignores the stale cursor and restarts the per-session event sequence numbering at 0 or 1. The client's `Last-Event-ID` bookkeeping is now numerically ahead of the server, and every subsequent event appears "already seen" or out of order. Both produce a live stream and both lose state. Neither produces an error the model or the orchestrator can observe. ## What Was Observed A long-running agent session (a code-review agent driving a multi-file edit workflow) held an MCP session against a filesystem/tool server. The server maintained a per-session ring buffer of the last 1,000 events. During a 40-minute tool-heavy phase, the agent issued bursts of `tools/call` requests and consumed `notifications/progress` events. The connection dropped mid-burst (idle proxy timeout on the client's egress path, unrelated to the server). The client reconnected with `Last-Event-ID: 84213`. The server's retained window at that moment began at `85200`. The server was Implementation A. It returned `200 OK`, `Content-Type: text/event-stream`, and began emitting from event `85200`. The client accepted the stream. The gap `84214..85199` contained: three `notifications/progress` for an in-flight `tools/call` (a long `apply_patch` operation), and the final JSON-RPC response for that call — the response that carried the tool's success/failure result and the new file hashes. The agent's pending-request table still had that request ID marked in-flight. Because the response was in the gap, the request never resolved on the client side. The agent's execution loop waited on a future that would never complete. After the client's own per-request timeout (90s) fired, the agent treated the tool call as failed and *retried it* — re-applying a patch that had already succeeded. The retry produced a conflict, the agent's error-recovery logic attempted a rollback using a file hash it had never received, and the session entered a retry/rollback loop that consumed the remaining token budget without converging. The observable signal that something was wrong was absent at every layer: HTTP was 200, SSE frames were well-formed, JSON-RPC envelopes were valid. The failure was entirely in the *seam* between transport resumption and logical resumption. ## Condition of Validity The invariant that must hold for `Last-Event-ID` resumption to be safe is: > A server MUST NOT accept a resumption cursor it cannot fully honor. If the requested `Last-Event-ID` is older than the oldest retained event, the server MUST reject the resumption with an explicit, machine-readable signal (e.g., `409 Conflict` with a body distinguishing "cursor too old" from other conflicts, or an SSE `event: resumption-failed` frame carrying the oldest available ID and a gap marker), rather than silently resuming from a later point. This is a *server-side* obligation, but the failure is *client-side observable only if the client checks*. The client-side obligation is equally sharp: > A client MUST treat a resumption response as logically complete only if either (a) the server echoes the requested cursor as honored, or (b) the client can reconcile the gap against its own pending-request table and confirm no in-flight request's terminal event falls in the gap. Condition (b) is almost never satisfiable in practice, because the client does not know which events fall in the gap — that is the whole problem. So the only safe client behavior is to treat any resumption that does not explicitly confirm cursor continuity as a **session-invalidating event**: drop the session, tear down all pending requests, and re-establish a fresh MCP session with a full re-initialization handshake. The cost is re-listing tools and re-establishing any server-side session state; the alternative is silent divergence. The boundary is sharp because the two behaviors are indistinguishable at the transport layer. A server that honors the cursor and a server that silently skips the gap both return `200` with `text/event-stream`. There is no header, no status code, and no frame shape that distinguishes them unless the server is built to emit one. ## Decision Boundary The decision the client must make on every reconnect: ``` on_reconnect(requested_id): response = POST /mcp with Last-Event-ID: requested_id if response.status == 200 and stream_is_sse: first_event = peek_first_event(response) if first_event.id == requested_id + 1 (or server-declared successor): resume_normally() else: # cursor was not honored; gap is unknown invalidate_session_and_reinitialize() elif response.status == 409 (cursor too old): invalidate_session_and_reinitialize() else: handle_transport_error() ``` The subtlety is that "server-declared successor" is not part of the MCP spec as of this writing. Servers do not reliably emit a "here is where I actually resumed from" frame. So in practice the client is reduced to comparing the first received event ID against its last-seen ID and assuming monotonic contiguity — which is exactly the assumption Implementation A violates. The correct architectural fix is on the server: emit an explicit `event: resume` frame as the first frame of any resumed stream, carrying `{requested_id, actual_start_id, gap: bool}`. A client that does not receive this frame within a bounded window (say, the first 2 seconds or first 10 events) must treat the stream as unverified and invalidate. This converts an invisible failure into a visible, recoverable one. ## Operational Effect The practical consequence for agent orchestration is that **reconnection is not a transparent transport concern for MCP sessions carrying in-flight tool calls.** It is a state-continuity event that must be routed through the agent's own pending-request bookkeeping. Three concrete operational rules follow: 1. **Never retry a tool call whose terminal response may have been in a resumption gap.** If a reconnect occurred while a request was in-flight and the resumption was not cursor-confirmed, the request is in an *unknown* state — not failed. Retrying risks double-application of non-idempotent effects (file writes, external API calls, database mutations). The correct action is to query the tool's idempotency key or effect state directly, or to abort the task and surface the ambiguity to the orchestrator. 2. **Bound the server's event log to the client's maximum in-flight window, not to a byte budget.** A ring buffer sized by memory (e.g., "keep 1,000 events") will truncate under bursty tool use precisely when in-flight requests are most likely. Size it by the maximum number of events that can be emitted between a request's dispatch and its terminal response, plus a margin. If the server cannot guarantee this, it must implement the explicit `resume` frame. 3. **Treat `Last-Event-ID` as a session-identity assertion, not a hint.** A client that reconnects with a cursor the server cannot honor is, from the server's perspective, a different logical client than the one that disconnected. The server should not pretend otherwise. The failure mode is insidious because it is *silent, intermittent, and correlated with load* — it appears exactly when the agent is doing the most work, and it manifests as a downstream retry storm rather than as a transport error. Agents that log only transport-level success will never see it. ```python import json from dataclasses import dataclass, field from typing import Optional class ResumptionGapError(RuntimeError): """Raised when an MCP SSE resumption cannot be proven cursor-contiguous.""" @dataclass class PendingRequest: request_id: str tool_name: str idempotent: bool = False @dataclass class McpSession: last_event_id: int = 0 pending: dict[str, PendingRequest] = field(default_factory=dict) resume_frame_seen: bool = False def handle_resume( session: McpSession, requested_id: int, first_event_id: int, resume_frame: Optional[dict] = None, ) -> None: """ Validate an SSE resumption. The server MUST either echo a resume frame declaring the honored cursor, or the client MUST be able to prove the first event is the immediate successor of requested_id. """ if resume_frame is not None: honored = resume_frame.get("requested_id") gap = resume_frame.get("gap", False) if honored != requested_id: raise ResumptionGapError( f"server honored cursor {honored} but client requested " f"{requested_id}; session state diverged" ) if gap: # Server admitted it skipped events. Any in-flight request whose # terminal response fell in the gap is in an unknown state. _invalidate_unknown_pending(session) raise ResumptionGapError( f"server declared gap from {requested_id} to " f"{resume_frame.get('actual_start_id')}" ) session.resume_frame_seen = True return # No resume frame: fall back to contiguity check. if first_event_id != requested_id + 1: # Cannot prove continuity. If any non-idempotent request was in flight, # retrying is unsafe; the only correct action is to abort the task. unsafe = [p for p in session.pending.values() if not p.idempotent] if unsafe: raise ResumptionGapError( f"unverified resumption: first event {first_event_id} does not " f"follow {requested_id}; {len(unsafe)} non-idempotent requests " f"in unknown state: {[p.request_id for p in unsafe]}" ) raise ResumptionGapError( f"unverified resumption from {requested_id}, first event " f"{first_event_id}; session must be reinitialized" ) session.resume_frame_seen = True def _invalidate_unknown_pending(session: McpSession) -> None: # Mark all pending requests as unknown-state; do NOT auto-retry. for req in session.pending.values(): req.tool_name = f"{req.tool_name} (state=unknown)" session.pending.clear() ```