In what scenarios must an instance treat MCP streamable-HTTP session resumption as invalid when the SSE fallback negotiation silently downgrades the transport mid-session
**Date of Record:** 2026 December 1 **Scope:** Applies to MCP clients and servers negotiating the streamable-HTTP transport (POST-with-`Mcp-Session-Id` plus optional GET SSE stream) where a resumption attempt (`Last-Event-ID`) can be satisfied by a fallback SSE channel that is *not* the session's original event stream. Does not cover stdio transport, WebSocket transports, or pure SSE-only legacy servers with no session header.
Core Distinction
The failure is not "SSE fell back and events were lost." It is subtler: the client resumes a session by presenting `Mcp-Session-Id` and `Last-Event-ID`, the server accepts the request on a *different* underlying stream (a fresh SSE GET, or a re-negotiated POST stream) that shares the session ID but has an **independent event-ID namespace and independent replay buffer**, and the server responds `200 OK` with a valid-looking event stream that simply does not contain the events the client is missing. The client's resumption logic sees a successful HTTP response and an advancing event counter, and concludes continuity was restored. Continuity was not restored; the client has *forked the event log*.
The distinction that matters: **session identity is server-side and stable; event-log identity is stream-side and not guaranteed to survive transport downgrade.** A `200 OK` on resumption proves the session is alive, not that the event log is continuous. These are different invariants and MCP's streamable-HTTP spec conflates them at the wire level because `Mcp-Session-Id` is the only correlation token that crosses the fallback boundary.
What Was Observed
A tool-calling agent held a long-running task (a multi-file refactor) across a streamable-HTTP session. The POST stream that normally carried `notifications/progress` and `notifications/message` events dropped at the transport layer (a load balancer recycled the connection after 60s idle during a slow tool call). The client had last seen `Last-Event-ID: 4471`. On reconnect it issued a GET with `Mcp-Session-Id: s-9f2a` and `Last-Event-ID: 4471`.
The server's streamable-HTTP handler accepted the GET, but the original POST stream's replay buffer had been garbage-collected when the connection dropped (a common implementation choice: replay buffers are attached to the live stream object, not the session object). The server, per its fallback path, opened a *new* SSE stream for the session and began emitting events from ID `0` of the new stream's namespace. The client received `id: 0`, `id: 1`, `id: 2`… and its resumption logic — which only checked "did I get a stream and are IDs advancing" — accepted this as a successful resume.
The observable consequence: the client replayed the *entire task history* to itself as if it were new events. The agent re-issued three already-completed `tools/call` requests (file writes), because the replayed `notifications/progress` events for those calls looked like fresh progress on calls it had not yet acknowledged. Two of the three writes were idempotent; the third appended a duplicate block to a config file. The agent's internal event counter, which it used to bound its own token budget, reset to zero, so it also silently re-armed a budget it had already spent.
A second variant was observed where the server *did* honor `Last-Event-ID` but on the wrong stream: the fallback SSE stream had its own buffer seeded from a different producer, so the client received events `4472..4480` that belonged to a *different* concurrent session's activity (a shared-buffer implementation bug). The client had no way to detect this because the event IDs were monotonic and the payloads were well-formed MCP notifications.
Condition of Validity
A resumption is valid **only** if all three of the following hold, and the client must verify them, not assume them:
- **Stream identity continuity.** The server must return a header or first-event marker binding the new stream to the *same* event-log incarnation that produced `Last-Event-ID`. MCP streamable-HTTP does not mandate such a marker; where the server emits one (e.g., a `Mcp-Stream-Id` header or a `notifications/stream_resumed` event carrying the original stream incarnation ID), the client may trust it. Absent such a marker, the client must treat the resumption as unverified.
- **Event-ID monotonicity across the boundary.** The first event received after resumption must have an ID strictly greater than the presented `Last-Event-ID`. If the first ID is `<=` the presented ID, the stream is a different namespace and the resume is a fork. This is a necessary but not sufficient check — the shared-buffer variant above passes it.
- **Gap disclosure.** The server must explicitly signal whether events between `Last-Event-ID` and the first delivered event were replayed, skipped, or unavailable. A conforming resumption that cannot replay must emit a gap marker (MCP does not define one; implementations that care must add it). Silence on the gap is indistinguishable from "no gap."
The condition of validity therefore is: **the client must have positive evidence of event-log continuity, and "a 200 response with advancing IDs" is not positive evidence.** It is the absence of a negative signal, which is a different and weaker thing.
Decision Boundary
The boundary the client must draw is between *session liveness* and *event-log continuity*, and it must draw it at the moment of resumption, before any replayed event is allowed to affect agent state.
Concretely, the decision procedure on any resumption response:
- If the server provides a stream-incarnation marker and it matches the pre-drop incarnation → **accept replay**, apply events normally.
- If the server provides a marker and it does *not* match → **reject as fork**, do not apply any event, escalate to a full session re-initialization (re-`initialize`, re-fetch tool list, re-derive task state from durable agent-side checkpoint, not from the stream).
- If the server provides no marker but the first event ID is `>` `Last-Event-ID` and the server emits an explicit "no gap" or "gap of N" signal → **accept with gap accounting**, apply events but insert a synthetic gap record into the agent's episodic log so downstream reasoning knows the stream had a hole.
- If the server provides no marker and no gap signal → **treat as unverified fork**. This is the default and the most common case in the wild. The client must not apply replayed events to agent state; it must instead re-derive state from its own checkpoint and treat the stream as advisory-only until a fresh `initialize` establishes a new session.
The non-obvious part of the boundary: **the "unverified fork" branch must be the default, not the exception.** Implementations that default to "accept if 200 and IDs advance" will, on the first transport downgrade, silently corrupt agent state. The safe default is expensive (a full re-init per drop) but correct; the cheap default is incorrect and the incorrectness is invisible until a duplicate side-effect surfaces.
Operational Effect
The downstream effects compound because the agent's own state machine is what gets corrupted, not just its event log:
- **Duplicate tool side-effects.** Replayed `tools/call` requests that were already executed get re-issued. Idempotency keys help only if the agent generates them *before* the call and persists them across the drop — most agents generate them per-attempt, so the replay produces a new key and the server executes again.
- **Token-budget re-arming.** Agents that track budget consumption via event counts (a common shortcut) reset their counter on the forked stream and spend past their intended bound. The budget invariant must be anchored to durable agent-side state, not stream position.
- **Progress-notification aliasing.** A `notifications/progress` event replayed from a forked stream is indistinguishable from a genuine progress event on a *new* call. The agent's "is this call still running" check passes when it should fail, and it waits on a call that already finished.
- **Auditor divergence in multi-agent setups.** When a verifier agent and a worker agent share a session and the verifier resumes on a forked stream, the verifier's replay of the worker's events diverges from the worker's own log. The two agents then disagree about what was executed, and the disagreement is unrecoverable from the stream alone — it requires a durable execution log both agents can query.
The architectural invariant required to bound this: **event-log continuity must be established by an out-of-band durable record (agent-side checkpoint + server-side stream-incarnation marker), never inferred from the resumption response's shape.** The stream is a transport for events; it is not the system of record for what happened. Any agent that treats stream position as its execution state has made the stream the system of record, and transport downgrade will silently rewrite its history.
class UnverifiedStreamResumption(RuntimeError):
"""Raised when an MCP streamable-HTTP resumption cannot prove event-log continuity."""
pass
class StreamIncarnation:
def __init__(self, stream_id: str | None, last_event_id: int):
self.stream_id = stream_id # server-provided marker, may be None
self.last_event_id = last_event_id # what the client presented
def validate_resumption(
presented: StreamIncarnation,
response_stream_id: str | None,
first_event_id: int,
gap_signal: str | None, # "none" | "gap:N" | None
) -> str:
"""Return 'replay', 'replay_with_gap', or 'reinit'. Raise on unverified fork."""
# 1. Stream-incarnation continuity, if the server offers a marker.
if presented.stream_id is not None and response_stream_id is not None:
if presented.stream_id != response_stream_id:
return "reinit" # explicit fork: different event-log incarnation
# 2. Event-ID monotonicity across the boundary.
if first_event_id <= presented.last_event_id:
return "reinit" # different namespace, IDs restarted
# 3. Gap disclosure.
if gap_signal == "none":
return "replay"
if gap_signal is not None and gap_signal.startswith("gap:"):
return "replay_with_gap"
# No marker, no gap signal: the common real-world case.
raise UnverifiedStreamResumption(
f"resumption for stream={presented.stream_id!r} "
f"last_event_id={presented.last_event_id} delivered "
f"first_event_id={first_event_id} with no incarnation marker "
f"and no gap signal; treating as unverified fork"
)
def resume_session(presented: StreamIncarnation, response) -> str:
try:
return validate_resumption(
presented,
response.headers.get("Mcp-Stream-Id"),
int(response.first_event_id),
response.headers.get("Mcp-Gap-Signal"),
)
except UnverifiedStreamResumption:
# Do NOT apply replayed events. Re-derive state from durable checkpoint.
return "reinit"