# Where must an instance bound replayed SSE event identity when an MCP streamable-HTTP session resumes across an SSE-to-POST fallback? **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients and servers using the streamable-HTTP transport where a server may downgrade an SSE stream to per-request POST responses and the client attempts session resumption via `Last-Event-ID`. Does not cover stdio transport, WebSocket transports, or stateless per-call HTTP without session identity. ## Core Distinction The failure is not "the connection dropped." A dropped SSE stream is a recoverable transport event; the MCP streamable-HTTP spec anticipates it by requiring the server to attach monotonic `id:` fields to SSE events so a client can resume with `Last-Event-ID` and receive only events after that cursor. The non-obvious boundary is this: **SSE event IDs are stream-scoped, but the fallback path is request-scoped.** When a server negotiates a downgrade from a long-lived SSE stream to discrete POST responses (because the client's `Accept` header omitted `text/event-stream`, or the server's concurrency budget forced it, or an intermediary stripped the stream), the resumed session's new events are emitted on a *different* stream whose ID space may restart, overlap, or be generated by a different code path. A client that trusts `Last-Event-ID` as a global session cursor will silently drop or duplicate events at the seam. The invariant that must hold is: **event ID monotonicity is only guaranteed within a single stream incarnation; across a fallback boundary the client must treat the ID space as re-derived and reconcile by message identity, not by cursor alone.** ## What Was Observed A client opened a streamable-HTTP session with `POST /mcp` carrying `Accept: text/event-stream`. The server responded with an SSE stream and assigned IDs `1..47` as the agent's tool-call progress events flowed. At event 47 the network path flapped; the client reconnected with `Last-Event-ID: 47`. The server, now under a concurrency cap, negotiated the fallback: it answered the reconnect with a `200` and `Content-Type: application/json` per-request responses rather than reopening an SSE stream, and the events after 47 were delivered as discrete POST results. Those discrete results carried `id` fields generated by a *separate* counter that began at `1`. The client's resume logic compared incoming IDs against its high-water mark of `47` and discarded events `1..46` as "already seen," then accepted event `47` as a duplicate and dropped it too. The agent lost 46 tool-progress events including the terminal result of a `write_file` call, resumed reasoning from a stale checkpoint, and re-issued the write against a file that had already been committed — producing a duplicate side effect. The trigger condition is precise: **a resume request that crosses a stream-incarnation boundary where the new incarnation reuses an overlapping ID namespace without a discriminator.** It requires all three of: (a) a prior SSE stream with IDs the client has recorded, (b) a fallback negotiation that changes the delivery mechanism, and (c) a server that does not namespace or reset-detect the ID space across that boundary. Remove any one and the failure does not fire — which is why it survives casual testing, since happy-path reconnects within the same SSE incarnation behave correctly. ## Condition of Validity The `Last-Event-ID` resume contract is *valid only when the server can prove, and the client can verify, that the new stream is a continuation of the same event log.* Two conditions must both hold: 1. **Server-side continuity attestation.** The server must either continue the same monotonic counter across the fallback, or explicitly signal a new incarnation with a distinguishable ID scheme (e.g., a per-incarnation prefix or a `reset` marker) so the client knows the cursor is no longer meaningful. 2. **Client-side identity reconciliation.** The client must not equate "ID ≤ high-water mark" with "already delivered." It must reconcile on message identity (a content hash or a server-assigned message UUID carried in the payload) and treat the cursor as a *hint* for replay pruning, never as a correctness gate. When either condition is absent, the resume is operating outside its validity envelope and the client's dedup logic is unsound. This is not a bug in the spec; it is a boundary the spec leaves to implementations, and the boundary is exactly where fallback negotiation lives. ## Decision Boundary The architect must decide, at the moment fallback is negotiated, whether the session is **resumable-by-cursor** or **resumable-by-identity**. The decision rule: - If the server can guarantee a single monotonic event-ID space across all incarnations of a session (including fallback), the client may prune by cursor. This is cheap and is the common case. - If the server cannot — because fallback spawns a fresh event generator, because an intermediary rewrites IDs, or because the downgrade path shares no state with the SSE path — the client **must** fall back to identity-based reconciliation and treat any cursor-based pruning as advisory only. The dangerous middle ground is a server that *believes* it maintains a monotonic space but whose fallback handler instantiates a new counter. The client cannot distinguish this from a correct server without out-of-band signal. Therefore the safe default, absent an explicit continuity attestation in the fallback response (a header or a session metadata field declaring the ID space is shared), is to assume the ID space is *not* shared and reconcile by identity. The cost is one content hash per event; the cost of getting it wrong is duplicated side effects and lost terminal results. ## Operational Effect Concretely, the guardrail is a resume gate that runs before the agent consumes any event after a fallback boundary: 1. On reconnect, inspect the response `Content-Type`. If it is not `text/event-stream`, a fallback has occurred; set `resume_mode = identity`. 2. In `identity` mode, maintain a set of delivered message IDs (payload-derived, not stream-derived). Deliver only events whose message ID is unseen; never prune on numeric cursor comparison. 3. If the server supplies a continuity attestation (shared ID space), promote to `cursor` mode and prune by `Last-Event-ID` as normal. 4. If a resumed event's message ID collides with a delivered ID but its content differs, raise — this indicates a server-side replay bug or ID reuse across incarnations and must halt the session rather than guess. This bounds the blast radius to a single event and forces the failure to surface as an explicit exception instead of a silent duplicate write. The invariant to carry forward: **the cursor is a transport hint, the message identity is the correctness anchor, and the fallback boundary is where the two diverge.** ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ResumeBoundaryError(RuntimeError): """Raised when a resumed MCP session crosses a fallback boundary without a verifiable continuity attestation, or when message identity collides with differing content across incarnations.""" pass @dataclass class Event: stream_id: int payload: bytes incarnation: Optional[str] = None def message_id(self) -> str: return hashlib.sha256(self.payload).hexdigest() @dataclass class SessionResumer: delivered_ids: set = field(default_factory=set) delivered_hashes: dict = field(default_factory=dict) high_water_stream_id: int = 0 resume_mode: str = "cursor" # "cursor" | "identity" def on_reconnect(self, response_content_type: str, continuity_attested: bool) -> None: if "text/event-stream" not in response_content_type: # Fallback negotiated: SSE downgraded to per-request POST. if not continuity_attested: self.resume_mode = "identity" else: self.resume_mode = "cursor" else: self.resume_mode = "cursor" def accept(self, ev: Event) -> bool: mid = ev.message_id() if self.resume_mode == "cursor": if ev.stream_id <= self.high_water_stream_id: return False self.high_water_stream_id = ev.stream_id self.delivered_ids.add(mid) self.delivered_hashes[mid] = ev.payload return True # identity mode: cursor is advisory only. if mid in self.delivered_hashes: if self.delivered_hashes[mid] != ev.payload: raise ResumeBoundaryError( f"identity collision: message {mid[:12]} delivered " f"with different content across incarnations; " f"stream_id={ev.stream_id}, incarnation={ev.incarnation}" ) return False # true duplicate, safe to drop self.delivered_ids.add(mid) self.delivered_hashes[mid] = ev.payload return True def require_attestation_or_identity(self, fallback_response_headers: dict) -> None: attested = fallback_response_headers.get( "x-mcp-event-id-continuity", "" ).lower() == "shared" if not attested and self.resume_mode != "identity": raise ResumeBoundaryError( "fallback negotiated without shared-ID attestation; " "refusing cursor-based pruning to avoid silent event loss" ) ```