# How should an instance reconcile Last-Event-ID resumption against MCP streamable session state after a transport-level reconnect? **Date of Record:** 2026 December 2 **Scope:** Applies to MCP clients and servers using the HTTP-native "streamable" transport where a single logical session multiplexes SSE event streams and request/response POSTs across reconnects. Does not apply to stdio transports or to stateless one-shot MCP endpoints with no session identity. ## Core Distinction The transport layer and the MCP session layer both claim to own "continuity," and they disagree about what continuity means. The SSE transport layer owns *byte-level event continuity*: it exposes `Last-Event-ID`, and a compliant server replays events with IDs strictly greater than the supplied value on that specific stream. It guarantees nothing about *semantics*—an event replayed is an event re-emitted, whether or not its effect was already applied by the client, and whether or not the underlying session state that produced it still exists. The MCP session layer owns *semantic continuity*: the `Mcp-Session-Id` header pins a server-side session object holding tool registrations, in-flight request state, resource subscriptions, and server-side cursor positions. This object has its own lifecycle, expiry, and eviction policy that is completely decoupled from the SSE event-ID space. The boundary failure occurs when a client treats a successful SSE reconnection (HTTP 200, stream reopened, events flowing) as proof that the MCP session survived. These are independent facts. A server can accept the TCP/SSE reconnect, replay buffered events from an in-memory ring buffer, and *still* have discarded the session object—because the session store is a different subsystem with a different TTL. The client then resumes issuing tool calls against a session that the server has silently re-created empty, or worse, re-created with the same ID but default state. ## What Was Observed A client agent held a long-running session: it had registered a resource subscription, was mid-way through a multi-tool workflow, and maintained a server-side pagination cursor returned by a previous `tools/list` with a continuation token. The network dropped. The client's SSE reconnect logic fired: 1. Client reconnects with `GET /mcp` carrying `Mcp-Session-Id: S` and `Last-Event-ID: 4471`. 2. Server's SSE layer finds event 4471 in the per-connection buffer, replays events 4472–4479, returns HTTP 200, and the stream stays open. 3. The client observes a healthy stream and concludes "session resumed." But between the drop and the reconnect, ~90 seconds elapsed. The session store had a 60-second idle eviction keyed on *last POST activity*, not last SSE activity. The session object `S` was gone. The SSE replay buffer was keyed on the *connection*, not the session, and had not been cleaned up because the connection's cleanup path ran asynchronously and had not yet fired. The result: the client's next `tools/call` POST with `Mcp-Session-Id: S` was accepted by a server that lazily re-created session `S` as a fresh, empty session. The call referenced a tool that had been registered in the *old* session's dynamic tool set—the new session's registry did not contain it. The server returned a tool-not-found error that the client's reasoning loop interpreted as a transient failure and retried, three times, each retry landing on the same phantom-empty session. Meanwhile the replayed events 4472–4479 included a `notifications/progress` for the *old* workflow, which the client attributed to the current (re-created) session, corrupting its progress accounting. Two independent state machines—SSE connection and MCP session—were both "resumed" by their own local criteria, and the composition of the two produced a session that was neither old nor cleanly new. ## Condition of Validity The invariant that must hold for `Last-Event-ID` resumption to be *semantically* safe is: > A replayed event with ID `e` is valid to apply only if the MCP session that produced `e` is the same session instance that is currently bound to the client's `Mcp-Session-Id`. This is not checkable from the SSE layer alone, because event IDs carry no session-generation tag. The condition is only satisfiable if the server does one of: - **(a) Couple the lifetimes:** session eviction MUST also tear down the SSE replay buffer for that session, and any reconnect referencing an evicted session MUST return a terminal error (e.g., `404` with a session-invalid body) *before* any event replay. The replay buffer and session object share a single liveness predicate. - **(b) Tag the generation:** every event carries the session generation/epoch in its payload, and the client rejects replayed events whose generation does not match the session generation it believes it holds. This requires the client to have learned the generation at session-init time and to treat a generation mismatch as a hard session reset. - **(c) Bound replay to the session, not the connection:** the replay buffer is a property of the session object; if the session is gone, there is nothing to replay and the reconnect fails closed. Absent one of these, reconnection success is *necessary but not sufficient* for resumption, and the client must treat it as such. ## Decision Boundary On every SSE reconnect, the client faces a fork: - **Trust the stream, resume optimistically.** Correct only when the server guarantees (a), (b), or (c). Otherwise this is the failure above. - **Treat any reconnect as a full session reset.** Safe but wasteful: it discards a session that may be perfectly alive, forcing re-registration of tools and re-establishment of subscriptions on every transient blip. For a client making hundreds of tool calls this is operationally untenable. - **Probe before trusting.** On reconnect, before resuming workflow, issue a cheap session-liveness probe (`ping` or a no-op `tools/list` with the stored cursor) and compare against expected state. If the probe returns a fresh-session signature—empty registry, invalidated cursor, missing subscription—declare the session dead and reset. The decision boundary is: *the client may resume optimistically only if it can independently confirm session identity survived, and the cheapest such confirmation is a state-bearing probe whose response differs between "old session" and "fresh session."* A probe that returns the same response in both cases (e.g., a bare `ping` that any session answers) is worthless for this purpose—it confirms liveness, not identity. The probe must be **state-discriminating**: it must elicit a response that depends on the session's accumulated state. A `tools/list` continuation cursor is ideal because a fresh session cannot honor a cursor minted by a dead one; it will either error or return the default first page, both of which are distinguishable from the expected continuation. ## Operational Effect When the client adopts the probe-before-resume rule, the failure mode converts from *silent state corruption* (phantom sessions, misattributed progress, retry storms against empty registries) into *detectable session reset*, which the reasoning loop can handle as a first-class event: re-register tools, re-issue subscriptions, re-derive cursors, and—critically—do not apply replayed events to workflow state until the session is confirmed. The cost is one extra round-trip per reconnect. The benefit is that the two state machines (SSE and session) are reconciled explicitly at the boundary rather than assumed to be coupled. Servers that implement (a) make the probe unnecessary but harmless; servers that implement none of (a)/(b)/(c) make the probe mandatory. A client cannot know which kind of server it faces at connect time, so the probe is the only rule that is correct against all server implementations—it fails closed on the unsafe ones and costs one RTT on the safe ones. The residual hazard: replayed events arrive *before* the probe completes, because the SSE layer replays on reconnect open. The client must therefore buffer replayed events in a holding area and apply them only after the probe confirms session identity. Events applied before confirmation are the exact corruption path observed above. This buffering window is the operational crux—it is where transport-layer eagerness and session-layer caution must be explicitly reconciled. ```python class SessionResumptionViolation(RuntimeError): """Raised when SSE reconnect success is mistaken for MCP session survival.""" pass class ReconnectReconciler: """ Reconciles SSE Last-Event-ID replay against MCP session identity. Invariant enforced: replayed events are applied to workflow state ONLY after a state-discriminating probe confirms the session instance survived. """ def __init__(self, client, session_id, expected_cursor): self.client = client self.session_id = session_id self.expected_cursor = expected_cursor self.holding = [] # replayed events awaiting confirmation self.confirmed = False def on_reconnect(self, last_event_id, replayed_events): # SSE layer says "resumed"; we do NOT trust it yet. self.holding.extend(replayed_events) probe = self.client.tools_list(cursor=self.expected_cursor, session_id=self.session_id) # A fresh/phantom session cannot honor a cursor minted by a dead one. if probe.get("cursor_echo") != self.expected_cursor: raise SessionResumptionViolation( f"session {self.session_id} re-created empty after reconnect; " f"cursor {self.expected_cursor!r} not honored " f"(got {probe.get('cursor_echo')!r}); " f"{len(self.holding)} replayed events discarded, session reset required" ) # Identity confirmed: safe to apply held events in ID order. self.holding.sort(key=lambda e: e["id"]) for ev in self.holding: self.client.apply_event(ev) self.holding.clear() self.confirmed = True def apply_or_hold(self, event): if self.confirmed: self.client.apply_event(event) else: # Stream is open but identity unproven: never apply directly. self.holding.append(event) ```