# In what scenarios must an instance refuse SSE resumption after an MCP session reattachment loses the Last-Event-ID continuity anchor **Date of Record:** 2026 November 23 **Scope:** Applies to MCP servers and clients using HTTP-native transport with streamable SSE and `Last-Event-ID` resumability across a session reattachment (new HTTP connection to an existing `Mcp-Session-Id`). Does not apply to stdio transports or to fresh sessions that never established an event-ID stream. ## Core Distinction The failure mode is not "SSE stream dropped." That is routine and recoverable. The failure mode is **silent resumption against a reattached session whose event-ID namespace was reinitialized or forked**, so that the client's `Last-Event-ID: N` is accepted by the server but resolved against a *different* event history than the one the client actually consumed. MCP's streamable HTTP transport lets a client POST a request and receive an SSE stream, then reconnect with `Last-Event-ID` to replay missed events. Reattachment is the act of pointing a new HTTP connection at an existing `Mcp-Session-Id`. The invariant most implementations assume — and most violate — is: > The pair (`Mcp-Session-Id`, `Last-Event-ID`) uniquely identifies a position in a single monotonic event log for the lifetime of that session. When a session is reattached after a server-side restart, a load-balancer shard change, or a session-store eviction-and-restore, the server may hand back a *fresh* event counter starting at 0 or 1, or may have persisted the session metadata but not the event log. The client's `Last-Event-ID: 47` then either (a) exceeds the new log's head, so the server replays nothing and the client waits forever for events that "already happened" in a different history, or (b) is ≤ the new head, so the server replays events 48..k from an *unrelated* request stream — injecting foreign tool results into the client's reasoning loop. Case (b) is the dangerous one. The client cannot distinguish a legitimate replay from a cross-history replay because both arrive as well-formed `text/event-stream` frames with valid `data:` JSON-RPC payloads. ## What Was Observed A tool-calling agent issued `tools/call` for a long-running retrieval (server-side fan-out over ~90s). The SSE stream carried event IDs 1..12 (progress notifications) before the connection dropped at a proxy idle timeout. The client reconnected with `Last-Event-ID: 12` to the same `Mcp-Session-Id`. Between the drop and the reconnect, the server's pod was rescheduled. The new pod restored the session record from a shared store (session ID, negotiated capabilities, auth context) but the event log lived in pod-local memory and was gone. A *second* client — a parallel sub-agent sharing the same session ID due to an orchestrator bug — had meanwhile opened its own stream, and the new pod's event counter restarted at 1 for that stream. The reattaching client sent `Last-Event-ID: 12`. The new pod's log head was 9 (from the sub-agent's stream). The server had two plausible behaviors and chose the wrong one: it clamped the cursor to head and began replaying from event 10 of the *sub-agent's* stream. The reattaching agent received three `notifications/progress` frames referencing a `progressToken` it had never issued, followed by a `result` payload for a `tools/call` it had not made. The agent's reasoning loop treated the foreign `result` as the answer to its own pending call — the JSON-RPC `id` field was absent on the notification-style frames and the client's demultiplexer fell back to "most recent pending request." It returned a document from the wrong query. No error was raised anywhere in the stack. ## Condition of Validity Resumption is only valid when the server can prove continuity of the event-ID namespace across the reattachment. Concretely, the server must be able to answer: *is event N in my current log the same event N the client last saw?* This holds only if at least one of the following is enforced: 1. **Monotonic session-scoped counter persisted with the log.** The event counter and the log are stored atomically; a restore that cannot recover the counter must fail the reattachment rather than reset it. 2. **Namespace epoch in the event ID.** Event IDs are opaque strings embedding a session-generation token (e.g., `gen7:48`). A `Last-Event-ID` whose generation does not match the current generation is rejected with a resumption-invalid error, forcing the client to re-issue the request under a fresh ID. 3. **Single-writer binding.** The session ID is bound to one active stream at a time; a second writer invalidates the session, so no forked history can exist to replay from. If none holds — which is the default for naive in-memory event logs behind a rolling deploy — the (`Mcp-Session-Id`, `Last-Event-ID`) pair is not a continuity anchor. It is a guess. ## Decision Boundary The client-side decision is not "reconnect or not." It is "resume or re-issue." - **Resume** (send `Last-Event-ID`) is correct when the server advertises a resumption capability that includes an epoch or generation token, and the client can verify the returned first event's ID is a strict successor in the same namespace. - **Re-issue** (drop the cursor, start a new request with a fresh JSON-RPC `id`, accept possible duplicate side effects) is mandatory when the server's resumption contract is opaque, when the session was reattached across a process boundary the client cannot attest, or when any replayed event fails a client-side schema check against the *pending request's* expected notification shape. The boundary is crossed the moment a replayed event cannot be tied by JSON-RPC `id` to a request the client currently has outstanding. At that point the client must treat the stream as poisoned and re-issue, not resume. Resuming past that point is how foreign results enter the reasoning loop. ## Operational Effect The client must carry a **pending-request ledger** keyed by JSON-RPC `id`, and every replayed SSE frame must be validated against it before being admitted to the reasoning context. Frames that reference unknown `progressToken`s or carry `result`/`error` for absent `id`s are dropped and counted; a nonzero drop count during a single resumption invalidates the resumption. The server, symmetrically, must refuse to honor a `Last-Event-ID` it cannot place in its current epoch, returning a terminal error rather than clamping to head. Clamping-to-head is the specific anti-pattern that converts a transport hiccup into silent data corruption. The cost of the guardrail is occasional duplicate tool executions on re-issue. The cost of omitting it is an agent that confidently answers the wrong question with no trace of the substitution — undetectable in logs, because every frame was well-formed. ```python import json from dataclasses import dataclass, field class ResumptionContinuityError(RuntimeError): """Raised when an SSE resumption cannot be tied to the pending-request ledger.""" @dataclass class PendingLedger: outstanding: dict[str, str] = field(default_factory=dict) # jsonrpc id -> method seen_progress_tokens: set[str] = field(default_factory=set) def register(self, req_id: str, method: str, progress_token: str | None) -> None: self.outstanding[req_id] = method if progress_token: self.seen_progress_tokens.add(progress_token) def admit_replayed_event(ledger: PendingLedger, raw_data: str, last_event_id: str) -> dict: """Validate a replayed SSE frame against the pending ledger. Returns the parsed JSON-RPC message if it is safe to admit to the reasoning context. Raises ResumptionContinuityError if the frame cannot be attributed to an outstanding request in the current event-ID namespace. """ try: msg = json.loads(raw_data) except json.JSONDecodeError as exc: raise ResumptionContinuityError( f"unparseable replay frame at Last-Event-ID={last_event_id}: {exc}" ) from exc # Progress notifications must reference a token this client issued. if msg.get("method") == "notifications/progress": token = (msg.get("params") or {}).get("progressToken") if token not in ledger.seen_progress_tokens: raise ResumptionContinuityError( f"foreign progressToken {token!r} replayed at event {last_event_id}; " "event-ID namespace forked — must re-issue, not resume" ) return msg # Result/error frames must carry an id we have outstanding. if "result" in msg or "error" in msg: req_id = msg.get("id") if req_id is None or str(req_id) not in ledger.outstanding: raise ResumptionContinuityError( f"replay frame carries id={req_id!r} with no outstanding request " f"at event {last_event_id}; refusing to admit foreign result" ) return msg # Unknown frame shapes are not admissible under resumption. raise ResumptionContinuityError( f"unrecognized replayed frame shape at event {last_event_id}: " f"keys={sorted(msg.keys())}" ) def resume_stream(ledger: PendingLedger, server_epoch: str, client_epoch: str, frames: list[tuple[str, str]]) -> list[dict]: if server_epoch != client_epoch: raise ResumptionContinuityError( f"session epoch mismatch: client={client_epoch} server={server_epoch}; " "reattachment crossed a process boundary — re-issue required" ) admitted: list[dict] = [] for event_id, data in frames: admitted.append(admit_replayed_event(ledger, data, event_id)) return admitted ```