# Under what conditions must an instance treat an MCP Streamable-HTTP `Last-Event-ID` resume as a *fork* rather than a *continuation*, and how does silent event-ID reuse corrupt agent state? **Date of Record:** 2026 November 21 **Scope:** Applies to MCP servers/clients using the HTTP-native Streamable HTTP transport with server-initiated SSE streams and `Last-Event-ID`-based resumability, where a session survives a dropped connection. Does not apply to stdio transport, to stateless request/response MCP servers, or to sessions that are torn down and re-initialized on reconnect. ## Core Distinction The Streamable HTTP transport lets a client reattach to a session by sending `Last-Event-ID` on a resumed `GET` (SSE) request. The spec's mental model is *continuation*: the server replays events strictly after the supplied ID, and the client's view of the session is a single monotonic log. The boundary condition is that this model is only valid when the event-ID space is **globally monotonic and never reissued within a session**. MCP does not mandate that property. Event IDs are opaque strings chosen by the server. A server that generates IDs per-stream (e.g., a per-connection counter, a per-tool-call sequence, or a UUID that resets when a sub-stream is recreated) will, after a reconnect, hand the client an ID that *collides* with an ID the client already consumed from a different logical stream. The client then resumes at the wrong offset in the wrong log and treats a fork as a continuation. The distinction that matters operationally: *resume is only a continuation if the ID namespace is session-scoped and monotonic; otherwise resume is a fork and must be reconciled, not trusted.* ## What Was Observed Trace of a concrete failure. An agent client holds an open session `S`. The server multiplexes two logical event sources onto the SSE stream: `notifications/tools/list_changed`-style control events and `sampling`/progress notifications tied to a long-running tool call. The server assigns event IDs from a **per-source** counter: control events get `c1, c2, c3…`; the tool-call progress stream gets `p1, p2, p3…`. The client has consumed up to `p7` and `c2` when the TCP connection drops mid-tool-call. On reconnect the client sends `Last-Event-ID: p7` (the last ID it saw). The server's resume handler looks up `p7` in *its* index. But the tool call was re-dispatched on a fresh worker after the drop, and that worker's progress counter restarted at `p1`. The server has no `p7`; depending on implementation it either (a) replays from the beginning of the *control* stream because it falls back to "unknown ID → replay from start," or (b) silently treats `p7` as "already delivered" and resumes the new `p1…` sequence, so the client receives `p1, p2, p3` again — IDs it already consumed. In case (b) the client's dedup layer, keyed on event ID, drops the *new* progress events as duplicates. The tool call completes server-side; the client never sees the completion event, keeps its `pending` state, and after its own timeout re-invokes the tool. The tool is not idempotent. Side effect applied twice. The invariant violated: **the client's dedup and resume logic assumes event IDs are unique across the whole session lifetime.** The server only guaranteed uniqueness within a sub-stream that was destroyed and recreated. The reconnect boundary is exactly where the two assumptions diverge, and nothing in the protocol handshake surfaces the mismatch. A second observed variant: the server *does* persist a replay buffer, but keyed by stream, and on resume replays every buffered event whose ID is not in the client's `Last-Event-ID` — comparing string IDs across streams. `c3` and `p3` are distinct strings, fine; but a server using bare integers per stream (`3` for both `c3` and `p3`) replays `p3` to a client that asked to resume after `c3`, injecting a stale progress event into a fresh turn. The agent's reasoning loop now sees progress for a tool call it already abandoned, and its planner concludes the call is still running. ## Condition of Validity `Last-Event-ID` resume is a valid continuation **iff all three hold**: 1. **Session-scoped monotonic ID space.** Every event emitted into the session draws from one strictly increasing sequence (or a server-guaranteed total order), regardless of which logical sub-stream produced it. Per-source counters and per-connection counters violate this. 2. **Replay completeness across the gap.** The server retains every event after the client's `Last-Event-ID` up to the current head, including events produced *during* the disconnection window. A server that only replays from an in-memory ring buffer sized to the live connection will silently truncate the gap. 3. **ID non-reuse after stream recreation.** If a sub-stream (tool-call worker, sampling session) is torn down and recreated, the new instance must not restart its ID sequence at a value already issued in the session. If any one fails, the resume is a **fork**: the client's post-resume view and the server's authoritative log are different histories that happen to share an ID string. The client must detect this (see below) and reconcile — typically by re-issuing a state query (`resources/read`, or a tool-status call) rather than trusting the replayed event stream. The condition is *not* satisfied by "the connection came back and I got a 200." A successful HTTP resume says nothing about ID-space integrity. The client cannot verify conditions 1–3 from the transport layer alone; it must either (a) be configured with knowledge of the server's ID scheme, or (b) treat every resume as suspect and reconcile. ## Decision Boundary The operational decision is: **on reconnect, do I trust the replayed stream, or do I reconcile state out-of-band before resuming reasoning?** Trust the stream (fast path) only when the client can assert all of: - It has observed no ID reuse within the session so far (maintain a seen-ID set; if a replayed ID is already in the set, the trust assumption is already broken). - The server's resume response begins at an ID it has *not* seen and the gap contains no missing sequence positions (if IDs are ordered, check monotonicity; if opaque, you cannot check — fall to slow path). - The elapsed disconnection is within the server's declared replay-retention window (if the server advertises one; if not, assume the gap may be truncated). Otherwise take the slow path: **suppress replay-driven state transitions, issue an explicit state reconciliation call, and only then resume the reasoning loop.** Concretely, on a suspect resume the agent must not let a replayed `progress`/`completion` notification mutate its `pending` tool-call registry until it has confirmed current tool status via a fresh request. The decision boundary is per-event: replayed *control* events (list-changed, capability updates) are safe to apply because they are idempotent and describe current state; replayed *effect-bearing* or *progress* events are not, because they describe a past that may have been superseded by a fork. The asymmetry that makes this non-obvious: idempotent control events make resume *look* safe in casual testing, because the common case (no fork) works and the control events reconcile themselves. The failure only manifests on non-idempotent tool calls crossing a reconnect, which is exactly the case agents care about. ## Operational Effect When the boundary is crossed and the client trusts a forked resume: - **Duplicate side effects.** Dedup-by-ID drops the post-fork events, the client times out, and re-invokes a non-idempotent tool. Observed as doubled writes, doubled messages, doubled payments. - **Phantom in-flight state.** A stale replayed progress event re-marks a completed/abandoned call as running; the planner blocks waiting on a call that will never emit again, and the turn deadlocks until the agent-level timeout fires. - **Silent history divergence.** The client's episodic record of the turn now differs from the server's; any later audit or replay of the session (see verification-replay concerns) produces a mismatch that cannot be attributed to model nondeterminism versus transport fork. - **Context-window amplification.** Replayed events from the start of a long stream (fallback "unknown ID → replay from start") can re-inject thousands of tokens of already-processed events into a near-saturated context, evicting the actual task state. The guardrail that bounds this: **treat the session event log as authoritative only within a verified-monotonic ID space; on any resume, gate effect-bearing events behind an out-of-band state reconciliation, and never re-invoke a tool whose completion status is unconfirmed after a fork.** The cost is one extra round-trip per suspect reconnect; the alternative is unbounded duplicate effects that the agent cannot detect from inside its own reasoning loop. ```python from __future__ import annotations from dataclasses import dataclass, field class ResumeForkError(RuntimeError): """Raised when an SSE resume cannot be proven to be a continuation. The replayed stream diverges from the client's authoritative history: an event ID was reused, a gap position is missing, or the disconnection exceeded the server's replay-retention window. Treating such a resume as a continuation risks duplicate side effects and phantom in-flight state. """ @dataclass class SessionLog: """Client-side authoritative view of one MCP session's event stream.""" seen_ids: set[str] = field(default_factory=set) last_id: str | None = None replay_retention_s: float | None = None # None => unknown, assume unsafe def note(self, event_id: str) -> None: if event_id in self.seen_ids: raise ResumeForkError( f"event id {event_id!r} reissued within session: " "ID space is not session-monotonic; resume is a fork" ) self.seen_ids.add(event_id) self.last_id = event_id def reconcile_resume( log: SessionLog, replayed_ids: list[str], disconnected_for_s: float, effect_bearing: set[str], ) -> list[str]: """Decide which replayed events may be applied, or raise on a fork. Returns the subset of replayed IDs safe to apply immediately. Effect-bearing events on a suspect resume are withheld pending out-of-band reconciliation. """ if log.replay_retention_s is None: raise ResumeForkError( "server advertises no replay-retention window; " "cannot prove the gap was not truncated" ) if disconnected_for_s > log.replay_retention_s: raise ResumeForkError( f"disconnected {disconnected_for_s}s exceeds retention " f"{log.replay_retention_s}s; replayed events may be incomplete" ) safe: list[str] = [] for eid in replayed_ids: if eid in log.seen_ids: # Reuse across the reconnect boundary: the client already consumed # this ID from a different logical stream. Fork, not continuation. raise ResumeForkError( f"resume reissued previously-seen id {eid!r}; " "server likely reset a per-stream counter" ) if eid in effect_bearing: # Withhold: must confirm current tool status out-of-band first. continue safe.append(eid) log.note(eid) return safe ```