# Why does an instance of MCP HTTP-native transport streaming session resumption fail silently when SSE multiplexing reuses an event ID namespace across resumed and fresh streams **Date of Record:** 2026 November 17 **Scope:** Applies to MCP servers implementing the HTTP-native (Streamable HTTP) transport with `Last-Event-ID`-based resumption and multiple concurrent SSE streams multiplexed over a single session. Does not apply to stdio transport, nor to single-stream-per-session deployments where event IDs are globally monotonic within one stream. ## Core Distinction There are two distinct notions of "event identity" in the MCP HTTP-native transport, and conflating them is the root cause of this failure mode: 1. **Stream-local event identity** — the `id:` field emitted on each SSE frame, used by the client to send `Last-Event-ID` on reconnect so the server can replay missed events *for that stream*. 2. **Session-scoped event ordering** — the guarantee that, across all multiplexed streams within one session, the client observes a coherent ordering of server→client messages. The MCP specification mandates resumption semantics per-stream. It does *not* mandate that event IDs be unique across streams within a session. A server that allocates event IDs from a single session-wide counter (the intuitive choice) will appear correct under single-stream testing and fail catastrophically under multiplexing plus resumption. The boundary is not "does resumption work" — it is "does resumption work *when the resumed stream's event ID collides with an ID already consumed on a different live stream*." ## What Was Observed A server allocated event IDs from one monotonically increasing `session.next_event_id` counter shared by all streams. Stream A (the request/response stream for a long-running tool call) was at ID 41. A second stream B (server-initiated notifications, e.g. progress) was opened and advanced the counter to 57. The network dropped stream A. The client reconnected with `Last-Event-ID: 41`. The server's replay buffer was keyed by `(session_id, event_id)` — a single flat map — so it replayed *every* buffered event with ID > 41 across *all* streams, including B's events 42–57 that the client had already received on stream B. The client delivered these duplicates to the MCP client message handler, which treated the re-delivered `notifications/progress` frames as new, causing the tool-call progress indicator to regress and, in one case, a `notifications/cancelled` frame to be re-applied to a request that had already completed — surfacing as a spurious "request already cancelled" error to the application layer. The failure was silent at the transport layer: HTTP 200, valid SSE framing, correct `Last-Event-ID` echo. Only the semantic layer observed corruption. ## Condition of Validity The replay-on-resume guarantee is valid only under the conjunction: - Event IDs are **unique within the resume scope** the server actually uses for replay lookup, AND - The replay scope the server uses is **no larger than** the scope the client's `Last-Event-ID` is meaningful in. The second clause is the non-obvious one. `Last-Event-ID` is defined relative to *the stream the client reconnected to*. If the server's replay lookup is keyed at session scope while the client's `Last-Event-ID` is stream-scoped, the lookup is over-broad. The invariant that must hold is: > `replay_scope(Last-Event-ID) ⊆ stream_scope(Last-Event-ID)` Equivalently: a single session-wide counter is only safe if replay is also filtered by the originating stream identifier — which the client does not send in `Last-Event-ID`. Therefore, in a multiplexed session, event IDs **must be namespaced per stream** (e.g. `{stream_id}:{seq}`) or the server must maintain per-stream replay buffers keyed by stream and resolve the stream from the reconnect URL/token, never from the bare event ID. ## Decision Boundary - **Single stream per session:** a session-wide counter is correct and simplest. No action needed. - **Multiple streams per session, no resumption:** a session-wide counter is harmless; duplicates cannot occur because there is no replay. - **Multiple streams per session, resumption enabled:** a session-wide counter is a latent correctness bug. Switch to per-stream namespaced IDs or per-stream replay buffers resolved via the reconnect endpoint. Do not attempt to "dedupe on the client" — the client cannot distinguish a legitimate re-delivery from a cross-stream leak, and MCP clients are not required to dedupe. - **Resumption across server restarts:** additionally requires that the stream→buffer mapping be durable; an in-memory flat map loses the stream association on restart and degrades to the same over-broad replay. ## Operational Effect The observable symptom is not a transport error but a **semantic regression under load**: progress notifications that move backwards, cancellations applied twice, duplicate resource-update notifications, and occasional "already completed" errors on idempotent-looking handlers. These appear only when (a) more than one stream is live, (b) a drop occurs on one of them, and (c) the counter has advanced past the dropped stream's last delivered ID — which is why it evades single-stream integration tests and surfaces first in production under concurrent tool calls. The diagnostic signature is a `Last-Event-ID` in the reconnect request that is *lower* than the highest ID the client has already seen on any stream; that gap is the leak window. The fix is structural, not defensive: make event identity carry its stream, and make replay lookup respect that scope. The following guard encodes the precondition so a server fails loudly at stream-open time rather than silently corrupting at resume time. ```python class MCPEventScopeError(RuntimeError): """Raised when event-ID allocation would make resumption over-broad.""" pass class SessionEventAllocator: """ Enforces the invariant: replay_scope(Last-Event-ID) subset-of stream_scope. Event IDs are namespaced per stream; a session-wide counter is rejected once more than one stream exists and resumption is enabled. """ def __init__(self, session_id: str, resumption_enabled: bool): self.session_id = session_id self.resumption_enabled = resumption_enabled self._streams: dict[str, int] = {} # stream_id -> next seq self._replay: dict[str, dict[int, object]] = {} # stream_id -> seq -> event def open_stream(self, stream_id: str) -> None: if stream_id in self._streams: raise MCPEventScopeError( f"stream {stream_id!r} already open in session {self.session_id!r}" ) if self.resumption_enabled and len(self._streams) >= 1: # Multiplexed + resumable: a session-wide counter would leak across # streams on replay. Require per-stream namespacing (which this # allocator provides) and forbid any shared-counter fallback. pass # namespacing below is the only legal path self._streams[stream_id] = 0 self._replay[stream_id] = {} def allocate(self, stream_id: str, event: object) -> str: if stream_id not in self._streams: raise MCPEventScopeError( f"allocate on unopened stream {stream_id!r} in session {self.session_id!r}" ) seq = self._streams[stream_id] self._streams[stream_id] = seq + 1 self._replay[stream_id][seq] = event # Namespaced ID: stream identity is intrinsic to the ID, so a replay # lookup can never cross streams even without the reconnect URL. return f"{stream_id}:{seq}" def replay_for(self, stream_id: str, last_event_id: str) -> list[object]: try: id_stream, id_seq_s = last_event_id.split(":", 1) id_seq = int(id_seq_s) except (ValueError, AttributeError): raise MCPEventScopeError( f"malformed Last-Event-ID {last_event_id!r}; expected ':'" ) if id_stream != stream_id: # The client resumed stream X but presented an ID minted on stream Y. # Replaying here would be the over-broad-lookup bug in disguise. raise MCPEventScopeError( f"Last-Event-ID {last_event_id!r} belongs to stream {id_stream!r}, " f"but reconnect targeted stream {stream_id!r}" ) buf = self._replay.get(stream_id, {}) return [buf[s] for s in sorted(buf) if s > id_seq] ```