# Where must an instance reconcile SSE event-ID continuity when an MCP session migrates from resumable SSE transport to streamable HTTP mid-conversation **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers/clients that expose the same logical session across both the legacy resumable SSE transport (GET stream + POST endpoint, `Last-Event-ID` resumption) and the newer streamable HTTP transport (single endpoint, per-message `id` correlation, optional SSE responses). Does not apply to pure stdio transport or to sessions that never cross transport boundaries. ## Core Distinction The failure is not "the connection dropped." Both transports tolerate drops. The failure is that the two transports encode *resumption identity* in incompatible coordinate systems, and the migration path silently collapses one into the other. Resumable SSE defines continuity by a monotonic, server-issued `id:` field on each event. The client's only legal recovery primitive is `Last-Event-ID: ` on reconnect; the server replays everything strictly after that id. The id is an *opaque cursor into a server-side event log* — it is not a message identifier, not a JSON-RPC id, and carries no semantic meaning the client may interpret. Streamable HTTP defines continuity differently. A single endpoint accepts POSTed JSON-RPC requests; responses may be `application/json` or an SSE stream, and streamed responses carry per-message `id` fields that correlate to the *request* that produced them (JSON-RPC request ids), not to a resumable log cursor. There is no `Last-Event-ID` semantics: if the stream breaks mid-response, the client is expected to re-issue the request (with the same JSON-RPC id) or open a fresh GET for server-initiated messages. The transport has no server-side replay log keyed by a monotonic cursor. So the boundary condition is: **at migration time there exist in-flight events that the old transport could replay by cursor but the new transport can only re-derive by request replay — and the two sets are not equal.** Events the server *pushed spontaneously* (notifications, progress, sampling requests) under SSE have a `Last-Event-ID` but no originating JSON-RPC request id to replay against. Events the client *requested* under streamable HTTP have a request id but no cursor. A naive migration that carries the SSE `Last-Event-ID` forward as if it were a resume token, or that drops it and assumes the new transport's request-replay covers the gap, loses exactly one class of message in each direction. ## What Was Observed A long-running agent session (tool-call loop against a filesystem MCP server) ran on resumable SSE. At event id `4417` the client received a `notifications/progress` for a `tools/call` still executing, plus a `notifications/message` logging line. The orchestrator then decided to migrate the session to streamable HTTP (server advertised both; the client preferred the newer transport for its single-endpoint model and better proxy behavior). The migration sequence executed: 1. Client opened the streamable HTTP endpoint and POSTed an `initialize`-adjacent session-continuation request carrying the existing `Mcp-Session-Id`. 2. Client discarded the old `EventSource` and its last-seen `Last-Event-ID` of `4417`, on the reasoning that "streamable HTTP resumes by request id, so the outstanding `tools/call` will just be re-polled." 3. Client re-issued the pending `tools/call` GET-equivalent? No — it did not. The `tools/call` had already returned its `result` at id `4415`; only the *progress* and *log* notifications were in flight. Result: the `tools/call` result was intact (it was a completed request/response, replayable by request id if needed, and already delivered). But the `notifications/progress` at `4416` and `notifications/message` at `4417` — server-initiated, never tied to a client request id — were never delivered on the new transport and never replayed. The agent's progress tracker sat at the last pre-migration percentage; its log buffer had a hole. Downstream, the agent's "did the tool finish cleanly?" check keyed off the last progress event, concluded the call was still 60% done, and re-issued a *duplicate* `tools/call` for an idempotent-but-expensive operation. The duplicate returned a second `result` with a different content hash (the tool embedded a timestamp), which the agent's auditor flagged as a consensus conflict against the first result. The trace, distilled: ``` SSE log (server-side): id 4415 response {id: 12, result: } <- delivered, acked id 4416 notification {method: notifications/progress, params:{token, 60%}} id 4417 notification {method: notifications/message, params:{level:info,...}} id 4418 notification {method: notifications/progress, params:{token, 100%}} Migration at client last-seen = 4417: streamable-HTTP resume token = none (transport has no cursor) request-replay set = {12} (already completed) server-push set = {4416, 4417, 4418} (unreplayable on new transport) Outcome: 4418 (the 100% completion signal) lost. Agent observes last progress = 60%, re-issues call 12. ``` Note the asymmetry that made this non-obvious: the *completed* work (the tool result) survived because it was a request/response pair; the *completion signal* (a spontaneous notification) did not, because it had no request id. The migration preserved exactly the wrong half of the state. ## Condition of Validity The invariant holds — i.e., migration is safe — only when **all of the following are simultaneously true**: 1. **No un-acked server-push events exist at cutover.** Formally, the client's last-seen `Last-Event-ID` equals the server's current log head for that session, so there is nothing in the SSE log after the cursor that the new transport would need to synthesize. 2. **Every in-flight `tools/call` / `sampling` / `elicitation` has either completed (result delivered and acked) or been explicitly cancelled** before the transport swap, so no future server-push notification is owed for it. 3. **The server treats `Mcp-Session-Id` as transport-independent** and preserves the session's server-side state (subscriptions, progress tokens, resource watches) across the transport change. If the server scopes subscriptions to the SSE connection, they are silently dropped at cutover regardless of cursor handling. 4. **The client does not reinterpret the SSE `Last-Event-ID` as a streamable-HTTP resume token**, nor discard it while any server-push event remains un-acked. When any condition is false, events are lost in one direction and duplicated in the other. Condition 1 is the hard one: it requires a *quiescence barrier* — the client must drain the SSE stream to the log head (or a server-acknowledged checkpoint) before migrating, not merely stop reading. A second, subtler validity condition: the server's SSE `id` space and the streamable-HTTP JSON-RPC `id` space must not be conflated. They are independent namespaces. A migration routine that maps `Last-Event-ID: 4417` to "resume JSON-RPC requests after id 4417" is nonsensical — JSON-RPC ids are client-chosen and may be strings, may restart, may collide across sessions. This mapping must be rejected at the protocol layer, not left to client discipline. ## Decision Boundary The decision is *not* "which transport is better." It is: **at the moment of migration, is the session quiescent with respect to server-push events?** - If **yes** (last-seen cursor == server log head, no in-flight calls owing notifications): migrate freely. Carry `Mcp-Session-Id`, drop `Last-Event-ID`, open streamable HTTP, re-subscribe if the server requires it. - If **no**: do not migrate mid-flight. Either (a) drain to quiescence first — keep the SSE connection open, read until the server signals log-head or the client's outstanding calls all resolve, then migrate; or (b) if the server supports it, request an explicit checkpoint that flushes pending notifications before the swap; or (c) abort the migration and stay on SSE for the remainder of the session. The boundary is sharp because the cost is asymmetric: migrating while non-quiescent *looks* successful (the session continues, requests work) but silently drops the completion signals that autonomous agents use to decide when to stop. A human-facing client would just show a stale progress bar; an agent re-executes work and produces conflicting results. The guardrail must therefore be a hard precondition, not a heuristic. The correct architectural invariant: **transport migration is a state-transfer operation, and the transferred state must include the set of owed-but-undelivered server-push events. If that set is non-empty and the target transport cannot represent it, migration is illegal.** The SSE `Last-Event-ID` is the only encoding of that set; it must be either fully consumed (drained) or explicitly carried as a "replay obligation" the new transport fulfills by other means (e.g., server re-emits the missed notifications on the new stream). Discarding it without draining is the bug. ## Operational Effect Concretely, an agent runtime that ignores this boundary exhibits a characteristic failure signature: **duplicate tool execution with divergent results, correlated with transport changes, with progress/log gaps immediately preceding the duplicate.** The auditor sees two `result`s for one logical call with different content hashes (because tools embed timestamps, nonces, or live data), flags a consensus conflict, and the swarm either retries again or halts on the conflict — compounding the original one-event loss into a multi-agent stall. The mitigation that actually bounds it: - Treat `Last-Event-ID` as a **replay obligation**, not a disposable cursor. On migration, if last-seen < server log head, refuse to migrate or drain first. - Make `tools/call` results **idempotency-keyed** by the JSON-RPC request id *plus* a client-generated idempotency token, so a re-issued call after migration returns the cached original result rather than re-executing. This converts the duplicate-execution failure into a benign replay. - Require the server to **re-emit un-acked notifications** on the new stream when the session id is carried across transports, or to expose a `notifications/replay` mechanism keyed by the SSE cursor. Absent that, the client must drain. - Assert at the transport layer that the SSE `id` namespace and the JSON-RPC `id` namespace are never cross-mapped; a migration routine that does so should raise immediately rather than proceed. The residual risk after these guards: a server that scopes subscriptions to the SSE connection (validity condition 3) will drop resource watches at cutover even with perfect cursor handling, and the client will not notice until a watched resource changes and no notification arrives. That is a separate invariant — subscription continuity — and must be re-established explicitly post-migration, not assumed. ```python from __future__ import annotations from dataclasses import dataclass class TransportMigrationError(RuntimeError): """Raised when an MCP session migration would lose server-push events.""" class ReplayObligationUnmet(TransportMigrationError): """SSE cursor is behind the server log head and target transport cannot replay.""" @dataclass(frozen=True) class SessionSnapshot: session_id: str last_seen_event_id: int # client's SSE Last-Event-ID server_log_head_id: int # server's current SSE log head for this session outstanding_calls: frozenset[int] # JSON-RPC ids still owing notifications target_transport: str # "streamable_http" | "sse" def migrate_session(snap: SessionSnapshot, *, target_supports_replay: bool) -> str: """ Enforce the quiescence barrier before allowing SSE -> streamable-HTTP migration. Invariant: migration is legal only if there are no owed-but-undelivered server-push events that the target transport cannot represent. """ if snap.target_transport not in {"streamable_http", "sse"}: raise TransportMigrationError(f"unknown transport {snap.target_transport!r}") if snap.target_transport == "sse": # Staying on / moving to SSE: cursor semantics are native, no barrier needed # beyond normal resumption. return "sse" # Target is streamable HTTP: it has NO Last-Event-ID replay log. behind = snap.server_log_head_id - snap.last_seen_event_id owed_events = behind > 0 owed_calls = len(snap.outstanding_calls) > 0 if (owed_events or owed_calls) and not target_supports_replay: # The exact failure observed: completed results survive, completion # notifications do not, agent re-executes and diverges. raise ReplayObligationUnmet( "refusing SSE->streamable-HTTP migration: " f"last_seen={snap.last_seen_event_id} log_head={snap.server_log_head_id} " f"(owed_events={owed_events}) outstanding_calls={sorted(snap.outstanding_calls)} " "target transport cannot replay server-push events; " "drain to quiescence or require server-side notification replay" ) if owed_events and target_supports_replay: # Legal only because server will re-emit missed notifications on the # new stream keyed by the carried cursor. return "streamable_http_with_replay" return "streamable_http" def attempt_migration(snap: SessionSnapshot, *, target_supports_replay: bool) -> str: try: return migrate_session(snap, target_supports_replay=target_supports_replay) except ReplayObligationUnmet: # Fall back to draining on SSE rather than migrating mid-flight. return "sse_drain_then_retry" ```