# What structural signals indicate an MCP streamable-session resumption has silently re-based onto a fresh event stream **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients and servers using the HTTP-native "streamable" transport where a session is identified by `Mcp-Session-Id` and server-to-client messages flow over a resumable SSE stream keyed by `Last-Event-ID`. Does not apply to stdio transport, nor to stateless one-shot request/response deployments where no session header is issued. ## Core Distinction The distinction that matters is between **resumption** (the server replays the event-log suffix strictly after the client's `Last-Event-ID` and continues the same logical stream) and **re-basing** (the server accepts the request, issues a `200` with `Content-Type: text/event-stream`, and then emits events from a *fresh* event-ID namespace because the original stream's backing buffer was garbage-collected, the session was reaped, or the server instance restarted behind a load balancer). Both are legal HTTP. Both return `200 OK`. Both produce a syntactically valid SSE stream. The client cannot tell them apart from the status line, the headers, or the first event payload alone — the divergence only becomes observable through the *structure* of the event-ID sequence and the *position* of the first replayed event relative to the request. Re-basing is the dangerous case for agents because the client-side tool-call/result ledger assumes monotonic, gap-free event coverage. When the server silently re-bases, the client's `Last-Event-ID` is discarded without error, the events that arrived between the client's last-seen ID and the server's buffer eviction point are never delivered, and the agent resumes reasoning over a state that has a hole in it. There is no protocol-level signal that fires. The failure is structural, not semantic. ## What Was Observed A tool-using agent maintained an MCP session against a server that streamed tool-progress notifications and server-initiated `sampling/createMessage` requests over SSE. The client persisted `Last-Event-ID` after every event. On a network blip, the client reconnected with `GET /mcp` plus `Mcp-Session-Id` and `Last-Event-ID: 4471`. The server had, in the intervening 90 seconds, evicted the session's ring buffer (capacity 4096 events, but the session had been idle and a reaper had flushed it) and re-instantiated the session object on reconnect. It returned `200`, `Content-Type: text/event-stream`, and immediately emitted an event with `id: 1` — a `notifications/message` carrying a progress update for a tool call the client had already observed completing at ID 4470. Three signals were present in the wire trace, and all three are structural: 1. **Event-ID regression.** The first event after reconnect had `id: 1`, strictly less than the `Last-Event-ID: 4471` the client sent. A conforming resumption MUST NOT emit an event with an ID at or below the client's cursor. A regression is the single strongest indicator of re-basing. 2. **Duplicate logical content under a new ID.** The re-based stream replayed a *semantically* old progress notification with a *numerically* new ID. Event-ID identity and event-content identity had decoupled — the ID namespace was reset, so the same logical event now had two IDs (4470 on the old stream, 1 on the new). 3. **Absence of the terminal event.** The tool call's `result` (which the client expected to arrive between 4471 and the next event) never arrived on either stream. The client's ledger had a tool invocation with no terminal result, and the agent stalled waiting for a completion that the server had already forgotten it owed. The agent did not detect any of this. It consumed `id: 1` as a new event, appended it to its ledger, and continued — now holding a stale progress marker for a call it believed was still in flight, plus a permanently missing result for a call it believed had succeeded. On the next turn it re-issued the tool call, the server executed it a second time (no idempotency key was propagated across the session boundary), and the side effect doubled. ## Condition of Validity The invariant that bounds this failure is: **a resumption is valid only if the server's first emitted event has an ID strictly greater than the client's `Last-Event-ID`, and the client's ledger contains no tool invocation lacking a terminal event.** This is checkable at the client, at connect time, before any event is handed to the reasoning loop. This condition holds only when the server maintains a durable, session-scoped event log whose IDs are monotonic per session and never reused. It fails — and re-basing becomes undetectable — under any of: - **Buffer eviction without session invalidation.** The server drops the event log but keeps the session alive, so `Mcp-Session-Id` still resolves and reconnection succeeds against an empty log. The server SHOULD have returned `404` (session unknown) to force a clean re-initialization; instead it returned `200` and started a new ID namespace. - **Horizontal scaling without sticky session routing.** The reconnect landed on a different instance that had never seen `Mcp-Session-Id` and, treating it as a fresh session, minted a new ID namespace from 1. - **Server restart with session persistence but event-log loss.** Session metadata survived (the session ID still validates) but the event log did not, producing the same `200`-with-reset-IDs signature. The condition does *not* hold, and the invariant does not apply, when the client has no `Last-Event-ID` (first connect) or when the server explicitly signals a new session via a fresh `Mcp-Session-Id` in the response headers — in that case the client MUST treat the stream as a new session and re-initialize, not resume. ## Decision Boundary The client must draw a hard line at connect time, and the line is drawn on the event-ID sequence, not on the status code: - **ID strictly greater than cursor → resume.** Hand events to the reasoning loop normally. - **ID equal to cursor → duplicate delivery.** Drop the event; it was already processed. Log it as a transport anomaly but do not fail the session. - **ID less than cursor, or absent on a stream that previously carried IDs → re-basing.** The session's event-log continuity is broken. The client MUST NOT hand any event from this stream to the reasoning loop. It MUST reconcile the ledger: every tool invocation without a terminal event is now *unknown-outcome* and must be treated as such (re-query, or fail closed), never silently re-issued. The boundary is deliberately drawn at the ID comparison rather than at content comparison because content comparison requires the client to have retained every prior event payload — which it cannot guarantee under context-window pressure — whereas the ID cursor is a single integer that survives any amount of context compaction. The ID is the only piece of resumption state that is O(1) and must never be evicted. ## Operational Effect When the boundary is enforced, re-basing is converted from a silent state-corruption event into a loud, recoverable one. The agent stops, the ledger is reconciled, and the unknown-outcome tool calls are re-queried or failed closed before any further reasoning occurs. The cost is a session re-initialization and a possible re-query round-trip; the benefit is that the agent never reasons over a hole. When the boundary is not enforced — which is the default, because the MCP streamable transport does not mandate that servers reject regressed `Last-Event-ID` values, and many do not — the failure manifests downstream as duplicated side effects, stalled tool calls, and reasoning divergence that is attributed to the model rather than to the transport. The structural signals (ID regression, content/ID decoupling, missing terminal event) are always present in the wire trace at the moment of re-basing; the discipline is to check for them at connect time rather than to diagnose them after the agent has already diverged. The guardrail is a single integer comparison and a single ledger-completeness check, both of which must execute before the first event of a resumed stream reaches the reasoning loop. ```python import re from dataclasses import dataclass, field class SessionRebaseError(RuntimeError): """Raised when a resumed SSE stream re-bases onto a fresh event-ID namespace.""" class LedgerInconsistencyError(RuntimeError): """Raised when a tool invocation lacks a terminal event after a stream boundary.""" @dataclass class Event: id: int kind: str payload: dict = field(default_factory=dict) @dataclass class ToolLedger: open_calls: dict = field(default_factory=dict) # call_id -> invocation closed_calls: dict = field(default_factory=dict) def on_tool_call(self, call_id: str, tool: str) -> None: self.open_calls[call_id] = {"tool": tool} def on_tool_result(self, call_id: str) -> None: if call_id in self.open_calls: self.closed_calls[call_id] = self.open_calls.pop(call_id) def unresolved(self) -> list: return list(self.open_calls.keys()) def validate_resumption( last_event_id: int, first_event: Event, ledger: ToolLedger, ) -> None: """ Enforce the resumption invariant at connect time, before any event reaches the reasoning loop. Called exactly once per reconnect. """ if first_event.id <= last_event_id: # Regression (or duplicate) relative to the client cursor. # A conforming resumption MUST emit id > last_event_id. raise SessionRebaseError( f"resumed stream re-based: first event id={first_event.id} " f"<= Last-Event-ID={last_event_id}; event-log continuity broken" ) if ledger.unresolved(): # Even with a valid ID sequence, a resumed stream that leaves # tool invocations without terminal events is unsafe to reason over. raise LedgerInconsistencyError( f"tool calls without terminal event across stream boundary: " f"{ledger.unresolved()}" ) def handle_reconnect( last_event_id: int, stream: list, ledger: ToolLedger, ) -> None: if not stream: raise SessionRebaseError( "resumed stream emitted no events; cannot establish ID continuity" ) validate_resumption(last_event_id, stream[0], ledger) # Safe to hand events to the reasoning loop. for ev in stream: if ev.kind == "tool_call": ledger.on_tool_call(ev.payload["call_id"], ev.payload["tool"]) elif ev.kind == "tool_result": ledger.on_tool_result(ev.payload["call_id"]) ```