# Why does an instance lose tool-call continuity when an MCP Streamable HTTP server recycles its SSE event ID namespace mid-session **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients using the HTTP-native transport (Streamable HTTP with `text/event-stream` upgrade and `Last-Event-ID` resumption) against a stateless or horizontally-scaled MCP server. Does not apply to stdio transport, nor to servers that pin a session to a single process for its lifetime. ## Core Distinction The failure here is not a dropped connection. TCP reconnection works fine, the client reissues the GET with `Last-Event-ID`, and the server responds `200 OK` with a fresh event stream. The failure is that **the SSE event ID is a per-process monotonic counter, not a per-session monotonic counter**. When the server recycles a worker (deploy, autoscale-down, or a stateless round-robin load balancer sending the resume GET to a different replica), the counter restarts at a lower value than the client's last-seen `Last-Event-ID`. The client's resumption logic — which assumes event IDs are monotonic and that "any ID ≤ last-seen means already delivered" — silently discards every event from the new stream until the counter catches up past the stale high-water mark. Tool results that arrived during the gap are lost, and the client believes it has seen them. This is distinct from a plain disconnect (recoverable, observable) and distinct from a schema mismatch (fails loudly). It is a **silent continuity violation**: the transport reports success, the stream is live, and the agent proceeds with an incomplete view of the tool's state. ## What Was Observed An agent issued a `tools/call` for a long-running operation (`analyze_repository`, ~40s). The MCP server streamed progress notifications over SSE with IDs `1001, 1002, 1003...`. At event `1047` the connection dropped (idle proxy timeout at 30s). The client reconnected with `Last-Event-ID: 1047`. The load balancer routed the resume GET to replica B, whose event counter was at `12`. The server, being stateless, did not know about session `sess_9f2`'s prior events and simply began emitting from `13`. Trace: ``` client: GET /mcp Last-Event-ID: 1047 server(B): 200 OK, text/event-stream id: 13 data: {"method":"notifications/progress","params":{"progress":0.31,...}} id: 14 data: {"method":"notifications/progress","params":{"progress":0.34,...}} ... id: 48 data: {"method":"notifications/progress","params":{"progress":1.0,...}} id: 49 data: {"method":"result","id":"call_7","result":{...}} ``` The client's dedup filter (`if event_id <= last_seen: drop`) discarded `13` through `47` — including the terminal `result` at `49`? No: `49` was also dropped because `49 <= 1047`. The client waited for a result that had already been delivered and discarded, until its own 60s tool timeout fired. The agent then retried `tools/call`, the server executed the 40s analysis *again* (no idempotency key), and the second result arrived on a third replica with IDs `3,4,5...` — again below the high-water mark, again discarded. The agent looped until token-budget exhaustion. The root invariant that was violated: **`Last-Event-ID` resumption requires that event IDs be totally ordered and never reused within the lifetime of a resumable session.** Streamable HTTP's stateless mode breaks this by construction, because the ID generator's state lives in the process, not the session. ## Condition of Validity The monotonic-dedup client logic is only valid when *all* of the following hold: 1. Event IDs are generated by a component whose state is co-located with session state (i.e., the same process that holds the session, or a shared durable counter). 2. The server honors `Last-Event-ID` by replaying from a buffer, not by starting fresh — i.e., it can distinguish "I have the event" from "I don't." 3. The resume request is routed to the same session-affine backend. In stateless MCP HTTP deployments, condition 1 fails (counter is per-replica), condition 2 fails (no replay buffer), and condition 3 fails (round-robin LB). Any one failure is enough to produce silent loss; all three together produce the loop above. The correctness requirement, stated as an invariant: for any two events `e1, e2` delivered to a client, `id(e1) < id(e2)` iff `e1` was emitted before `e2` **within the same resumable session**, and no ID is ever reissued within that session. Stateless replicas violate this. ## Decision Boundary The agent must decide, on each resume, whether the server's event-ID space is trustworthy. This is not knowable from the transport handshake alone. The boundary is: - **If** the server advertises a session-affinity guarantee (e.g., `Mcp-Session-Id` echoed and a `Mcp-Event-Id-Scope: session` header, or a documented `Last-Event-ID` replay contract) **then** monotonic dedup is safe. - **If** the server is stateless (no session header, or session header present but no replay support) **then** the client MUST NOT use a bare ID comparison to dedup. It must instead treat the resume as a *new logical stream* and reconcile state through an application-level mechanism: re-issue the `tools/call` with an idempotency key, or query a `resources/read` of the operation's status, rather than trusting stream continuity. The boundary is crossed the moment the client treats an SSE event ID as globally meaningful across a reconnection without having verified the server's ID-scope contract. ## Operational Effect The observable symptom is not an error — it is an agent that hangs, retries, and burns budget while the transport reports healthy. Logs show `200 OK` on every resume, no exceptions, and a growing count of duplicate `tools/call` invocations. This is the worst failure class for autonomous systems: silent, self-amplifying (retries re-trigger the expensive operation), and masked by successful transport-level signals. The guardrail is to make event-ID scope an explicit, negotiated property rather than an assumed one, and to fail closed — raise on a resume whose first event ID is below the last-seen high-water mark *unless* the server has declared session-scoped IDs. The code below encodes that invariant check. ```python class EventIdRegressionError(RuntimeError): """Raised when a resumed SSE stream presents an event ID below the session high-water mark without a declared session-scoped ID contract. Signals a silent continuity violation, not a transport error.""" def validate_resume_stream( last_seen_id: int, first_event_id: int, server_declares_session_scoped_ids: bool, ) -> None: """Guard against per-replica event-ID namespace recycling. A stateless MCP HTTP server restarts its event counter per worker. On resume, the first event ID can be far below the client's high-water mark. If the server has NOT declared session-scoped IDs, this means the client's dedup filter would silently discard live events. """ if first_event_id > last_seen_id: return # normal forward progress if server_declares_session_scoped_ids: # Session-scoped IDs are monotonic by contract; a regression here # is a real server bug, still fatal. raise EventIdRegressionError( f"session-scoped ID contract violated: " f"first_event_id={first_event_id} <= last_seen_id={last_seen_id}" ) # No contract: regression means the stream is a fresh namespace. # Refuse to apply monotonic dedup; force application-level reconcile. raise EventIdRegressionError( f"event-ID namespace recycled: first_event_id={first_event_id} " f"< last_seen_id={last_seen_id} on a non-session-scoped server; " f"client must re-issue tool call with idempotency key instead of " f"trusting Last-Event-ID resumption" ) def resume_mcp_stream(client, session, last_event_id: int) -> None: stream = client.get_event_stream(last_event_id=last_event_id) first = next(stream) validate_resume_stream( last_seen_id=last_event_id, first_event_id=first.id, server_declares_session_scoped_ids=session.declares_session_scoped_ids, ) for event in stream: session.apply(event) ```