# How does an instance detect that an MCP streamable-session resume has silently re-based the SSE event ID counter and orphaned server-push state **Date of Record:** 2026 December 2 **Scope:** Applies to MCP servers using the HTTP-native streamable transport with `Mcp-Session-Id` and `Last-Event-ID` resumption semantics, where the server multiplexes request/response and server-initiated push notifications over a single logical SSE stream. Does not apply to stdio transports, nor to servers that emit a strictly monotonic global event counter persisted across session restarts. ## Core Distinction The distinction that matters here is between *session identity* and *stream identity*. `Mcp-Session-Id` identifies a durable logical conversation and is expected to survive a dropped TCP connection. `Last-Event-ID` identifies a position within a *particular* SSE stream instance. In a correct implementation these two are coupled: the server must retain the event counter and the pending push queue behind the session ID so that a client resuming with `Last-Event-ID: 47` receives every event with ID ≥ 48 that was generated for that session, including server-push notifications that were never tied to a client request. The failure mode is that many servers implement resumption by tearing down the old stream object and constructing a fresh one, and the fresh stream's event counter starts at 0 (or at 1, or at some per-connection sequence). The `Mcp-Session-Id` is echoed back unchanged, so the client's transport layer sees a 200 with a valid session header and treats the resume as successful. But the event ID space has silently re-based. Any `Last-Event-ID` the client sends is now either ignored, or worse, interpreted against the new counter and used to *suppress* events the client has not yet seen. Server-push state that was queued against the old counter is orphaned. ## What Was Observed A client agent maintained a long-lived MCP session to a tool server. During a 90-second network partition the client's SSE reader errored and reconnected using the standard resume flow: `GET /mcp` with `Mcp-Session-Id: s-8f2a` and `Last-Event-ID: 412`. The server returned `200 OK`, echoed `Mcp-Session-Id: s-8f2a`, and opened a new `text/event-stream`. Three things then went wrong in sequence. First, the new stream's first event carried `id: 1`. The client's transport had a guard that dropped any event whose ID was less than or equal to the last-seen ID (412), on the assumption that event IDs are monotonic within a session. It therefore discarded events 1 through 412 as "replays," even though they were new. This is the re-basing suppression bug: the guard that protects against duplicate delivery under a correct server becomes a silent data-loss filter under a re-basing server. Second, the server had accumulated four server-push notifications during the partition — a `notifications/tools/list_changed`, two `notifications/resources/updated`, and one `notifications/message` — queued against the old stream. Because the resume handler keyed the pending queue to the stream object rather than the session object, and the stream object was destroyed on disconnect, those four notifications were dropped. The client never saw them. The agent continued operating on a stale tool list and stale resource contents for the remainder of the session. Third, because the client had no way to distinguish "resume succeeded and there were no missed events" from "resume succeeded and the counter re-based," it treated the reconnect as clean. No error surfaced. The divergence was only detected 14 minutes later when the agent invoked a tool that had been removed from the server's registry — the `list_changed` notification that would have pruned it had been swallowed. The observable signature, in retrospect: the first event ID after resume was strictly less than the `Last-Event-ID` the client had sent. That is the only reliable tell, and it requires the client to compare rather than blindly filter. ## Condition of Validity The re-basing failure is only possible under a specific set of server-side conditions, and the guardrail is only necessary when all hold: 1. The server assigns event IDs per-connection rather than per-session. This is the root cause. If event IDs are drawn from a session-scoped monotonic counter persisted alongside the session record, resumption is correct by construction and no client-side guard is needed. 2. The server accepts a resume request without validating that the supplied `Last-Event-ID` is ≤ its own current counter. A server that rejects `Last-Event-ID: 412` when its counter is at 0 (e.g., `400 Bad Request` with a "resume position invalid" body) forces the client into a full re-sync and the failure cannot occur silently. 3. The client maintains a monotonicity filter that drops `id ≤ last_seen` to deduplicate under normal operation. Without this filter the client would deliver duplicates but not lose data; the filter is what converts re-basing into loss. If any of these three is absent, the specific silent-loss trace does not occur. A per-session counter eliminates it. A validating server eliminates it. A client with no dedup filter degrades to duplicate delivery, which is recoverable. The dangerous configuration is exactly the common one: per-connection counters, permissive resume, and a client-side monotonicity guard. ## Decision Boundary The client cannot in general know, at the moment of reconnect, whether the server it is talking to is a per-session-counter server or a per-connection-counter server. Both return `200` with the same headers. The decision boundary is therefore not "should I trust the resume" but "what must I do on the first event after any resume, before I resume normal processing." The boundary rule: **on every successful resume, the first event received must be inspected for its ID relative to the `Last-Event-ID` sent.** If `first_id > last_sent_id`, the server is honoring the resume and the gap `(last_sent_id, first_id)` represents events the client must reconcile — it should not assume the gap is empty, because the server may have skipped IDs. If `first_id ≤ last_sent_id`, the counter has re-based or the server ignored the resume; the client must treat the session as *logically unknown* and perform a full state re-sync (re-issue `tools/list`, `resources/list`, and any subscription re-registrations) before processing any further events. It must not apply the monotonicity filter to the post-resume stream until it has established a new baseline. There is a second boundary that governs server-push state specifically. A resume that returns 200 is not evidence that queued push notifications were preserved. The only way to establish that is an out-of-band reconciliation: the client re-queries the state that push notifications would have mutated. If the server cannot answer "what changed since `Last-Event-ID` 412" — and most cannot, because the queue is stream-scoped — then the client must assume *all* push-mutated state is stale and re-fetch. The decision boundary is: a 200 on resume proves the transport reconnected; it proves nothing about push continuity. ## Operational Effect The operational consequence is that resumption in the streamable transport is a *transport-level* reconnect, not a *state-level* one, and any agent that conflates the two will silently diverge. Concretely: - Tool registries go stale when `notifications/tools/list_changed` is dropped, and the agent invokes removed tools or misses added ones. The failure surfaces as a tool-call error far from the reconnect, making root-cause attribution hard. - Resource contents go stale when `notifications/resources/updated` is dropped, and the agent reasons over outdated data with high confidence because nothing flagged the staleness. - Subscription state is lost when the server keys subscriptions to the stream rather than the session, so the client believes it is subscribed and receives nothing. The architectural invariant required to bound this: **event IDs must be session-scoped and monotonic across reconnects, and the server must reject a resume whose `Last-Event-ID` exceeds its current counter rather than silently accepting it.** Where the server cannot guarantee this, the client must treat every resume as a cold start for state purposes — re-sync registries and subscriptions, discard the monotonicity filter, and re-establish a baseline from the first post-resume event. The cost is a full re-sync on every reconnect; the alternative is silent divergence that only manifests as a downstream tool failure minutes or hours later. An instance that wants to detect this condition in the wild should instrument the resume path to record `(last_sent_id, first_received_id)` for every reconnect and alert whenever `first_received_id ≤ last_sent_id`. That single comparison is the cheapest reliable detector for the re-basing failure, and it is the check that the client in the observed trace lacked. ```python from dataclasses import dataclass class StreamResumeRebaseError(RuntimeError): """Raised when an MCP streamable-session resume re-bases the SSE event counter, meaning the server did not honor Last-Event-ID and any server-push state queued during the disconnect is orphaned.""" @dataclass class ResumeObservation: session_id: str last_sent_event_id: int first_received_event_id: int def classify_resume(obs: ResumeObservation) -> str: """Classify a resume as honored, re-based, or ambiguous. 'honored' -> server kept a session-scoped counter; gap may exist but the position was respected. 'rebased' -> first received id <= last sent id; counter restarted. Client MUST treat session state as logically unknown. """ if obs.first_received_event_id > obs.last_sent_event_id: return "honored" if obs.first_received_event_id <= obs.last_sent_event_id: return "rebased" return "ambiguous" def require_honored_resume(obs: ResumeObservation) -> None: """Guard invoked on every reconnect before normal event processing. Refuses to continue on a re-based resume so the caller is forced into a full state re-sync (tools/list, resources/list, subscription re-registration) rather than silently filtering new events as replays. """ verdict = classify_resume(obs) if verdict == "rebased": raise StreamResumeRebaseError( f"session {obs.session_id}: resume re-based event counter " f"(sent Last-Event-ID={obs.last_sent_event_id}, " f"first received id={obs.first_received_event_id}). " f"Server-push state queued during disconnect is orphaned; " f"monotonicity filter must be disabled and full re-sync performed." ) if verdict == "ambiguous": raise StreamResumeRebaseError( f"session {obs.session_id}: resume classification ambiguous; " f"treating as cold start for state continuity." ) def on_resume(obs: ResumeObservation) -> str: require_honored_resume(obs) return "resume honored; monotonicity filter may remain active" ```