Where must an instance reconcile the SSE event-ID watermark against the MCP session ID before honoring a resumption request
**Date of Record:** 2026 December 1 **Scope:** Applies to MCP servers exposing the HTTP-native transport (streamable HTTP with Server-Sent Events) where a client may reconnect and request session resumption via `Last-Event-ID`. Does not apply to stdio transport, nor to stateless request/response MCP deployments where no event stream is multiplexed.
Core Distinction
The failure is not "the client reconnected and lost messages." The failure is that the SSE `Last-Event-ID` and the MCP `Mcp-Session-Id` are two *independent* identity axes that the spec treats as orthogonal but that a naive server implementation silently conflates. The event-ID is a monotonic cursor into a per-connection event log; the session ID names a logical agent session that may span multiple physical connections. When a resumption request arrives carrying a `Last-Event-ID` from connection A but an `Mcp-Session-Id` whose event log was forked (because a second connection was opened under the same session, or because the server garbage-collected the event buffer and restarted its counter), the server either replays events the client already consumed (duplicate tool-call results) or skips events the client never saw (lost `notifications/tools/list_changed`, lost partial tool output). The boundary invariant is: *an event-ID is only meaningful relative to the exact event-log lineage named by the session ID it was issued under.* Any resumption must validate that lineage before replay.
What Was Observed
An agent runtime held an MCP session `sess_7f3a` open over streamable HTTP. Mid-task it issued `tools/call` for a long-running filesystem scan. The server streamed three SSE events under that connection: `event: message, id: 41` (ack), `id: 42` (progress), then the connection dropped at the load balancer's 60-second idle timeout before `id: 43` (final result) was delivered.
The client reconnected per spec, sending `Last-Event-ID: 42` and `Mcp-Session-Id: sess_7f3a`. The server had, in the interim, evicted the event buffer for `sess_7f3a` under a memory-pressure GC and — critically — a *second* connection had been opened by the client's health-check probe under the same session ID, which the server treated as a fresh event-log lineage and began numbering at `id: 1`. On resumption the server looked up `Last-Event-ID: 42` in the *new* lineage, found no event with that ID, and — per a permissive-but-wrong "resume from nearest" branch — replayed from the head of the new buffer. The client received `id: 1` through `id: 5`, all belonging to the health-probe connection, none belonging to the scan. The scan's `id: 43` result was never delivered. The agent, seeing no terminal result and a stream of unrelated events, timed out the tool call and retried the entire scan — a duplicate filesystem mutation.
The tell was a divergence between two counters the server logged: the session's `max_event_id_issued` (43) and the buffer's `max_event_id_present` (5). The server had no check that `Last-Event-ID <= max_event_id_issued` *and* `>= min_event_id_present` within the same lineage.
Condition of Validity
The replay guard is only sound when all of the following hold:
- **Lineage is monotonic within a session.** The server must never reset the event-ID counter for an `Mcp-Session-Id` unless it also rotates the session ID. A GC that evicts the buffer must either persist a `min_event_id_present` watermark and refuse resumption below it, or terminate the session and force a fresh `initialize`.
- **Concurrent connections under one session share one event log.** If the transport permits multiple physical connections per session (the spec allows it for server-to-client notifications), the event IDs must be drawn from a single shared counter, not per-connection counters. Per-connection counters make `Last-Event-ID` ambiguous across connections.
- **The client echoes the session ID it actually holds.** A client that reconnects without `Mcp-Session-Id` (or with a stale one) must be treated as a *new* session, not resumed. Resumption requires both headers and their joint validation.
When any of these is violated, `Last-Event-ID` is a dangling pointer and replay is unsound.
Decision Boundary
On receiving a resumption request with `(Mcp-Session-Id = S, Last-Event-ID = L)`:
- If `S` is unknown → reject with `404`, do not replay. The client must re-`initialize`.
- If `S` is known but its event-log lineage was rotated (GC'd or forked) → reject with `409 Conflict` carrying the current `min_event_id_present`; the client must decide to re-`initialize` or accept a gap. **Never** silently replay from the new buffer's head.
- If `L < min_event_id_present(S)` → the cursor has fallen behind the retained window. Reject with `409` and the watermark; do not fabricate continuity.
- If `L > max_event_id_issued(S)` → the client claims to have seen events the server never issued. This is a lineage mismatch (stale session ID against a reused log). Reject with `409`; treat as new session.
- Only when `min_event_id_present(S) <= L <= max_event_id_issued(S)` within a single, unrotated lineage do you replay `L+1 … max_event_id_issued(S)` and resume live multiplexing.
The boundary is exactly the watermark pair `(min_event_id_present, max_event_id_issued)` scoped to one lineage. The invariant: **no event is replayed across a lineage boundary, and no gap is papered over with fabricated continuity.**
Operational Effect
Without the guard, the observed failure mode is *silent tool-result loss with duplicate side effects*: the agent loses the terminal event of a mutating tool call, retries, and the server — which never validated lineage — accepts the retry as a new call, producing a double mutation. The agent's own checkpointing cannot detect this because from its side the first call simply "timed out," which is indistinguishable from a slow call. The guard converts this into a *loud* `409` at resumption time, forcing the agent to reconcile state (re-`initialize` or explicitly accept the gap) before continuing. The cost is a rejected resumption; the benefit is that the agent's retry logic is never silently wrong about whether a mutation landed.
Code
class SSELineageMismatch(RuntimeError):
"""Raised when a resumption request's Last-Event-ID cannot be soundly
reconciled against the event-log lineage named by its Mcp-Session-Id."""
pass
class EventLineage:
def __init__(self, session_id: str):
self.session_id = session_id
self.min_present = 1 # lowest event ID still retained
self.max_issued = 0 # highest event ID ever issued
self.rotated = False # set True if buffer GC'd/forked
def rotate(self, new_min_present: int):
# GC evicted everything below new_min_present
self.min_present = new_min_present
self.rotated = True
def validate_resumption(
lineages: dict[str, EventLineage],
session_id: str,
last_event_id: int,
) -> int:
"""Return the next event ID to replay from, or raise SSELineageMismatch."""
lineage = lineages.get(session_id)
if lineage is None:
# Unknown session: must re-initialize, never replay.
raise SSELineageMismatch(
f"unknown session {session_id!r}; client must re-initialize"
)
if lineage.rotated and last_event_id < lineage.min_present:
raise SSELineageMismatch(
f"cursor {last_event_id} below retained window "
f"[{lineage.min_present}, {lineage.max_issued}] for {session_id!r}"
)
if last_event_id > lineage.max_issued:
# Cursor ahead of issued range: stale ID against a reused log.
raise SSELineageMismatch(
f"cursor {last_event_id} exceeds max_issued "
f"{lineage.max_issued} for {session_id!r}; lineage mismatch"
)
if last_event_id < lineage.min_present - 1:
raise SSELineageMismatch(
f"cursor {last_event_id} predates retained min "
f"{lineage.min_present} for {session_id!r}"
)
# Sound: replay strictly after the cursor, within one lineage.
return last_event_id + 1