What structural signals indicate that an MCP SSE stream's `Last-Event-ID` resumption has silently forked the session rather than resumed it

**Date of Record:** 2026 December 1 **Scope:** Applies to MCP servers exposing HTTP-native streaming (Streamable HTTP transport with SSE event IDs and `Last-Event-ID` resumption) to agents that reconnect mid-tool-call. Does not apply to stdio transports, nor to stateless request/response MCP servers that never emit event IDs.

Core Distinction

The distinction that matters is between *resumption* and *replay-with-fork*. When an MCP client reconnects to an SSE stream and presents `Last-Event-ID: N`, the server has two legitimate-looking implementations:

  1. **Replay-from-buffer**: the server holds a bounded ring buffer of emitted events keyed by ID and re-emits everything after `N` to the same logical session. The client's view is continuous.
  2. **Resume-by-reissue**: the server, unable to find `N` (evicted, or the session was migrated to another process/pod), starts a *new* event sequence for the *same* session ID and begins emitting from the current head, not from `N`. The client receives a stream that looks alive but whose event IDs are not contiguous with what it previously held.

The failure is that both look identical on the wire to a naive client: HTTP 200, `Content-Type: text/event-stream`, a stream of well-formed events. The fork is only detectable through *structural signals* — ID monotonicity, session-epoch metadata, and the presence or absence of the events the client expected between `N` and the first new event. An agent that treats "stream is flowing" as "resumption succeeded" will splice a post-fork event sequence onto a pre-fork reasoning state and proceed with a corrupted causal history.

What Was Observed

A tool-calling agent issued `tools/call` for a long-running operation (a repository-wide static analysis, ~90s). The server streamed progress events with IDs `1001…1047`, then the client's TCP connection dropped (NAT rebind). The client reconnected with `Last-Event-ID: 1047`.

The server had, in the interim, been rescheduled (rolling deploy). The new process had no ring buffer for that session. Its handler logic was:

if last_event_id in buffer: replay_suffix(last_event_id)
else: open_new_stream(session_id)   # emits from current head

The new process emitted events starting at ID `2001`, `2002`, … — a fresh monotonically-increasing sequence scoped to the *same* `Mcp-Session-Id`. The client, whose resumption logic only checked `response.ok` and `content-type`, accepted the stream. It then received a `notifications/progress` at `2003` reporting `progress: 0.05` — because the new process had *restarted the tool from scratch* under a new internal job ID, having lost the original job's handle along with the buffer.

The agent's transcript now contained: progress 0.98 (pre-drop, ID 1047), then progress 0.05 (post-reconnect, ID 2003), then completion at 2009. The agent's summarizer read the final completion as authoritative and discarded the pre-drop partial results — which had actually been *further along* and contained the only copy of a partial index the tool never persisted. Silent data loss, no error code, no `4xx`, no `reset` event.

A second variant was observed where the server *did* find the session but the buffer had evicted `1047` (ring buffer capacity 256, high event rate). The server resumed at the oldest available ID (`1050`), skipping `1048` and `1049`. IDs were contiguous-looking from the client's perspective if it only checked "next ID > last seen," because `1050 > 1047`. Two events — including a `notifications/message` carrying a schema-amendment that changed the meaning of a subsequent field — were never delivered. The agent parsed the post-amendment payload under the pre-amendment schema and mis-typed a batch of results.

Condition of Validity

The replay-from-buffer invariant holds **only if all three** of the following are true, and the client must verify each independently:

  1. **ID continuity**: the first event on the resumed stream has ID exactly `last_seen_id + 1` (for dense integer sequences) *or* the server advertises a resumption contract that guarantees a gap-free suffix. "Greater than" is not sufficient; it admits eviction skips.
  2. **Session epoch stability**: the `Mcp-Session-Id` is unchanged *and* any server-emitted epoch/generation token (e.g., a `Mcp-Session-Epoch` header or a field in the `initialize` result) is unchanged. A session ID that survives a process migration but not the epoch is a fork.
  3. **No state reset signal**: the resumed stream does not re-emit initialization, capability negotiation, or progress values that move *backwards* relative to pre-drop state. Backwards progress is the canonical tell of a restarted job.

If any of the three fails, the connection is a **fork**, not a resume, and the client must treat all pre-drop in-flight state as *unverified* rather than *continued*.

Decision Boundary

The boundary the agent must encode:

The trap is that a fork is *cheaper to accept than to detect*. The stream is healthy; the events parse; the only cost of acceptance is a corrupted causal history that manifests far downstream as a wrong answer with no proximate cause. Agents under token pressure will accept the fork because rejecting it means re-running an expensive tool. The boundary must therefore be enforced structurally — by a validator that raises on invariant violation — rather than left to the model's judgment, because the model has a systematic bias toward continuing.

A secondary boundary: when the server *cannot* distinguish eviction from migration (both yield "ID not found"), it must emit an explicit `stream-reset` event with the new base ID and a `reason` field, rather than silently opening a new stream. Absent that, the client cannot tell variant 1 (restart) from variant 2 (skip), and must conservatively treat both as forks.

Operational Effect

Enforcing the three-invariant check converts a silent-corruption class into a loud, recoverable failure. In the observed case, the corrected client:

Net effect: one extra tool round-trip in the happy path (a status query on every resume), traded against elimination of silent partial-result loss and schema-mismatch parsing. The invariant is cheap to check and expensive to omit; it belongs in the transport adapter, not in the agent's prompt.

from dataclasses import dataclass

class StreamForkDetected(RuntimeError): """Raised when an SSE resumption is structurally a fork, not a resume."""

@dataclass class ResumeState: last_event_id: int session_id: str session_epoch: str last_progress: float

def validate_resumption( prior: ResumeState, first_event_id: int, session_id: str, session_epoch: str, first_progress: float | None, ) -> None: if session_id != prior.session_id: raise StreamForkDetected( f"session id changed on resume: {prior.session_id!r} -> {session_id!r}" ) if session_epoch != prior.session_epoch: raise StreamForkDetected( f"session epoch advanced {prior.session_epoch!r} -> {session_epoch!r}; " "process migration, buffer lost" ) if first_event_id != prior.last_event_id + 1: # covers both restart (id jumped far forward) and eviction (id skipped) raise StreamForkDetected( f"event id gap: expected {prior.last_event_id + 1}, got {first_event_id}; " "replay suffix not contiguous" ) if first_progress is not None and first_progress < prior.last_progress: raise StreamForkDetected( f"progress regressed {prior.last_progress} -> {first_progress}; " "job restarted under same session" )