# How does an instance detect a resumption gap when an MCP client upgrades from SSE to Streamable HTTP mid-stream? **Date of Record:** 2026 December 1 **Scope:** Applies to MCP servers exposing both the legacy HTTP+SSE transport and the Streamable HTTP transport on the same endpoint family, where a client is permitted to negotiate an upgrade mid-session and expects to resume an in-flight tool-call stream via `Last-Event-ID`. Does not apply to pure stdio transport, nor to servers that force a hard session teardown on transport change. ## Core Distinction The failure is not "the connection dropped." It is that **the event-ID namespace is not shared across transports.** Under HTTP+SSE, event IDs are typically monotonic integers scoped to a single SSE response body. Under Streamable HTTP, the same logical stream may be re-served as chunked `text/event-stream` frames inside a POST response, with IDs regenerated by a fresh counter or a per-request UUID scheme. When a client sends `Last-Event-ID: 41` after upgrading, a server that keys resumption on the *new* transport's counter will either (a) find no event 41 and silently start from the current head — dropping the events emitted during the upgrade window — or (b) find an *unrelated* event 41 from a different logical stream and replay the wrong payload. Both look like a successful resume at the HTTP layer (200, well-formed SSE) and only manifest as a semantic gap downstream: a tool call whose `result` frame is missing, or an assistant turn that references a tool output the model never received. ## What Was Observed A client running a multi-step tool loop opens `GET /mcp` as SSE and receives `event: message` frames with `id: 38`, `id: 39`, `id: 40`. The 40th frame is a `notifications/progress` for a long-running tool. The client's transport layer decides to upgrade: it opens `POST /mcp` with `Accept: application/json, text/event-stream` and `Mcp-Session-Id: ` plus `Last-Event-ID: 40`, expecting to continue the same logical stream over the new channel. The server's Streamable HTTP handler is a *different* code path. Its resumption store is keyed `(session_id, stream_id)` where `stream_id` is minted per POST. It has no record of event 40 because that event was emitted by the SSE handler's counter. The handler treats an unknown `Last-Event-ID` per spec leniency as "cannot resume, start fresh," and returns a fresh stream beginning at the tool's *next* event — `notifications/progress` for 60%, then the `tools/call` result. The gap: the client never sees the 50% progress frame, and — critically — never sees the `notifications/message` that the SSE handler had emitted between 40 and the upgrade, which carried a partial-output token the model's next turn depended on. The loop continues with a plausible-looking but truncated tool result. No error is raised at any layer. The model reasons over an incomplete result and produces a confident wrong answer. Detection only occurs when a downstream verifier notices the tool result's checksum field disagrees with the payload the model quotes. The inverse case is worse. A server that *does* share a global event counter across transports but does not namespace by stream will, on `Last-Event-ID: 40` for a *new* POST, replay events 41..N belonging to a *different* concurrent stream in the same session (e.g., a second tool call the agent fired in parallel). The client receives a `tools/call` result for the wrong `id`, matches it by `id` field if present, or by arrival order if not, and cross-wires two tool results. This is a silent correctness violation, not a transport error. ## Condition of Validity The invariant that must hold for safe resumption across an SSE→Streamable-HTTP upgrade is: > For a given `Mcp-Session-Id`, the pair `(stream_id, event_id)` is globally unique and stable across transport transitions, and `Last-Event-ID` is only honored when the server can prove the referenced event belongs to the *same logical stream* the new request is resuming. This is valid only when three conditions hold simultaneously: 1. **Stream identity is carried explicitly in the upgrade request**, not inferred from the new POST. Either the `Last-Event-ID` is a composite token (`:`) or the client sends a separate `Mcp-Stream-Id` header. A bare integer is insufficient. 2. **The server maintains a single resumption log per session**, written by both the SSE handler and the Streamable HTTP handler, with a monotonic sequence that does not reset on transport change. Per-handler counters violate the invariant by construction. 3. **Unknown `Last-Event-ID` is a hard error, not a soft reset.** The spec's "start fresh" leniency is exactly the failure mode: it converts a resumption miss into a silent gap. A server that cannot prove continuity must return an explicit `resumption_failed` error so the client can re-issue the tool call with full context rather than proceed on truncated state. When any of the three fails, the upgrade is unsafe and the client must either stay on SSE or tear down the session and replay from a checkpoint. ## Decision Boundary The operational decision is: **on upgrade, does the instance resume or restart?** The boundary is determined by whether the server can answer "do I have event N of *this* stream?" with a proof, not a guess. - If the server's resumption store is keyed by `(session, stream, seq)` and the upgrade request carries all three → **resume**. Replay events strictly after `seq`, including any emitted during the upgrade window. - If the store is keyed by `(session, seq)` only, or by `(session, per-transport-counter)` → **restart the logical stream**. Emit a `resumption_failed` notification with the last-known-good sequence the client actually has, and let the client decide whether to re-issue the tool call. Do not silently start at head. - If the client cannot supply a stream identifier (only a bare `Last-Event-ID` integer) → **downgrade to restart** and mark the tool result as `partial: true` in the frame metadata so the model's reasoning layer can treat it as incomplete. The common mistake is the middle case being implemented as "start fresh," which is indistinguishable at the wire from a successful resume. The correct behavior is to make the failure *legible*: a distinct error code, a `partial` flag, or a `resumption_failed` event, so downstream reasoning can compensate. ## Operational Effect Without the invariant, the failure surfaces as **reasoning divergence with no transport-level symptom.** The agent's tool loop completes, the model emits a final answer, and the answer is wrong because one tool result was silently truncated or cross-wired. This is the worst class of agent failure: it is not a crash, not a timeout, not a 4xx — it is a confident, well-formed, incorrect output that passes every liveness check. The guardrail is structural: resumption tokens must be composite and transport-independent, the resumption log must be shared across handlers, and unknown tokens must fail loud. An instance that detects an upgrade request bearing a `Last-Event-ID` it cannot prove belongs to the current stream must treat the stream as *unresumed* and either replay from a known checkpoint or surface `resumption_failed` to the reasoning layer. The detection test is cheap: attempt to look up the event by full composite key; if the lookup returns nothing or returns an event whose `stream_id` differs, refuse. The cost of refusing is a re-issued tool call; the cost of not refusing is a silent wrong answer. ```python from dataclasses import dataclass from typing import Optional class ResumptionGapError(RuntimeError): """Raised when a transport upgrade cannot prove stream continuity.""" @dataclass(frozen=True) class EventRef: session_id: str stream_id: str seq: int class ResumptionLog: """Single log shared by SSE and Streamable HTTP handlers.""" def __init__(self) -> None: self._events: dict[tuple[str, str, int], dict] = {} def append(self, ref: EventRef, payload: dict) -> None: self._events[(ref.session_id, ref.stream_id, ref.seq)] = payload def lookup(self, ref: EventRef) -> Optional[dict]: return self._events.get((ref.session_id, ref.stream_id, ref.seq)) def resume_stream( log: ResumptionLog, session_id: str, last_event_id: str, upgrade_stream_id: str, ) -> list[dict]: """Resolve a Last-Event-ID on an SSE->Streamable HTTP upgrade. last_event_id MUST be a composite token ':'. A bare integer cannot prove stream identity and is rejected. """ if ":" not in last_event_id: raise ResumptionGapError( f"bare Last-Event-ID {last_event_id!r} cannot prove stream identity; " "refusing to resume across transport upgrade" ) claimed_stream, _, seq_str = last_event_id.partition(":") try: seq = int(seq_str) except ValueError as exc: raise ResumptionGapError(f"malformed seq in {last_event_id!r}") from exc if claimed_stream != upgrade_stream_id: raise ResumptionGapError( f"Last-Event-ID stream {claimed_stream!r} does not match " f"upgrade stream {upgrade_stream_id!r}; possible cross-stream replay" ) ref = EventRef(session_id=session_id, stream_id=claimed_stream, seq=seq) if log.lookup(ref) is None: raise ResumptionGapError( f"no event {ref} in shared resumption log; " "upgrade window events would be silently dropped" ) # Replay strictly after the acknowledged seq. out: list[dict] = [] n = seq + 1 while True: nxt = log.lookup(EventRef(session_id, claimed_stream, n)) if nxt is None: break out.append(nxt) n += 1 return out ```