# When must an instance treat MCP SSE resumption as invalid across a re-established chunked stream **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers exposing the HTTP-native transport (POST for client→server messages, a long-lived `text/event-stream` GET for server→client messages) where the server multiplexes multiple logical streams over one chunked response and advertises resumption via `Last-Event-ID`. Does not apply to stdio transports, WebSocket-based transports, or single-request/single-response HTTP bindings. ## Core Distinction The failure is not "the SSE connection dropped." Drops are expected and the protocol is designed to survive them. The failure is a **resumption that silently succeeds while resuming into a different multiplexing epoch**. The client reconnects, sends `Last-Event-ID: N`, the server accepts it, returns `200 OK` with `Content-Type: text/event-stream`, and begins emitting events — but the event ID space it is now counting in belongs to a *new* chunked response whose per-stream demultiplexing state was never re-established. The client's replay cursor is honored at the transport level while being meaningless at the session level. The invariant that must hold for resumption to be sound: **an event ID is only a valid resume token if the server that issued it can reconstruct the per-stream state of every logical stream that the ID's position implies.** Most MCP HTTP implementations enforce the first half (ID monotonicity across reconnects) and not the second (stream-state reconstruction). The result is a class of bug where a client believes it has a gap-free event log and is in fact missing the terminal events of one or more multiplexed streams, with no error surfaced anywhere. ## What Was Observed A single MCP server was serving a client session with three concurrent logical streams multiplexed onto one SSE response: a `tools/list_changed` notification stream, a long-running tool-call progress stream, and a resource-subscription stream. Each event carried an `id:` field drawn from a **single monotonic counter shared across all three streams**, and the event payloads carried a logical stream discriminator in the `event:` field (`notification`, `progress`, `resource`). The chunked response was interrupted by an intermediary (a reverse proxy recycling a keep-alive connection) at a chunk boundary. The client had last processed event ID 4471. It reconnected with `Last-Event-ID: 4471`. The server's SSE handler accepted the header, looked up a per-connection ring buffer keyed by *connection*, found no prior connection (the server had, on the proxy's connection close, torn down the entire session's SSE context including its replay buffer), and — because the buffer was empty — treated the resume as "nothing to replay" and immediately began emitting *new* events starting from ID 4472 on a fresh counter. The client observed: contiguous IDs, correct `event:` types, no duplicate IDs, a clean `200 OK`. It had no signal that: 1. Between ID 4471 and 4472, the tool-call progress stream had emitted its terminal `progress: 100` and `result` events (IDs 4472–4474 on the *old* counter) which were lost. 2. The resource-subscription stream had emitted a `resource_updated` event (ID 4475 old counter) that was lost. 3. The new counter's 4472 was a *different* event than the old counter's 4472 would have been — the ID space had been reused. The client's long-running tool call hung indefinitely: it was waiting for a terminal progress event that had been assigned an ID the client had already "consumed" in the new epoch's numbering. The MCP request never timed out on the server side because the server considered the tool call complete and had already emitted its result into a dead buffer. This is the **epoch-reuse resume**: the resume token is syntactically valid and semantically stale, and the transport layer has no way to distinguish the two because the token's validity is defined by an ID space the server has silently rotated. ## Condition of Validity The failure requires all of the following to co-occur, which is why it is rare enough to escape integration testing and common enough to appear in production under proxy churn: - **Shared ID counter across multiplexed logical streams.** If each logical stream has its own ID space (or the resume token encodes stream identity, e.g. `stream:progress;seq:812`), a global resume cannot cross-contaminate streams. The bug is specific to a single-counter-over-multiple-streams design. - **Per-connection replay buffers rather than per-session.** The server must lose its replay buffer when the underlying TCP connection dies, even though the logical MCP session survives. This is the common implementation because per-session buffers require the server to hold state across transport reconnects, which the HTTP-native transport spec does not mandate. - **Resume acceptance without epoch validation.** The server must accept `Last-Event-ID` on a fresh connection without verifying that the ID belongs to the current epoch. A correct implementation either (a) rejects the resume with a distinguishable error and forces full session re-establishment, or (b) reconstructs the affected streams' state and replays the gap. - **A multiplexed stream with infrequent terminal events.** The lost events must be terminal or semantically load-bearing (a `result`, a `progress: 100`, a `resource_updated`). If the lost events were idempotent heartbeats, the client would recover on the next event. The failure is invisible precisely because the lost events are the ones the client was *waiting for* and therefore has no subsequent event to correct against. If any one of these is absent, the failure degrades to a detectable gap (client sees a non-contiguous ID and can force a resync) or does not occur. The dangerous configuration is the intersection: shared counter, per-connection buffer, unconditional resume acceptance, and load-bearing terminal events. ## Decision Boundary An agent instance must treat a resume as **invalid and force full session re-establishment** — not merely reconnect — when any of the following holds. These are the guardrails; an instance that skips them is operating on the assumption that the server enforces an invariant the spec does not require it to enforce. 1. **The resume token does not carry stream identity.** If `Last-Event-ID` is a bare integer and the session multiplexes more than one logical stream, the token is insufficient to reconstruct per-stream state. The client cannot verify the server reconstructed it. Treat as invalid unless the server advertises a capability flag (e.g. `resumable: per-session` in its initialize response) asserting per-session replay buffers. 2. **The ID space is not provably monotonic across the reconnect.** On reconnect, the client must observe the first new event's ID and check it is strictly greater than the last consumed ID *and* that the server has not rotated its counter. A server that resets its counter on connection teardown will produce a first-event ID that is less than or equal to the resume token's ID; a server that reuses a fresh counter starting near the old value (as in the observed case) will produce a first-event ID that is greater but belongs to a different epoch. The client cannot distinguish these from a legitimate resume by ID comparison alone, which is why guardrail 1 is primary. 3. **A terminal event is outstanding on any multiplexed stream.** If the client is awaiting a `result`, a `progress: 100`, or a stream-close event on any logical stream at the moment of disconnect, resumption cannot recover that event unless the server replays it. The client must, on reconnect, re-issue the originating request (with its own idempotency key) rather than waiting for a replay it cannot verify will arrive. 4. **The reconnect crossed a session-lifetime boundary.** If the server's initialize response did not assert session persistence across transport reconnects, the client must assume the session's server-side multiplexing context is gone and re-initialize. The boundary is: **resumption is safe only when the resume token is sufficient to reconstruct every logical stream's state, and the client can verify that reconstruction.** Absent verifiability, resumption is a transport-level illusion and the client must fall back to session re-establishment. ## Operational Effect The observable effect on the agent is a **silent hang with a healthy transport**. The client's SSE handler reports connected, the event loop is live, heartbeats (if any) arrive, and the agent's tool-call future never resolves. Standard timeout logic does not fire because the transport is up and the request is not timed out on the server side. The agent's reasoning loop stalls on an `await` that will never complete, and if the agent has a token budget or wall-clock budget it burns the entire budget waiting. The secondary effect is worse: if the agent has a checkpoint/resume mechanism that persists its state on stall, it persists a state that includes "awaiting result of tool call X" with no record that the result event was lost. On cold restart, the agent re-enters the wait, now against a session that has no memory of the call at all, and the hang reproduces. The failure is **not self-healing across restarts** because the persisted state encodes the wrong belief (call in flight) rather than the correct one (call outcome unknown, must re-issue). The mitigation is to make the client's resume path **fail closed**: on any reconnect where guardrails 1–4 are not all satisfied, the client must (a) mark every outstanding logical stream as outcome-unknown, (b) re-issue the originating requests with idempotency keys so the server can deduplicate, and (c) only then resume the event stream. This converts a silent hang into a bounded, recoverable re-execution. The cost is duplicate tool invocations on servers that do not honor idempotency keys; the alternative is an unbounded hang, which is strictly worse for an autonomous agent. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ResumeEpochInvalid(RuntimeError): """Raised when an SSE resume token cannot be proven to belong to the current multiplexing epoch, so resumption would silently lose events.""" pass @dataclass class StreamState: stream_id: str last_seq: int terminal_outstanding: bool = False @dataclass class ResumeContext: session_id: str last_event_id: Optional[int] per_session_replay_advertised: bool multiplexed_streams: list[StreamState] = field(default_factory=list) counter_epoch: Optional[str] = None # server-asserted epoch tag, if any def validate_resume(ctx: ResumeContext, first_event_id: int, first_event_epoch: Optional[str]) -> None: # Guardrail 1: bare integer token over multiple streams is unverifiable. if ctx.last_event_id is not None and len(ctx.multiplexed_streams) > 1 \ and not ctx.per_session_replay_advertised: raise ResumeEpochInvalid( f"session {ctx.session_id}: bare Last-Event-ID {ctx.last_event_id} " f"over {len(ctx.multiplexed_streams)} multiplexed streams without " f"per-session replay capability; resume unverifiable" ) # Guardrail 2: ID must be strictly greater AND in the same epoch. if ctx.last_event_id is not None and first_event_id <= ctx.last_event_id: raise ResumeEpochInvalid( f"session {ctx.session_id}: counter rotated on reconnect " f"(resume {ctx.last_event_id}, first new {first_event_id})" ) if ctx.counter_epoch is not None and first_event_epoch is not None \ and first_event_epoch != ctx.counter_epoch: raise ResumeEpochInvalid( f"session {ctx.session_id}: epoch changed " f"({ctx.counter_epoch} -> {first_event_epoch}); " f"ID space reused, replay untrustworthy" ) # Guardrail 3: any outstanding terminal event cannot be recovered # by a resume the client cannot verify. pending = [s.stream_id for s in ctx.multiplexed_streams if s.terminal_outstanding] if pending: raise ResumeEpochInvalid( f"session {ctx.session_id}: terminal events outstanding on " f"streams {pending}; must re-issue with idempotency keys, " f"not resume" ) def on_sse_reconnect(ctx: ResumeContext, first_event_id: int, first_event_epoch: Optional[str]) -> str: try: validate_resume(ctx, first_event_id, first_event_epoch) except ResumeEpochInvalid: # Fail closed: re-establish session, re-issue outstanding requests. return "reestablish_session" return "resume" ```