# Where must an instance reconcile a resumed MCP SSE stream against a Streamable-HTTP fallback that replayed a different event prefix **Date of Record:** 2026 November 30 **Scope:** Applies to MCP clients that negotiate HTTP-native transports (legacy SSE vs. Streamable HTTP) with per-session resumption via `Last-Event-ID`. Does not cover stdio transport, WebSocket transports, or stateless request/response MCP servers with no session identity. ## Core Distinction A resumption is not a reconnection. When an MCP client reattaches to a session after a transport drop, it is asking the server to *continue* an event stream from a specific cursor, not to *replay* a session. The legacy SSE transport encodes this contract as `Last-Event-ID` on `GET /sse`, and the server is expected to emit events strictly after that ID. Streamable HTTP encodes a weaker contract: the client POSTs to `/mcp` and may receive either a single JSON response or an SSE stream, with resumption signalled by `Last-Event-ID` on the POST itself. The non-obvious boundary is that these two contracts are *not* equivalent under fallback negotiation. When a client that was mid-stream on SSE is forced onto Streamable HTTP—because the SSE endpoint 404s, the server advertises only `application/json` on the POST, or a proxy strips the `text/event-stream` accept header—the fallback path has no obligation to honor the SSE event-ID cursor. It may replay from the beginning of the session's logical history, from the last *checkpoint* (a different granularity than the last *event*), or from nothing at all. The invariant that must hold is: **the client may not assume the event-ID space is shared across transports, and must reconcile a replayed prefix against its own applied-state ledger before dispatching any replayed tool result.** ## What Was Observed A tool-orchestrating agent held an SSE session with a server exposing three tools (`read_file`, `write_file`, `run_tests`). Mid-call to `run_tests`, the SSE connection dropped after the server had emitted event `id: 41` (the `run_tests` invocation acknowledgment) but before `id: 42` (the result). The client's ledger recorded `41` as *dispatched, pending result*. On reconnect, the client's transport negotiator observed the SSE endpoint returning `404` (the server had been redeployed with Streamable HTTP only) and fell back to `POST /mcp` with `Last-Event-ID: 41`. The server, running Streamable HTTP, treated the POST as a *new* request in the session and replayed its session event log from event `id: 1` as an SSE response stream—including the original `run_tests` acknowledgment at what it labeled `id: 41`, but also the earlier `write_file` result at `id: 12` and the `read_file` result at `id: 7`. The client, seeing well-formed SSE with monotonically increasing IDs, applied every event. The `write_file` at `id: 12` was re-applied to a file that had since been modified by a peer agent, silently reverting the peer's edit. The client then dispatched `run_tests` a second time because its ledger keyed on `(event_id, tool_name)` and the replayed `41` matched the pending record—but the *server-side* invocation had already completed and been recorded, so the second dispatch created a duplicate test run whose output the agent then reasoned over as if it were the original's result. The failure is not "the server replayed events." Servers are permitted to replay. The failure is that the client treated event IDs as a globally stable cursor across a transport change, when in fact the SSE event-ID namespace and the Streamable-HTTP event-ID namespace are server-defined and may overlap numerically while diverging semantically. Two transports, one integer space, no shared meaning. ## Condition of Validity The reconciliation invariant holds only when the client can establish all three of the following at fallback time: 1. **Namespace identity.** The fallback transport's event-ID space is the same space as the prior transport's. This is only knowable if the server advertises a stable session-scoped event-ID namespace (e.g., a `Mcp-Session-Id` plus a transport-independent sequence), or if the client can probe by requesting `Last-Event-ID` and observing whether the first returned ID is strictly greater than the cursor. If the first returned ID is `≤` the cursor, the namespaces diverge and replay reconciliation is required. 2. **Checkpoint granularity.** The client's ledger records applied state at the same granularity the server uses for replay. If the server replays from a checkpoint that predates the client's last-applied event, the client must be able to *reject* replayed events whose effects are already subsumed by later state. This requires the ledger to carry a monotonic `applied_seq` per side-effecting tool, not just an event-ID set. 3. **Idempotency key stability.** Any tool invocation that the client may re-dispatch after replay must carry an idempotency key that survives the transport change. SSE `Last-Event-ID` is not such a key; it is a cursor, not an invocation identity. The key must be client-generated and attached to the tool call payload, not derived from the transport. If any of the three is unestablished, the client is in an *unreconciled* state and must not dispatch replayed tool results. The correct behavior is to abort the session, surface the divergence, and re-establish with a fresh session ID rather than to "best-effort" apply the replay. ## Decision Boundary The decision is not "resume or restart." It is "resume with reconciliation, resume without reconciliation, or refuse." The boundary is drawn by whether the fallback transport's first emitted event ID is `>` the client's cursor *and* whether the client's ledger can prove no side-effecting event was applied twice. Concretely, on fallback: - If `first_replayed_id > cursor` and the ledger's `applied_seq` per tool is monotonic and the tool payloads carry client idempotency keys, **resume with reconciliation**: apply events, but gate each side-effecting tool result on `applied_seq` comparison and idempotency-key dedup. - If `first_replayed_id ≤ cursor` (replay from before the cursor), **resume without reconciliation is forbidden**. The client must either request a server-side checkpoint at `cursor` (if the server supports a `Last-Event-ID`-honoring replay endpoint) or refuse. - If the fallback transport is single-response JSON (no SSE), there is no event-ID stream at all. The client must treat the response as a *snapshot*, not a continuation, and reconcile by snapshot diff—which requires the snapshot to carry a `session_seq` the client can compare against `cursor`. The subtle case is the middle one: a server that replays from `1` but *also* honors the cursor for the first event it emits after the replay (i.e., it replays history, then continues). This is legal under Streamable HTTP and is the most dangerous configuration, because the client sees monotonic IDs and no obvious discontinuity. The only defense is the `applied_seq` ledger. ## Operational Effect The practical consequence is that MCP clients which implement transport fallback must carry a *transport-independent* session ledger, not a transport-scoped one. The ledger must record, per side-effecting tool invocation: the client-generated idempotency key, the `applied_seq` at dispatch, and the `applied_seq` at result-application. On any fallback, the client compares the fallback's first event ID against the cursor and, if replay is detected, walks the replayed events against the ledger, dropping any whose idempotency key is already present and rejecting any whose `applied_seq` is `≤` the ledger's current value for that tool. Servers, for their part, must advertise whether their event-ID space is transport-stable. The absence of such an advertisement is itself information: it means the client must assume instability and reconcile conservatively. The failure mode described here is not a bug in either transport; it is the predictable result of composing two transports whose resumption contracts were never designed to interoperate, and the invariant that bounds it is the client-side ledger's independence from the transport cursor. ```python class UnreconciledReplayError(RuntimeError): """Raised when a transport fallback replays events the client cannot safely apply.""" pass class SessionLedger: def __init__(self) -> None: self.cursor: int = 0 self.applied_seq: dict[str, int] = {} # tool_name -> monotonic applied seq self.idempotency_keys: set[str] = set() # client-generated invocation keys def record_dispatch(self, tool_name: str, key: str, seq: int) -> None: self.applied_seq.setdefault(tool_name, 0) self.idempotency_keys.add(key) def reconcile_fallback(self, first_replayed_id: int, replayed: list[dict]) -> list[dict]: if first_replayed_id <= self.cursor: # Replay from before the cursor: namespaces diverge or server ignored Last-Event-ID. # We cannot prove no side-effecting event was double-applied. safe = [] for ev in replayed: key = ev.get("idempotency_key") seq = ev.get("applied_seq", 0) tool = ev.get("tool_name") if key in self.idempotency_keys: continue # already applied if tool and seq <= self.applied_seq.get(tool, 0): raise UnreconciledReplayError( f"replayed event {ev.get('id')} for {tool} has applied_seq={seq} " f"<= ledger {self.applied_seq[tool]}; cannot safely apply" ) safe.append(ev) return safe # Strictly forward: honor the stream, but still dedup by idempotency key. return [ev for ev in replayed if ev.get("idempotency_key") not in self.idempotency_keys] def apply_fallback_stream(ledger: SessionLedger, first_id: int, events: list[dict]) -> None: if not events: raise UnreconciledReplayError("fallback stream empty; cannot establish cursor continuity") safe = ledger.reconcile_fallback(first_id, events) for ev in safe: # dispatch side-effecting tool results only after reconciliation ledger.cursor = max(ledger.cursor, int(ev.get("id", 0))) if ev.get("tool_name"): ledger.record_dispatch(ev["tool_name"], ev["idempotency_key"], ev.get("applied_seq", 0)) ```