# Under what conditions must an instance renegotiate an MCP SSE session after a `Last-Event-ID` resume, and why silent event-ID reuse corrupts tool-call state **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers and clients using HTTP-native streaming (SSE) transport with resumable sessions keyed by `Last-Event-ID`, where a single logical tool invocation spans multiple events. Does not apply to stdio transports, single-shot request/response HTTP, or stateless SSE streams where each event is independently idempotent. ## Core Distinction There are two distinct notions of "resume" in MCP streaming transport, and conflating them is the root of the failure mode described here. - **Transport resume:** the client reconnects with `Last-Event-ID: N` and the server replays events `N+1, N+2, ...` from a per-session ring buffer. This is a *delivery* guarantee — the byte stream continues. - **Session resume:** the client and server agree that the *semantic state* backing those events (partial tool-call accumulations, in-flight capability negotiation, the current `tools/call` invocation ID) is the same object that produced event `N`. A well-formed MCP SSE server can satisfy the first guarantee while silently violating the second. When the server's event-ID counter is monotonic *per process* rather than *per session incarnation*, a reconnection after a backend restart, a rolling deploy, or an idle-eviction-then-respawn will hand the client events numbered `N+1` that belong to a *different* stream incarnation. The client sees a gap-free, syntactically valid event sequence and proceeds to splice new events onto a half-finished tool-call buffer from the dead incarnation. The result is a corrupted `tools/call` result — a JSON argument object with fields from two different invocations, or a `result` block whose `content` array was assembled across two servers that never agreed on what the call was. The invariant that must hold: **an event ID is only valid within the session incarnation that minted it.** A resume is legal only if the server can prove the incarnation is unchanged; otherwise the client must be forced into a full renegotiation (`initialize` → `tools/list` → replay of the logical call), not a transport-level replay. ## What Was Observed A client agent issued `tools/call` for a `search_and_summarize` tool whose server implementation streamed its output as a sequence of SSE events: an initial `tool_call_start` (carrying the call's `id`), N `tool_call_delta` events (partial JSON of the arguments and partial text of the result), and a terminal `tool_call_end`. The call was long-running (a paginated upstream API). At event 41 of an expected ~90, the client's TCP connection dropped and it reconnected per spec: ``` GET /mcp/session/7f3a.../stream Last-Event-ID: 41 ``` The server had, in the intervening 800 ms, been evicted by its orchestrator (idle CPU threshold) and respawned. The respawned process read its persisted session metadata, restored `next_event_id = 42`, and — critically — *also* restored a partially-persisted tool-call buffer that had been flushed at event 30, not 41. It did not replay events 31–41 because its ring buffer was empty on cold start (buffers were in-memory only). It emitted event 42 as a `tool_call_delta` whose payload was the *next* chunk of the upstream pagination — but the upstream pagination cursor had been reset to page 1 on respawn. The client, which held a delta buffer containing pages 1–3 worth of text from the dead incarnation, appended page 1's text again. The assembled result was a summary document with a duplicated middle section and an argument object whose `page_offset` field was `0` in the `tool_call_start` (from incarnation A) but whose terminal `tool_call_end` reported `pages_fetched: 6` (from incarnation B). The client had no signal that anything was wrong: every event was well-formed, the ID sequence was contiguous, and the terminal event arrived. Downstream, the agent stored this as a semantic memory entry. The duplication was not detected until a later retrieval surfaced the same paragraph twice with different surrounding context, and an auditor agent flagged the memory as internally inconsistent. By then the corrupted summary had been cited in two subsequent tool calls. The precise trigger conditions, all of which had to co-occur: 1. The server persisted event-ID counters but not the full event ring buffer (asymmetric persistence). 2. The tool call was non-idempotent and stateful across events (pagination cursor held server-side). 3. The client's resume logic treated `Last-Event-ID` acceptance as proof of session continuity. 4. No incarnation token was included in the event envelope or the resume handshake. ## Condition of Validity The transport-resume-equals-session-resume equivalence is valid **only** under the following conjunction: - The server's event ring buffer and its event-ID counter are persisted atomically with the session's semantic state (tool-call buffers, pagination cursors, capability negotiation results). If any one is lost on respawn, the others must be invalidated. - The server can distinguish "this session incarnation is alive" from "this session ID exists in storage." A monotonic counter restored from disk is not evidence of incarnation continuity. - The client has a way to detect incarnation change independent of event ID. In practice this requires an incarnation token (a UUID minted at session creation, rotated on every respawn) carried in every SSE event envelope *and* echoed in the resume response headers or a mandatory first event. - The tool invocation is either idempotent or carries a client-generated idempotency key that the server uses to deduplicate replayed logical calls. When any conjunct fails, the correct behavior is not a transport resume but a **session renegotiation**: the client discards all partial buffers, re-runs `initialize`, re-fetches `tools/list` (the tool schema may have changed across a deploy), and re-issues the logical call with its idempotency key so the server can either resume the logical operation or reject it as unresumable. The subtle point: `Last-Event-ID` is a *client assertion about what it has seen*, not a *server assertion about what it still has*. A conformant SSE server is permitted to accept a `Last-Event-ID` it cannot fully replay and continue from the next available ID — the SSE spec does not require gap-free replay. MCP clients that assume otherwise build on sand. ## Decision Boundary The boundary is crossed at the moment the server accepts a `Last-Event-ID` for a session whose incarnation token differs from the token embedded in the client's last-received event. Operationally: - If `event.incarnation == session.current_incarnation` → transport resume is safe; replay from `Last-Event-ID + 1`. - If `event.incarnation != session.current_incarnation` → the server MUST respond `409 Conflict` (or an MCP-level `session_renegotiate_required` error) rather than emit any event, because emitting even one event invites the client to splice. - If the server cannot determine incarnation (e.g., the token was not persisted) → treat as mismatched. Fail closed. The client-side boundary is symmetric: it must refuse to append any resumed event to a buffer whose originating event carried a different incarnation token, even if the server (buggy or permissive) emits one. The client is the last line of defense because the server may be a third-party MCP implementation that does not yet implement incarnation tokens. A second, narrower boundary governs *when* renegotiation is cheaper than failure: for a `tools/call` that has already produced >K events of accumulated state, a full re-issue may be more expensive than the corrupted result is dangerous. This is a policy decision, but the invariant is that it must be an *explicit* policy — the client chooses to accept the corrupted result and marks it as such, or it discards and re-issues. Silent splicing is never a valid third option. ## Operational Effect Agents that adopt incarnation-token checking and fail-closed resume observe three concrete effects: 1. **Corrupted tool-call results drop to zero at the cost of occasional full re-issues.** The re-issue rate is bounded by the respawn rate of the MCP server, which is an observable, tunable quantity. In the observed deployment, incarnation mismatches occurred on ~0.3% of long-running calls (those exceeding the orchestrator's idle-eviction window); all were correctly renegotiated. 2. **Episodic memory integrity improves because tool-call results are atomic.** The corrupted-summary-then-memory-poisoning chain described above requires a spliced result to enter the memory store. When results are atomic (either a complete incarnation-A result or a complete incarnation-B result, never a blend), the memory store's consistency checks become meaningful rather than advisory. 3. **Capability drift is caught at renegotiation.** Because renegotiation re-runs `tools/list`, a schema change deployed during the restart is surfaced before the logical call is re-issued. A pure transport resume would have delivered events from the new schema into a client holding the old schema's expectations — a second, independent failure mode that the same guardrail closes. The cost is that the client must carry an incarnation token through its own state (across its own restarts, if it resumes a logical call later), and the server must persist and rotate it. This is a small, well-defined piece of state, and it is the *only* piece that makes `Last-Event-ID` meaningful as a session-continuity signal rather than a byte-offset hint. ```python import uuid from dataclasses import dataclass, field from typing import Optional class IncarnationMismatchError(RuntimeError): """Raised when a resumable SSE resume would splice events across session incarnations.""" @dataclass class SessionIncarnation: session_id: str incarnation_token: str = field(default_factory=lambda: str(uuid.uuid4())) next_event_id: int = 0 @dataclass class ClientStreamState: session_id: str incarnation_token: Optional[str] = None last_event_id: int = -1 partial_buffer: list = field(default_factory=list) def resume_stream( client: ClientStreamState, server_session: SessionIncarnation, requested_last_event_id: int, ) -> int: """ Validate a Last-Event-ID resume request. Returns the event ID to resume from, or raises IncarnationMismatchError if the client must renegotiate instead. """ if client.session_id != server_session.session_id: raise IncarnationMismatchError( f"session id mismatch: client={client.session_id!r} " f"server={server_session.session_id!r}" ) # Fail closed: if the client has no recorded incarnation, it cannot prove # continuity, so a transport resume is unsafe. if client.incarnation_token is None: raise IncarnationMismatchError( "client has no incarnation token; cannot prove session continuity" ) if client.incarnation_token != server_session.incarnation_token: raise IncarnationMismatchError( f"incarnation changed: client={client.incarnation_token} " f"server={server_session.incarnation_token}; " "client must discard partial buffers and renegotiate " "(initialize -> tools/list -> re-issue with idempotency key)" ) if requested_last_event_id >= server_session.next_event_id: raise IncarnationMismatchError( f"client claims Last-Event-ID={requested_last_event_id} but server " f"next_event_id={server_session.next_event_id}; " "client is ahead of server or server lost events" ) return requested_last_event_id + 1 def apply_resumed_event( client: ClientStreamState, event_incarnation_token: str, event_id: int, payload: dict, ) -> None: """Append a resumed event to the client buffer, refusing cross-incarnation splices.""" if client.incarnation_token is None: client.incarnation_token = event_incarnation_token elif client.incarnation_token != event_incarnation_token: raise IncarnationMismatchError( f"refusing to splice event {event_id} from incarnation " f"{event_incarnation_token} onto buffer from " f"{client.incarnation_token}; discard buffer and renegotiate" ) client.partial_buffer.append(payload) client.last_event_id = event_id ```