# What happens when an instance resumes a streamable MCP session across an SSE-to-POST fallback without renegotiating the event cursor **Date of Record:** 2026 November 23 **Scope:** Applies to MCP clients using the HTTP-native "streamable" transport where a long-lived SSE GET stream carries server-to-client events and a separate POST channel carries client-to-server requests, and where the client may fall back from SSE to polling POST when the stream drops. Does not apply to stdio transport or to single-request/response MCP servers with no server-initiated events. ## Core Distinction There are two distinct resumption problems in the streamable MCP transport, and they are routinely conflated: 1. **Session resumption** — re-establishing the logical MCP session (session ID, negotiated capabilities, tool schema snapshot) after a transport drop. 2. **Stream resumption** — re-establishing the *event cursor* on the server-to-client SSE channel so that events emitted during the gap are replayed exactly once. The failure mode documented here occurs when a client correctly performs (1) via `Mcp-Session-Id` replay but silently performs (2) *incorrectly* during an SSE-to-POST fallback: it switches to POST-based polling without transmitting the last-seen SSE `id:` cursor (or transmits it on the wrong channel), causing the server to either replay from an older cursor or start a fresh event sequence. The result is duplicated tool-call side effects, dropped progress notifications, or a forked event sequence that the client silently accepts as authoritative. ## What Was Observed A client agent held an open SSE stream on `GET /mcp` with `Last-Event-ID: 4471`. The stream dropped (proxy idle timeout at 60s, no `retry:` hint received). The client's fallback logic, on seeing the stream closed, issued `POST /mcp` with the session header and a `tools/call` payload — but did **not** attach `Last-Event-ID` to the POST, because the POST channel in this transport is nominally request-scoped, not event-cursor-scoped. The server, receiving a POST on an existing session with no cursor, treated it as a fresh event consumer. It emitted a `notifications/progress` sequence starting at event `0` on the POST response's inline SSE body, and — critically — it also *re-emitted* the buffered events `4472–4479` that had been produced during the gap, because those had never been acknowledged. The client, now reading events from the POST response, appended them to its event log without deduplicating against the pre-gap log. Events `4472–4475` were each processed twice. Two of those duplicated events were `notifications/message` carrying partial tool results that the client's reducer applied non-idempotently: a `write_file` chunk was applied twice, producing a doubled payload, and a `progress` counter advanced to 200%. The invariant that broke: **the event cursor is a property of the session, not of the transport channel.** The client assumed cursor continuity was tied to the SSE connection; the server assumed cursor continuity was tied to the session. Neither assumption was wrong in isolation; the mismatch surfaced only at the fallback boundary. ## Condition of Validity The failure requires all of the following to co-occur: - The transport is streamable HTTP with a *separate* SSE GET channel and POST request channel (not the single-response-body variant). - The server buffers unacknowledged events for replay (required for at-least-once delivery; this is the correct behavior). - The client's fallback path constructs POST requests without propagating the last-seen SSE event `id`. - The client's event reducer is non-idempotent with respect to at-least-once delivery (i.e., it does not key events by `id` before applying). If the client deduplicates by event `id` on ingest, the failure is masked — duplicated events are dropped harmlessly. If the server does not buffer for replay, events are lost instead of duplicated (a different, equally serious failure). The dangerous case is exactly the combination of replay-capable server + non-deduplicating client + cursor-dropping fallback. ## Decision Boundary The boundary is whether the client treats the event cursor as **transport-scoped** or **session-scoped**. - **Transport-scoped (fails):** cursor lives on the SSE connection object; when the connection dies, the cursor dies with it; fallback POST starts a new event consumer. This is the natural implementation if the SSE client library owns the `Last-Event-ID` header. - **Session-scoped (correct):** cursor is persisted in the session state object alongside `Mcp-Session-Id` and negotiated capabilities; every event-consuming request — SSE GET *or* POST — carries `Last-Event-ID` from that persisted value, and every received event updates it before dispatch to the reducer. The decision must be made at the transport layer, not the reducer layer. Relying on reducer-side deduplication is a defense-in-depth measure, not a substitute: it prevents double-application but does not prevent the client from *missing* events that the server skipped because it believed the cursor had advanced past them (which happens in the inverse failure — cursor advanced by a stale value). A second boundary: the fallback must decide whether to **resume** the SSE stream (re-issue GET with `Last-Event-ID`) or **degrade** to POST polling. Degrading to POST is only safe if the POST response's event stream is cursor-addressable. If the server's POST handler does not honor `Last-Event-ID` on the inline event body, the client must not treat POST events as continuing the SSE sequence — it must treat them as a separate, non-authoritative channel and reconcile explicitly. ## Operational Effect Downstream effects observed in this trace: - **Duplicated side effects.** Non-idempotent tool-result application doubled a file write and corrupted a progress counter. The agent's internal state diverged from the server's, but no error surfaced — the agent continued with a corrupted working set. - **Silent sequence fork.** Because the POST response began its own event numbering at `0`, the client's event log contained two interleaved sequences (`4472–4479` from the pre-gap buffer and `0–7` from the POST body) with no shared key. Post-hoc reconciliation was impossible. - **False completion.** The `progress` notification reaching 200% was interpreted by the agent's planner as task completion (it checked `progress >= 100`), causing premature termination of a multi-step plan with two steps unexecuted. The guardrail that bounds this: persist the event cursor in session state; attach it to *every* event-consuming request regardless of channel; deduplicate by event `id` at ingest before dispatch; and require that any channel transition (SSE→POST or POST→SSE) either carry the cursor or be explicitly marked as a non-authoritative resync that the reducer must reconcile rather than append. ```python from dataclasses import dataclass, field class CursorContinuityError(RuntimeError): """Raised when an event-consuming request cannot prove cursor continuity.""" @dataclass class SessionState: session_id: str last_event_id: int = -1 channel: str = "sse" # "sse" | "post" seen_ids: set[int] = field(default_factory=set) def build_event_request(state: SessionState, *, new_channel: str) -> dict: """Construct headers for an event-consuming request on either channel.""" if new_channel not in ("sse", "post"): raise CursorContinuityError(f"unknown channel {new_channel!r}") headers = {"Mcp-Session-Id": state.session_id} # Invariant: the cursor is session-scoped. Any channel transition must # carry the last-seen event id, or the request is a non-authoritative # resync and must be flagged as such. if state.last_event_id >= 0: headers["Last-Event-ID"] = str(state.last_event_id) elif state.channel != new_channel: # No cursor yet but switching channels: this is a fresh consumer on a # live session. Refuse silently forking the event sequence. raise CursorContinuityError( f"channel switch {state.channel}->{new_channel} with no cursor; " "cannot guarantee event continuity" ) return headers def ingest_event(state: SessionState, event_id: int, payload: dict) -> bool: """Apply an event, deduplicating by id. Returns True if newly applied.""" if event_id in state.seen_ids: return False # at-least-once replay: drop duplicate if event_id != state.last_event_id + 1 and state.last_event_id >= 0: # Gap detected: server skipped events. Do not silently advance. raise CursorContinuityError( f"event gap: expected {state.last_event_id + 1}, got {event_id}" ) state.seen_ids.add(event_id) state.last_event_id = event_id # ... dispatch payload to reducer here ... return True def fallback_to_post(state: SessionState) -> dict: """Degrade SSE->POST. Must preserve cursor or refuse.""" headers = build_event_request(state, new_channel="post") state.channel = "post" return headers ```