# What structural signals indicate a resumed MCP streamable-session is replaying a server-push notification the agent already consumed, and how to bound it **Date of Record:** 2026 December 3 **Scope:** Applies to MCP servers exposing the streamable HTTP transport with `Last-Event-ID`-based session resumption and at least one server-initiated push channel (progress notifications, `notifications/message`, resource-change events) delivered on the same SSE stream as the response to a client request. Does not apply to stateless per-request transports or to stdio sessions where no resumption cursor exists. ## Core Distinction The failure is not "the stream disconnected." It is that on reconnection the server is entitled to re-emit events at or after the client's `Last-Event-ID`, and the client is not entitled to assume those events are new. The streamable HTTP transport makes resumption *at-least-once* by construction: the event ID is a cursor, not an acknowledgement. A resumed session therefore has two structurally indistinguishable states from the client's vantage—**the server replaying unacknowledged events**, and **the server replaying already-consumed events because the client's cursor was advanced past a gap the server never durably committed**. The agent cannot tell which by looking at the payload; it must look at structural signals: event-ID monotonicity gaps, the presence of a server-side replay floor, and whether push notifications carry a causal link to a request the agent still has open. ## What Was Observed A coding agent held a streamable session against an MCP server that pushed `notifications/progress` for a long-running `tools/call` (a repository-wide lint) and `notifications/resources/updated` for a watched config file. The SSE stream dropped mid-lint (idle proxy timeout, 60s). The agent reconnected with `Last-Event-ID: 4471`. The server, whose event log retained the last 512 events but whose *durable* commit lagged the in-memory log by up to a few hundred milliseconds, honoured the cursor against the in-memory ring buffer. It replayed events 4472–4503. Three of those replayed events were `notifications/progress` for the *same* `progressToken` the agent had already rendered at 88%, 91%, 94%. Two were `notifications/resources/updated` for the config file the agent had already re-read and reconciled. The agent's event handler was not idempotent: it appended progress to a running log (duplicating entries), and on the resource-update it re-read the file, found a *newer* mtime than the replayed event's payload described, and re-triggered a downstream `tools/call` that re-ran part of the lint. The lint job, which was server-side and keyed on a job handle, was now being polled by two logical loops; the second loop's cancellation raced the first's completion and the agent recorded a `cancelled` terminal state for a job that had actually succeeded. The structural tell was visible before the damage: the replayed progress notifications carried `progressToken` values whose *rendered* progress (94%) was lower than the agent's own last-observed progress (94% → then a fresh 88%). Monotonicity of the progress token's payload regressed across the resume boundary. That regression is the signal. A correct client treats a decrease in a `progressToken`'s reported progress, or a re-arrival of a resource-update whose payload version is not strictly greater than the last applied version, as evidence of replay, not as new work. ## Condition of Validity The invariant that makes resumption safe is: **for every event ID the client advances past, the client has durably applied the event's effect, and the server will not re-emit an event ID at or below the client's last-acknowledged cursor unless that event's effect is idempotent under re-application.** This holds only when all three of the following are true: 1. The client persists its `Last-Event-ID` *after* applying the effect, not on receipt. Advancing the cursor on receipt converts at-least-once into at-most-once-with-loss on the next crash. 2. The server's replay window is bounded by a durable, monotonic event log, not an in-memory ring buffer whose floor silently advances. If the server's log floor is above the client's cursor, the server MUST signal a gap (a `notifications/…` gap event or an HTTP 409 with a `Last-Event-ID` reset directive) rather than replaying from the floor as if contiguous. 3. Every server-push notification carries a causal key that is stable across replay—`progressToken` for progress, `(uri, version)` for resource updates—and the client's application of that notification is idempotent under a repeated key with a non-increasing version. When any of these is violated, the resume is a replay hazard and the client must not treat replayed events as new. ## Decision Boundary The boundary is between **resume-as-continuation** and **resume-as-replay-uncertain**. The client crosses into replay-uncertain when it observes any of: - An event ID at or below its persisted cursor arriving after a successful `Last-Event-ID` resume (server ignored the cursor, or reset its log). - A `progressToken` whose progress value is ≤ the last applied value for that token. - A resource-update whose `(uri, version)` is ≤ the last applied version for that URI. - A gap in event-ID monotonicity (e.g., 4471 → 4480) without an explicit gap notification—this means events 4472–4479 were dropped, not delivered, and the client's cursor is now ahead of what it applied. On crossing, the correct action is not to process the event but to **quarantine the session**: stop applying pushes, re-fetch authoritative state via a fresh request (not via the resumed stream), and only then advance the cursor. Processing a replay-uncertain push is the failure; quarantining is the guardrail. ## Operational Effect Without the guardrail, replay produces three concrete damages: duplicated side effects from re-triggered tool calls (the double-poll above), terminal-state corruption when a replayed cancellation races a real completion, and cursor poisoning—because the client, on applying a replayed event, advances its persisted cursor *past* the gap the server never delivered, permanently losing the events between the true last-applied and the replayed one. That last effect is the non-obvious one: replay does not just duplicate, it *consumes the cursor budget* that should have covered the gap, so the next resume skips real events. The guardrail is cheap: persist cursor after effect, key every push by a stable causal token, reject non-increasing versions, and treat any event-ID gap without an explicit gap signal as a hard session fault requiring re-fetch rather than resume. ```python class ReplayUncertainSessionError(RuntimeError): """Raised when a resumed MCP streamable session shows structural replay signals.""" pass class ResumablePushSession: def __init__(self): self.cursor = 0 # last event id whose effect is durably applied self.progress = {} # progressToken -> last applied progress value self.resource_version = {} # uri -> last applied version def on_resume(self, last_event_id: int, first_event_id: int): # Server must not re-emit at or below the cursor we sent. if first_event_id <= last_event_id: raise ReplayUncertainSessionError( f"resume ignored cursor: got {first_event_id} <= {last_event_id}" ) # A jump with no explicit gap signal means events were dropped, not delivered. if first_event_id != last_event_id + 1: raise ReplayUncertainSessionError( f"event-id gap {last_event_id}->{first_event_id} without gap notification" ) def apply_progress(self, event_id: int, token: str, value: float): last = self.progress.get(token) if last is not None and value <= last: # Replayed or regressed progress: do not re-apply, do not advance cursor past it. raise ReplayUncertainSessionError( f"progress regression for {token}: {value} <= {last}; treat as replay" ) self.progress[token] = value self.cursor = event_id # advance only after effect applied def apply_resource_update(self, event_id: int, uri: str, version: int): last = self.resource_version.get(uri) if last is not None and version <= last: raise ReplayUncertainSessionError( f"stale resource update for {uri}: v{version} <= v{last}; replay hazard" ) self.resource_version[uri] = version self.cursor = event_id def resume_and_drain(session: ResumablePushSession, last_event_id: int, events): if not events: return session.on_resume(last_event_id, events[0]["id"]) for ev in events: kind = ev["type"] if kind == "progress": session.apply_progress(ev["id"], ev["token"], ev["value"]) elif kind == "resource_updated": session.apply_resource_update(ev["id"], ev["uri"], ev["version"]) else: raise ReplayUncertainSessionError(f"unhandled push type {kind}; quarantine session") ```