# When must an instance abandon MCP SSE stream resumption rather than replay from Last-Event-ID **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients using the HTTP-native transport (Streamable HTTP with Server-Sent Events) that reconnect after a mid-stream disconnect using `Last-Event-ID` resumption against a stateful server. Does not apply to stdio transport, nor to servers that emit only terminal responses without event IDs. ## Core Distinction The distinction that matters is between **transport-level resumption** and **semantic-level continuity**. `Last-Event-ID` is a transport primitive: it tells the server "replay events strictly after ID N." It says nothing about whether the *tool-call state* that produced those events is still live on the server, nor whether the client's local view of in-flight tool results is consistent with the replay. A client that treats SSE resumption as a guarantee of task continuity will silently double-apply side effects or diverge from the server's authoritative state. The invariant is this: **resumption is safe only if the server's event log is the sole source of truth for the session AND the client has not independently committed any state derived from events after the resume point.** When either condition fails, the instance must abandon the stream and re-initialize the session, not replay. ## What Was Observed A client agent issued a `tools/call` for a long-running operation (a multi-step file mutation) over an SSE stream. The server emitted a `progress` event (ID 41), then a `notification` that the tool had begun writing (ID 42), then the connection dropped at a load balancer after ~30s idle timeout. The client reconnected with `Last-Event-ID: 41`. The server, whose event log was keyed per-connection rather than per-session, had already discarded IDs 42+ on the dropped connection and replayed from a fresh sequence starting at ID 1 of a *new* logical stream. The client, holding a stale `Last-Event-ID`, blocked waiting for events after 41 that would never arrive, while the server's tool execution completed and its result (ID 5 of the new stream) was delivered but ignored by the client's resume filter. The client timed out, retried the entire `tools/call`, and the server — which had no idempotency key — executed the mutation a second time. The file was written twice with non-idempotent appends. The deeper failure: the client's resume logic assumed monotonic, session-scoped event IDs. The server provided connection-scoped IDs. The mismatch was invisible until a reconnect occurred, and the retry amplified it into a duplicate side effect. A second observed variant: under backpressure, the server buffered events and dropped the oldest when the client's TCP window closed. The client resumed from `Last-Event-ID: 88`, but events 89–93 had been evicted from the buffer; the server replayed 94 onward. The client never saw the `tool_result` at 91 and proceeded with a null result, treating the tool as having returned empty. ## Condition of Validity SSE resumption via `Last-Event-ID` is valid **only** when all of the following hold simultaneously: 1. Event IDs are **session-scoped and monotonically increasing across reconnects** — the server must persist the event log for the session's lifetime, not the connection's. 2. The server **retains all events after the client's last acknowledged ID** — no eviction under backpressure. If the buffer evicts, the server must signal a gap (e.g., a `stream/reset` control event) rather than silently advancing the sequence. 3. The client has **not committed any state derived from events it may need replayed** — i.e., it treats replay as a re-delivery, not a re-execution, and its local state is a pure function of the event log up to the resume point. 4. Tool invocations carry an **idempotency key** so that a fallback full retry cannot duplicate side effects. If any condition fails, the instance must escalate from resume to **session re-initialization** (new `initialize` handshake, fresh event sequence, explicit reconciliation of any in-flight tool calls against server state). ## Decision Boundary The decision point is: *on reconnect, does the client's `Last-Event-ID` fall within the server's retained window, and is the session's event log authoritative?* - If `last_event_id >= server.retained_floor` **and** `server.session_scoped_ids == true` **and** in-flight tool calls are idempotent → **resume**. - If `last_event_id < server.retained_floor` (gap) → **abandon resume**, request full state snapshot, reconcile. - If `server.session_scoped_ids == false` (connection-scoped IDs detected, e.g., sequence restarts) → **abandon resume**, re-initialize session. - If any in-flight `tools/call` lacks an idempotency key and the resume point precedes its completion → **abandon resume**, re-initialize, and query server for authoritative tool outcome before retrying. The client cannot know condition 2 or 3 without an explicit capability negotiation at `initialize` time. Absent that negotiation, the safe default is to **treat all resumption as unsafe** and re-initialize on any disconnect — accepting the latency cost to avoid the duplicate-side-effect cost. ## Operational Effect Adopting the strict boundary changes behavior in three ways. First, reconnects that previously "succeeded" (delivered some events) but silently lost others now surface as explicit reconciliation events, converting silent divergence into a recoverable, observable state. Second, non-idempotent tool calls become gated: the client refuses to resume past a `tools/call` boundary without an idempotency key, forcing the tool layer to declare idempotency or accept re-initialization. Third, backpressure-induced eviction is detected via the retained-floor check rather than manifesting as a phantom empty `tool_result`. The cost is more re-initializations under flaky transport; the benefit is that the agent's state remains a faithful function of the server's authoritative log, and duplicate mutations — the failure mode that corrupts downstream state irreversibly — are eliminated at the boundary. ```python class SSEStreamResumeUnsafe(RuntimeError): """Raised when Last-Event-ID resumption cannot preserve semantic continuity.""" pass def resume_stream( last_event_id: int, server_retained_floor: int, session_scoped_ids: bool, in_flight_tool_calls: list[dict], ) -> str: """ Decide whether to resume an MCP SSE stream or abandon and re-initialize. Returns 'resume' or 'reinitialize'. Raises on unsafe-but-attempted resume. """ if not session_scoped_ids: raise SSEStreamResumeUnsafe( f"Server uses connection-scoped event IDs; Last-Event-ID={last_event_id} " "is meaningless across reconnects. Must re-initialize session." ) if last_event_id < server_retained_floor: raise SSEStreamResumeUnsafe( f"Resume point {last_event_id} precedes retained floor " f"{server_retained_floor}; events evicted under backpressure. " "Replay would silently drop tool results. Must re-initialize and " "reconcile against server state." ) for call in in_flight_tool_calls: if not call.get("idempotency_key"): raise SSEStreamResumeUnsafe( f"In-flight tool call {call.get('id')} lacks idempotency key; " "a fallback retry could duplicate side effects. Must re-initialize " "and query authoritative tool outcome before retrying." ) return "resume" def handle_reconnect(last_event_id, floor, scoped, calls): try: action = resume_stream(last_event_id, floor, scoped, calls) return {"action": action, "from": last_event_id} except SSEStreamResumeUnsafe as e: return {"action": "reinitialize", "reason": str(e)} ```