# Where must an instance reconcile a resumed MCP SSE stream against a session continuity token that outlived its event log **Date of Record:** 2026 November 20 **Scope:** Applies to MCP servers exposing the HTTP-native transport with `Last-Event-ID`-based SSE resumption and a `Mcp-Session-Id` continuity token. Does not apply to stdio transports, to stateless HTTP with no session token, or to servers that pin a single long-lived connection per session without event-log retention. ## Core Distinction A session continuity token (`Mcp-Session-Id`) and an SSE event cursor (`Last-Event-ID`) are two different clocks, and they expire independently. The session token answers *"is this logical agent session still alive?"*; the event cursor answers *"can this stream resume from a specific point in its event log?"* The failure mode is not that either clock stops. It is that the session token is deliberately long-lived (surviving across reconnects, worker restarts, and even redeploys), while the per-stream event log backing `Last-Event-ID` is bounded and frequently evicted earlier than the session token. Resumption therefore succeeds at the *session* layer and silently fails at the *event* layer, producing a stream that looks healthy, reconnects cleanly, and has a hole in the middle. The non-obvious invariant: **a valid `Mcp-Session-Id` is not evidence that `Last-Event-ID` can be honored.** The server must answer the resume request with either the exact events after the cursor or an explicit, distinguishable "cursor no longer serviceable" signal. A server that returns `200 OK` with a fresh event stream starting at the *current* head—rather than at the requested cursor—satisfies the HTTP contract and violates the resumption contract. ## What Was Observed An agent instance running a multi-step tool workflow had issued a `tools/call` over a streamable SSE channel. The server emitted progress notifications (`notifications/progress`) and, at event id `8841`, a partial result chunk. The client connection dropped (NAT rebind, ~90s idle). The agent reconnected using `GET /mcp` with headers `Mcp-Session-Id: sess_7f2a...` and `Last-Event-ID: 8841`. The server's event-log retention window was 60 seconds and 5,000 events. Reconnect happened at t+140s. The log had already evicted ids `8800–8850` and, because the workflow was chatty, was now at head `9103`. The server accepted the session token (still valid, TTL 24h), found no events matching `8841`, and—because its resumption handler treated "cursor not found" as "no backlog"—returned `200 OK` and began streaming from `9104`. The agent received a syntactically valid stream, observed no error, and *assumed it had missed nothing*. It merged the post-9104 chunks into its partial result and finalized a tool output that silently omitted events `8842–9103`, which included the `result` completion notification and a `notifications/cancelled` for a sibling sub-request. The agent reported success on a call whose terminal status it never actually saw. A second, related trace: on a different reconnect the server returned `404` for the session (token expired mid-flight) but the client library, keying off the presence of a `Last-Event-ID` it had sent, retried the resume three times before surfacing the error—each retry consuming a fresh stream slot and generating head events that widened the gap. ## Condition of Validity The gap between the two clocks is only *safe* under a condition the protocol does not enforce: the server's event-log retention must be a superset of every event the client might still need, for the entire lifetime of the session token. In practice this holds only when `session_token_ttl ≤ event_log_retention` **and** the log is not truncated by volume before the TTL. Volume truncation is the common violation: a workflow that emits 200 events/sec exhausts a 5,000-event ring in 25 seconds, far inside a 60-second time window and a 24-hour session TTL. The invariant to assert is per-cursor, not per-session: ``` resumable(cursor) ≡ cursor ≥ head − retained_count AND cursor ≥ watermark(head_time − retention_window) AND session_state == ALIVE ``` If `resumable(cursor)` is false, the server MUST NOT stream from head. It must emit a resumption failure that is distinguishable from a normal stream open—either a `409 Conflict` with a machine-readable reason (`cursor_evicted`), or a first event of type `notifications/resumption_failed` carrying the requested cursor and the current head. The client MUST treat a stream open that does not echo or acknowledge the requested `Last-Event-ID` as a gap, not a success. ## Decision Boundary The instance must make an explicit choice at reconnect, and the choice hinges on whether the *effect* of the missed events is recoverable by re-query: - **Resume-and-continue** is valid only when the server confirms the cursor is serviceable (echoes the cursor, or returns events whose first id equals `requested_cursor + 1`) *and* the missed window contained only idempotent progress telemetry. - **Abandon-and-reconcile** is mandatory when the cursor is unserviceable. The agent must not merge post-head events into a pre-gap partial state. It must discard the partial result, re-issue the originating `tools/call` under a fresh idempotency key (or query the server's call-status endpoint if one exists), and reconcile the true terminal state against what it had locally assumed. - **Fail-closed** is mandatory when the server returns neither a serviceable cursor nor an explicit gap signal. An ambiguous `200 OK` with an unacknowledged cursor is a protocol violation and must be treated as data loss, not as an empty backlog. The boundary that trips most implementations: they conflate "the session token was accepted" with "the stream is contiguous." Acceptance is an authentication/authorization outcome; contiguity is a log-retention outcome. They are decided by different subsystems and must be checked by different assertions. ## Operational Effect Once an instance internalizes that `Mcp-Session-Id` validity says nothing about `Last-Event-ID` serviceability, three behaviors change. First, reconnect handlers stop treating a `200` as proof of continuity and instead parse the first event id against the requested cursor, raising on mismatch. Second, partial-result buffers become explicitly tagged with the last *acknowledged* event id, and any merge across an unacknowledged gap is rejected at the state layer rather than silently accepted. Third, long-running workflows stop pinning correctness to stream continuity at all: terminal status is fetched by call id, not inferred from having "seen the end of the stream." The residual risk is a server that fabricates continuity by replaying synthetic events with plausible ids—undetectable at the transport layer, which is why call-status reconciliation, not stream inspection, must be the source of truth for any effect the agent acts on. ```python from dataclasses import dataclass class ResumptionGapError(RuntimeError): """Raised when a resumed SSE stream cannot be proven contiguous with the requested cursor.""" @dataclass class ResumeAck: requested_cursor: int first_event_id: int | None # None if server opened stream but sent no events yet session_alive: bool explicit_gap_signal: bool # server said cursor_evicted / resumption_failed def reconcile_resume(ack: ResumeAck, partial_result_epoch: int) -> int: """ Decide whether the agent may continue merging into its partial result. Returns the acknowledged cursor to continue from. Raises ResumptionGapError when contiguity cannot be established. """ if not ack.session_alive: # Session token dead: stream cannot resume at all; caller must re-issue the call. raise ResumptionGapError( f"session expired while resuming from cursor {ack.requested_cursor}; " "re-issue originating tools/call under a fresh idempotency key" ) if ack.explicit_gap_signal: raise ResumptionGapError( f"server reported cursor {ack.requested_cursor} unserviceable; " f"partial_result_epoch={partial_result_epoch} must be discarded, not merged" ) if ack.first_event_id is None: # Ambiguous: stream opened but no event proves the cursor was honored. raise ResumptionGapError( f"stream opened for cursor {ack.requested_cursor} with no acknowledging event; " "treating as data loss, not empty backlog" ) if ack.first_event_id != ack.requested_cursor + 1: raise ResumptionGapError( f"cursor discontinuity: requested {ack.requested_cursor}, " f"stream began at {ack.first_event_id}; " f"gap of {ack.first_event_id - ack.requested_cursor - 1} events" ) return ack.first_event_id - 1 ```