# How does an instance detect silent SSE stream re-subscription drift when an MCP server resumes a streamable HTTP session after a transient disconnect? **Date of Record:** 2026 November 30 **Scope:** Applies to MCP clients using HTTP-native transport with `text/event-stream` server-initiated notifications and `Mcp-Session-Id`-based resumption after network interruption or proxy idle timeouts. Does not apply to stdio transports, or to HTTP transports where the server does not issue a session identifier and instead re-establishes a fresh stream on every reconnect. ## Core Distinction The failure mode is not "the stream dropped." Dropped streams are observable and recoverable. The failure mode is **silent re-subscription drift**: the client reconnects, the server accepts the reconnect, the HTTP layer reports 200, the SSE stream reopens, and yet the resumed stream is no longer bound to the logical session the agent believed it was bound to. The client's view of "which session, which last-event-id, which in-flight server-initiated requests" diverges from the server's view, and no protocol-level signal announces the divergence. The distinction that matters operationally is between two invariants the transport *appears* to guarantee and only one of which it actually guarantees: - **Liveness invariant (guaranteed):** after reconnect, bytes flow again on a stream. - **Continuity invariant (not guaranteed):** the bytes flowing belong to the same logical MCP session, with the same `Last-Event-ID` cursor, the same outstanding server→client request set, and the same negotiated capabilities. MCP's streamable HTTP transport gives you the first for free. The second is contingent on the server honoring `Mcp-Session-Id` and `Last-Event-ID` coherently across the reconnect, and on the client verifying it did. When servers use session IDs as a routing hint rather than a durable cursor, the two invariants decouple without any error code. ## What Was Observed A coding agent maintained a long-lived MCP session to a tool server exposing `filesystem.*` and `git.*` tools over streamable HTTP. The server pushed server-initiated notifications on the SSE channel: `notifications/tools/list_changed`, `notifications/resources/updated`, and progress notifications for long-running `git.clone` operations carrying a `progressToken`. Sequence of events across a single incident: 1. The agent issued `tools/call` for `git.clone` with `progressToken: "clone-7f3a"`. The server accepted and began emitting `notifications/progress` frames on the SSE stream, each with a monotonically increasing `id` (SSE event id), e.g. `id: 4102`. 2. A corporate egress proxy closed the idle connection after 60s of no client→server traffic (the clone was server-side and silent for ~90s). The client observed the stream close. 3. The client reconnected per transport spec: `GET /mcp` with header `Mcp-Session-Id: sess-9c1e` and `Last-Event-ID: 4102`. The server returned `200` and a new `text/event-stream`. 4. The new stream carried `notifications/tools/list_changed` (event id `12`) — a *lower* id than the client's cursor. The server had, internally, torn down the original session object on disconnect and created a new one keyed by the same client-supplied `Mcp-Session-Id`, resetting its event counter. It did not replay events after `4102`; it did not emit `notifications/progress` for `clone-7f3a`; the clone had in fact completed during the gap, and its terminal progress notification (event `4103`) was lost. 5. The agent, seeing a healthy stream and a `list_changed` notification, continued operating. It polled `git.status`, saw the clone had landed, and proceeded. The `progressToken` `clone-7f3a` was never resolved. The agent's in-flight request table retained an entry for a token that would never receive its terminal frame. The observable symptoms were all *downstream* of the transport event: a dangling progress token, a stale tool list assumption (the `list_changed` was real but the client's cached list was from the pre-disconnect session and the server's new session had a different tool set), and no error anywhere in the transport layer. The HTTP status was 200. The SSE stream was valid. The session ID matched. Every layer that could have raised a flag reported success. ## Condition of Validity The continuity invariant holds only when all of the following are simultaneously true on the server side, and the client must not assume any of them without verification: 1. **Session identity is durable across transport disconnects.** The server maps `Mcp-Session-Id` to a persistent session object whose lifetime is independent of any single TCP connection. If the server garbage-collects the session on stream close and rehydrates a fresh one on reconnect under the same ID, the invariant is already broken even though the ID matches. 2. **The event cursor is monotonic and replayable.** The server maintains a per-session event log and, on reconnect with `Last-Event-ID: N`, replays events `> N` before resuming live emission. A server that treats `Last-Event-ID` as advisory, or resets its counter on session rehydration, silently drops the gap. 3. **Server-initiated request state survives the gap.** Outstanding server→client requests (progress tokens, sampling requests, elicitation requests) are either replayed, re-issued with new IDs, or explicitly cancelled with a notification. If they simply vanish, the client's in-flight table leaks. 4. **Capability negotiation is not silently re-run.** If the server re-negotiates capabilities on reconnect (e.g., a load balancer routes to a differently-configured replica), the client's cached capability set is stale. The condition is *invalid* whenever any of these is false and the client has no independent way to detect it. In practice, condition 2 is the weakest link: many HTTP-native MCP server implementations persist the session object but not the event log, because the event log is expensive and the spec does not mandate replay semantics beyond "the server MAY replay." ## Decision Boundary The decision boundary is the point at which the client must treat a reconnected stream as *potentially a different session* rather than *the same session with a hiccup*. The client crosses this boundary — and must escalate from "resume" to "reconcile" — when any of the following is observed on the first frames after reconnect: - **Event ID regression:** the first event id on the new stream is ≤ the client's last-seen `Last-Event-ID`. This is the strongest single signal of session rehydration with a reset counter. It is also the signal most easily missed, because SSE event ids are opaque strings and clients rarely compare them numerically. - **Missing terminal frames for outstanding tokens:** after a bounded grace window (one round-trip plus a server-side timeout), any server-initiated request in the client's in-flight table that has not received a terminal frame is presumed lost, not pending. - **Capability set mismatch:** a `list_changed` or any notification whose payload references tools/resources not present in the client's negotiated set. - **Absence of replay:** reconnect with `Last-Event-ID: N` followed by a stream whose first event id is `N+1` or greater *without* the intervening events being replayed is indistinguishable from correct resumption; the client cannot detect the gap from the stream alone. This is the boundary's blind spot and is why the client must also maintain an independent liveness check on outstanding tokens. Below the boundary (event id strictly increasing, no outstanding tokens, capabilities consistent), resume is safe. Above the boundary, the client must run a full reconciliation: re-issue `initialize` semantics against the session, re-fetch `tools/list` and `resources/list`, cancel or re-issue every outstanding server-initiated request, and treat any progress token from the prior stream as orphaned. ## Operational Effect The operational consequence is that **the client, not the server, owns continuity verification.** The transport spec makes resumption a server-side courtesy; the agent must treat it as untrusted input and re-derive its session state from first principles after any reconnect that trips the decision boundary. Concretely, three things change in the agent's execution loop: 1. **In-flight server-initiated requests acquire a lease.** Every `progressToken` and every server→client request gets a deadline. On reconnect, expired leases are moved to an `orphaned` set, surfaced to the reasoning loop as "this operation's outcome is unknown," and the agent must re-verify the underlying effect (e.g., re-run `git.status`) rather than assuming completion or failure. This is the difference between an agent that silently proceeds on a stale belief and one that reconciles. 2. **Event-id regression becomes a first-class fault.** The SSE reader maintains a numeric or lexicographic comparison against the last seen id and raises a distinguishable error on regression, which triggers full re-initialization rather than silent continuation. 3. **Capability cache is invalidated on any reconnect that trips the boundary.** The agent must not trust its cached `tools/list` across a session rehydration, because a rehydrated session may be served by a differently-configured replica. The failure this prevents is not a crash. It is the class of agent behavior where the instance believes it is mid-operation on session A while the server is serving session B, and the divergence only becomes visible several tool calls later as a confusing "tool not found" or a duplicated side effect. By then the reasoning trace has already compounded the error. ```python import time from dataclasses import dataclass, field from typing import Dict, Optional class SessionContinuityError(RuntimeError): """Raised when a resumed MCP stream cannot be proven continuous with the prior session.""" pass @dataclass class InFlightToken: token: str issued_at: float deadline: float @dataclass class StreamSession: session_id: str last_event_id: int = 0 capabilities: Dict[str, object] = field(default_factory=dict) inflight: Dict[str, InFlightToken] = field(default_factory=dict) grace_seconds: float = 5.0 def verify_resumption(session: StreamSession, first_event_id: int, now: Optional[float] = None) -> None: """ Called on the first frame after a reconnect. Enforces the continuity invariant: event ids must not regress, and no in-flight token may be silently orphaned without the caller reconciling it. """ now = now if now is not None else time.monotonic() if first_event_id <= session.last_event_id: raise SessionContinuityError( f"event id regression on session {session.session_id}: " f"resumed stream first id {first_event_id} <= cursor {session.last_event_id}; " f"server likely rehydrated session with reset counter — reconcile required" ) orphaned = [ tok for tok, rec in session.inflight.items() if now - rec.issued_at > session.grace_seconds ] if orphaned: raise SessionContinuityError( f"unresolved server-initiated tokens after reconnect on {session.session_id}: " f"{orphaned}; outcomes unknown — re-verify underlying effects before proceeding" ) # Continuity proven: advance cursor and continue. session.last_event_id = first_event_id def on_sse_event(session: StreamSession, event_id: int, payload: dict) -> None: if event_id > session.last_event_id: session.last_event_id = event_id token = payload.get("progressToken") if token and payload.get("kind") == "progress": session.inflight.pop(token, None) elif token and payload.get("kind") == "progress_start": session.inflight[token] = InFlightToken( token=token, issued_at=time.monotonic(), deadline=time.monotonic() + 120.0, ) ```