Under what conditions must an instance treat an MCP elicitation request as un-resumable across an SSE reconnect, and how does the `Last-Event-ID` cursor silently swallow a pending server-initiated prompt

**Date of Record:** 2026 December 1 **Scope:** Applies to MCP clients using the HTTP-native streamable transport with resumable SSE (`Last-Event-ID` replay) on a session where the server has issued a server-initiated `elicitation/create` request mid-stream. Does not apply to stdio transports, nor to sessions where the server disables resumption (`Mcp-Session-Id` without event replay support).

Core Distinction

The MCP streamable HTTP transport conflates two independent ordering domains under a single monotonic event ID: **server-to-client notification delivery** (idempotent, replayable, safe to re-deliver) and **server-initiated request lifecycle** (stateful, single-shot, consumed by exactly one response). Resumable SSE is correct for the first domain and silently corrupt for the second. An `elicitation/create` is a *request*, not a *notification*: it has a pending-response obligation on the client, and the server holds a coroutine awaiting that response. When the client's SSE connection drops after the elicitation event has been emitted but before the client has POSTed its `elicitation/result`, the client reconnects with `Last-Event-ID: N-1`. The server replays from `N-1`. The elicitation event at `N` is re-emitted. **This looks like recovery but is not**, because the server-side elicitation handler has already transitioned from `PENDING` to `ORPHANED` on the disconnect (or worse, to `CANCELLED` with a `-32602`-adjacent error that the client never sees because the POST channel is separate from the SSE channel). The replay delivers a *zombie request*: a request whose response slot no longer exists.

What Was Observed

A production trace, condensed. Server is a tool-augmented agent exposing `file_write` with a destructive-operation guard that elicits confirmation before overwriting.

t=0     client GET /mcp  Accept: text/event-stream
t=1     server SSE: id=41 event: message  {"method":"tools/call","id":"c-7","result":{...}}
t=2     server SSE: id=42 event: message  {"method":"elicitation/create","id":"e-1",
                "params":{"prompt":"Overwrite /etc/app.conf?","schema":{...}}}
t=2.1   server internal: elicitation e-1 state -> PENDING, awaiting POST /mcp
t=3     [network blip; client TCP RST]
t=3.1   server internal: elicitation e-1 state -> ORPHANED (no response within grace, or
                disconnect-triggered cancel). Tool handler for file_write resumes with
                outcome=CANCELLED, writes nothing, returns error to tool caller.
t=4     client reconnects: GET /mcp  Last-Event-ID: 41
t=4.1   server SSE replay: id=42 event: message  {"method":"elicitation/create","id":"e-1", ...}
t=5     client (correctly, per spec) POSTs {"method":"elicitation/result","id":"e-1",
                "result":{"action":"accept"}}
t=5.1   server: no pending elicitation with id e-1. Responds 404 / -32602 "unknown request id".
t=5.2   client logs a transport error, retries the POST once, gives up.
t=6     client believes the user approved the overwrite. Server wrote nothing. Divergence.

The failure is not in the replay. The replay is spec-correct. The failure is that the client's **recovery model** (SSE replay = full state restoration) is false for the request subdomain. The client has no way, from the SSE stream alone, to distinguish "id=42 is a live pending request" from "id=42 is a replayed corpse of a request the server already abandoned."

The observable symptom is a **silent no-op with a user-visible approval**: the human clicked "yes," the client recorded consent, the server performed nothing. In an agent loop this is the worst class of bug — a false-success that poisons downstream reasoning (the agent now believes the file was written and plans against a state that does not exist).

Condition of Validity

The zombie-replay hazard holds if and only if all three of the following are true simultaneously:

  1. **The server couples elicitation lifetime to SSE connection lifetime.** If the server keeps `PENDING` elicitations alive across reconnects (keyed by `Mcp-Session-Id`, not by connection), replay is safe: the replayed request is still live and the subsequent POST succeeds. Many servers do *not* do this — they cancel pending work on disconnect to avoid resource leaks, which is the natural choice for a stateless-ish HTTP transport.
  1. **The client treats SSE replay as authoritative state restoration.** A client that, on reconnect, *discards* any locally-tracked pending elicitations and re-derives its pending set purely from replayed events will accept the zombie. A client that reconciles against a separate `elicitation/list` (if the server exposes one) or that tracks elicitation IDs it has already *responded to* will reject it.
  1. **The elicitation result POST is idempotent-unsafe.** If the server deduplicates elicitation results by `id` (returning the prior outcome on duplicate POST), the second delivery of `e-1`'s result is harmless. If it 404s on unknown id, the client's retry logic may interpret that as a transient error and either retry forever or surface a spurious failure — but critically, the *tool call* has already completed with `CANCELLED`, so the client's approval is now orphaned regardless.

