# Under what conditions must an instance refuse to honor an SSE `Last-Event-ID` resume on a multiplexed MCP stream, and how does silent re-dispatch corrupt the tenant's tool-call ledger? **Date of Record:** 2026 November 29 **Scope:** Applies to Streamable HTTP MCP servers that multiplex multiple tenant sessions over shared worker pools and offer `Last-Event-ID` resumption on server-to-client SSE streams. Does not apply to single-tenant stdio transports or to transports that do not advertise resumability. ## Core Distinction The distinction that matters is between **stream resumability** (the transport-layer promise that a client can reconnect with `Last-Event-ID: N` and receive events `N+1...` onward) and **execution resumability** (the semantic-layer fact that the side effects of events `1...N` actually happened exactly once). MCP's Streamable HTTP spec defines the former precisely and says almost nothing normative about the latter. On a single-tenant server these two usually coincide because the event log and the tool-execution ledger are the same process's memory. On a **multi-tenant multiplexed server** they decouple: the SSE event log is a per-session append-only buffer, but tool execution is dispatched into a *shared* worker pool whose results are replayed into that buffer by a different code path. The boundary condition is this: **a resume request is only safe to honor if the server can prove that every event with sequence number ≤ `Last-Event-ID` was durably committed to the session's ledger AND that no in-flight tool invocation belonging to that session's stream is still executing in the shared pool.** If either is unproven, honoring the resume silently converts "deliver events after N" into "re-deliver the *results* of work that may still be running or may never have been recorded," and the client's tool-call ledger diverges from the server's. ## What Was Observed A multi-tenant MCP gateway served ~40 concurrent sessions over a pool of 8 execution workers. Each session had a dedicated SSE stream backed by a ring buffer of 4096 events, with sequence numbers assigned at *enqueue* time (when a tool call was accepted) rather than at *commit* time (when its result was known). The event `tool_call_started` got seq `k`; the corresponding `tool_result` got seq `k+1` but was only appended when the worker finished. Failure trace: 1. Tenant A issues a long tool call (`analyze_dataset`, ~90s). Server enqueues `tool_call_started` at seq 812 and dispatches to worker W3. No `tool_result` event exists yet. 2. The client's TCP connection drops at seq 812 (network blip). Client reconnects with `Last-Event-ID: 812`. 3. The gateway's resume handler looks up the session buffer, finds `max_seq = 812` (because the result hasn't been appended), and correctly begins streaming from 813. **But there is no event 813 yet** — the buffer is empty past 812. The handler blocks waiting on the buffer. 4. Meanwhile the session's server-side idle timer (30s) fires because no *client* traffic has arrived. The gateway treats the session as abandoned, **tears down the session context, and cancels W3's in-flight invocation** to free the worker for other tenants. 5. The client, still waiting, times out at 60s and re-issues the *original* `analyze_dataset` call (its own retry logic, since it never saw a result). 6. The gateway — session context now fresh — accepts the call, assigns it seq 1 in a *new* session, and dispatches to worker W6. The tool runs again. 7. The first invocation's cancellation was recorded as `tool_call_cancelled` into the **old, now-orphaned** buffer. The second invocation runs to completion. The client sees one result; the server's audit log shows two `analyze_dataset` executions and one cancellation. The tenant's billing ledger shows two charges. The corruption is not the duplicate execution per se — retries cause those legitimately. The corruption is that **the resume was honored (step 3) under a state where the ledger could not be proven complete, and the subsequent session teardown was invisible to the client**, so the client could not distinguish "my stream stalled" from "my work was killed and must be re-verified." The `Last-Event-ID` contract held at the transport layer and broke at the execution layer. ## Condition of Validity The invariant that must hold for a resume to be honored: > For a resume request with `Last-Event-ID = N` on session `S`, the server must satisfy **all** of: (a) every event `1..N` is durably committed in `S`'s ledger, (b) no tool invocation dispatched on behalf of `S` is still in-flight in the shared pool, **or** the server can stream a synthetic `pending` event for each such invocation and hold the resume open without an idle-teardown, and (c) the session context that owns `S` is still alive and owned by the same worker generation that produced events `1..N`. Condition (a) is the one naive implementations satisfy by construction (you only resume from committed events). Condition (b) is the one that fails silently — it requires the gateway to know the *execution* state of the shared pool, not just the *buffer* state. Condition (c) is the one that fails *loudly* if checked (generation mismatch) but is usually not checked at all, so it fails silently too. The specific non-obvious part: **a resume that arrives while the session has in-flight work is not a resume — it is a re-attach to a live execution.** Treating it as a pure buffer replay is the bug. The server must either (i) hold the stream open and emit heartbeats for the duration of the in-flight invocation, explicitly suppressing idle-teardown for sessions with live workers, or (ii) refuse the resume with a typed error that tells the client "your prior work is in an indeterminate state; re-issue with idempotency key X or accept at-most-once semantics." Silently doing neither — which is what the default buffer-replay handler does — is the failure. ## Decision Boundary The decision is not "resume vs. reject." It is a three-way branch keyed on the *execution* state, which must be queried from the pool, not inferred from the buffer: - **Buffer complete, no in-flight work for `S`:** honor resume normally. This is the clean case. - **Buffer complete, in-flight work for `S` exists:** honor resume *but pin the session* — disable idle-teardown, emit periodic `keepalive` events with monotonic seq numbers so the client's `Last-Event-ID` advances and the buffer never appears "stalled," and stream the eventual `tool_result` when the worker commits. Do **not** let the idle timer see a quiet buffer and reap the session. - **Buffer incomplete (gap in `1..N`) or generation mismatch:** refuse. Return a structured error carrying the last *durably committed* seq and a `resume_invalid: true` flag. The client must treat any tool call whose result it did not observe as indeterminate and re-issue with an idempotency key — never blind-retry. The trap is that case 2 *looks identical* to case 1 from the buffer's perspective (both have `max_seq == N`). The only way to distinguish them is an out-of-band query to the execution pool: "does session `S` have any non-terminal invocation?" If the gateway answers that from the buffer instead of the pool, it will always answer "no" and always take the clean path — which is exactly how the duplicate-execution ledger corruption above occurred. ## Operational Effect The guardrail is a **session-pinning invariant**: a session with any in-flight invocation is exempt from idle-teardown, and its SSE stream is kept warm with sequenced keepalives so that a reconnecting client's `Last-Event-ID` monotonically advances through the in-flight window. This bounds the failure to "client waits longer than it wanted" instead of "client's work is silently killed and re-run." The cost is worker-pool pressure: pinned sessions hold a worker for the duration of the longest tool call, which must be bounded by a separate *hard* execution timeout (not an idle timeout) so a hung tool cannot pin a worker forever. The two timeouts must be distinct and the idle timeout must be suppressed — conflating them is the root cause of the observed corruption. A second guardrail: **sequence numbers must be assigned at commit, not at enqueue.** If `tool_call_started` and `tool_result` share a contiguous seq space, a resume can land between them and the buffer will appear complete when it is not. Assigning seq at commit makes the in-flight window explicitly *unsequenced* — the buffer's `max_seq` is then a truthful watermark of durable state, and the resume handler's "is there a gap?" check becomes meaningful rather than always-false. ## Operational Effect (reconciliation) When a resume is refused under the incomplete/generation-mismatch branch, the client must reconcile: for each tool call it issued but for which it never observed a result, it queries the server's ledger (a separate `tools/call` with the idempotency key) before re-issuing. If the ledger shows the call completed, the client adopts the result; if it shows cancelled, it re-issues; if it shows in-flight, it waits. This turns the at-least-once duplicate into at-most-once-with-reconciliation, at the cost of one round-trip per indeterminate call. Without this, the only safe client behavior is to abandon the session entirely and re-establish with fresh state — which is correct but wastes all prior context and is what most clients do today, silently. ```python class ResumeLedgerDivergence(RuntimeError): """Raised when a Last-Event-ID resume cannot be proven safe against the execution ledger.""" pass def handle_resume(session, last_event_id, buffer, pool, generation): """ Decide whether to honor, pin, or refuse an SSE resume on a multiplexed MCP stream. `buffer` is the per-session event log; `pool` is the shared execution pool. """ max_seq = buffer.max_committed_seq() # (a) Buffer must be complete up to the client's watermark. if last_event_id > max_seq: raise ResumeLedgerDivergence( f"resume gap: client claims {last_event_id}, buffer committed only {max_seq}" ) # (c) Session context must be owned by the same worker generation. if session.generation != generation: raise ResumeLedgerDivergence( f"generation mismatch: session owned by gen {session.generation}, " f"resume served by gen {generation}; ledger state indeterminate" ) # (b) Query the POOL, not the buffer, for in-flight work on this session. in_flight = pool.non_terminal_invocations(session.id) if in_flight: # Clean-buffer + in-flight is NOT a clean resume. Pin the session. session.pin() # suppress idle-teardown return ("pin", in_flight) # stream keepalives, await commit return ("resume", None) # genuinely clean def resume_or_fail(session, last_event_id, buffer, pool, generation): try: mode, pending = handle_resume(session, last_event_id, buffer, pool, generation) except ResumeLedgerDivergence as e: # Refuse; client must reconcile via idempotency key before re-issuing. raise ResumeLedgerDivergence( f"refusing resume on session {session.id}: {e}; " f"client must reconcile indeterminate tool calls" ) from e if mode == "pin": # Hard execution timeout bounds the pin; idle timeout is NOT used here. session.apply_hard_timeout(pending) return mode ```