Break any one and the hazard collapses. Condition 1 is the one most commonly and silently broken.

Decision Boundary

The client must classify every replayed SSE event by **response-obligation status**, not by event ID monotonicity. The decision rule:

The invariant the server must uphold to make this tractable: **an elicitation's `id` is globally unique within the session and is never reused, and the server responds to a POST for an already-terminal elicitation id with a structured `{status: "already_resolved", outcome: <prior>}` rather than a bare 404.** Without this, the client cannot distinguish "I raced a cancel" from "I am talking to the wrong server."

The invariant the client must uphold: **the set of elicitation IDs it has issued a POST for is persisted across reconnects and consulted before any re-prompt.** A replayed `e-1` that matches a POSTed id is a zombie by definition — drop it and log, do not surface to the user.

Operational Effect

Downstream of the fix, the agent loop's correctness depends on the client surfacing `already_resolved` outcomes into the tool result rather than swallowing them. When the client drops a zombie `e-1` and the tool handler has already returned `CANCELLED`, the agent must receive a tool result of the form `{"status":"cancelled","reason":"elicitation_orphaned_on_reconnect"}` — not a `success` with empty effect. The distinction matters because the agent's next planning step branches on it: `cancelled` triggers a re-plan (ask again, or abort), while a silent success causes the agent to proceed against a false world model. In traces, the un-fixed variant shows up as an agent that "wrote" a file and then fails on the subsequent read with `ENOENT`, with the approval event present in the human-facing audit log but no corresponding write syscall in the server trace. That asymmetry — approval present, effect absent — is the signature of this boundary condition and should be a first-class alert.

import time
from dataclasses import dataclass, field
from typing import Literal


class ElicitationReplayViolation(RuntimeError):
    """Raised when a replayed server-initiated request is treated as live."""
    pass


@dataclass
class ElicitationRecord:
    id: str
    state: Literal["pending", "responded", "orphaned"]


@dataclass
class ResumableClient:
    posted_elicitation_ids: set[str] = field(default_factory=set)
    seen_elicitation_ids: set[str] = field(default_factory=set)

    def on_replayed_event(self, event: dict) -> dict:
        method = event.get("method", "")
        req_id = event.get("id")

        # Notifications: replay-safe, deliver idempotently.
        if method.startswith("notifications/"):
            return {"action": "deliver", "id": req_id}

        # Server-initiated requests: replay is NOT safe to auto-respond.
        if method in ("elicitation/create", "sampling/createMessage", "roots/list"):
            if req_id in self.posted_elicitation_ids:
                # We already responded to this id before the reconnect.
                # Replay is a zombie; do not re-prompt, do not re-POST.
                return {
                    "action": "drop_zombie",
                    "id": req_id,
                    "reason": "already_posted_pre_reconnect",
                }
            if req_id in self.seen_elicitation_ids:
                # Seen but never posted: ambiguous. Probe liveness.
                return {"action": "liveness_probe", "id": req_id}

            # First observation on this connection: treat as live.
            self.seen_elicitation_ids.add(req_id)
            return {"action": "surface_to_user", "id": req_id}

        return {"action": "ignore", "id": req_id}

    def submit_elicitation_result(self, req_id: str, result: dict) -> dict:
        if req_id not in self.seen_elicitation_ids:
            raise ElicitationReplayViolation(
                f"POST for elicitation {req_id!r} never observed on stream; "
                "refusing to send a response the server cannot correlate"
            )
        # Mark BEFORE the network call so a crash mid-POST still records intent.
        self.posted_elicitation_ids.add(req_id)
        return {"posted": True, "id": req_id, "result": result}


def reconcile_replay(client: ResumableClient, replayed_events: list[dict]) -> list[dict]:
    outcomes = []
    for ev in replayed_events:
        decision = client.on_replayed_event(ev)
        outcomes.append(decision)
        if decision["action"] == "drop_zombie":
            # The tool handler already returned CANCELLED server-side.
            # Surface this to the agent so it re-plans against reality.
            outcomes.append({
                "action": "emit_tool_result",
                "id": decision["id"],
                "payload": {
                    "status": "cancelled",
                    "reason": "elicitation_orphaned_on_reconnect",
                },
            })
    return outcomes