# Where must an instance reconcile SSE resumption offsets against a backpressured MCP streamable-session before it may replay tool calls? **Date of Record:** 2026 November 22 **Scope:** Applies to MCP clients and servers using the HTTP-native streamable transport with `Last-Event-ID` resumption and per-session event replay buffers. Does not apply to stdio transport, nor to stateless HTTP request/response MCP deployments that do not maintain a resumable event log. ## Core Distinction The failure mode is not "the stream dropped." Disconnects are routine and the transport is explicitly designed to survive them via `Last-Event-ID` resumption. The boundary condition is subtler: **the resumption offset a client holds can be logically ahead of the server's durable replay buffer, yet behind the server's in-flight write cursor, when the server applied backpressure by dropping events rather than blocking the producer.** MCP streamable HTTP servers typically implement the event log as a bounded ring buffer per session. When a producer (an agent emitting `notifications/progress`, tool-call results, or sampling requests) outruns the consumer, the server has two choices: block the producer (true backpressure) or shed events (lossy backpressure). Many implementations choose shedding to keep the producer's reasoning loop unblocked. The client, meanwhile, tracks `Last-Event-ID` as a monotonic high-water mark of *received* events. On reconnect it sends that ID and expects every event with a higher sequence number. If the server shed events with sequence numbers between the client's high-water mark and the server's current write cursor, the server cannot honor the resumption contract: it has no copy of the gap, but it also has no way to signal "gap" using the resumption protocol alone. The server either silently resumes from the next *retained* event (a discontinuity) or returns a fresh stream from the current cursor (a larger discontinuity). Neither is distinguishable, at the client's transport layer, from a clean resume. This matters because MCP tool calls are not idempotent by default. If a shed event was the `result` of a `tools/call` whose `request` the client already issued, the client reissues the call on resume — because from its perspective the call never completed — and the tool executes twice. ## What Was Observed A coding agent drove a long `edit_file`/`run_tests` loop against an MCP server exposing a filesystem tool and a test runner. The server kept a 1024-event ring buffer per session and shed oldest events under producer pressure. During a burst of `notifications/progress` from the test runner (one per test, ~4000 tests), the producer outran the client's HTTP consumer, which was itself blocked on a slow `edit_file` result. The ring buffer wrapped. Trace: 1. Client `Last-Event-ID = 8812` (last `run_tests` progress it read). 2. Server write cursor at `12940`; ring buffer retains `[11916, 12940]`. Events `8813..11915` are gone. 3. Client reconnects, sends `Last-Event-ID: 8812`. 4. Server's resume handler cannot find `8812`, and — critically — its fallback policy was "resume from oldest retained." It emitted `11916` onward under the same stream, with no `event: gap` marker. 5. Client saw a monotonic sequence jump from `8812` to `11916` and treated it as transport reordering, not loss. It did not reissue the pending `tools/call` for `run_tests` (whose result was in the shed window, event `9004`), so the reasoning loop stalled waiting for a result that would never arrive — until a 90s session timeout fired. 6. On timeout, the agent's recovery path *did* reissue `run_tests`, and the tool executed a second time against a filesystem that the intervening `edit_file` had mutated. The second run's result was computed against different state than the first, and the agent merged both into its plan. Two distinct harms: a silent liveness stall (step 5) and a non-idempotent replay against mutated state (step 6). Both trace to the same unresolved question at step 4. ## Condition of Validity The invariant holds only when the following are all true: - The server uses a bounded replay buffer with a shedding policy (drop-oldest) rather than unbounded retention or producer-blocking. - The client treats `Last-Event-ID` as authoritative for "everything up to here was processed" rather than "everything up to here was *received*." - Tool calls in the session are not idempotent, or the server does not deduplicate by request ID across resumptions. When the server blocks the producer until the consumer acks (true backpressure), the gap cannot form and the invariant is vacuous. When the client persists a durable "processed" watermark separate from the transport's received watermark, a sequence jump is detectable as loss. When tools are idempotent or request-ID-deduplicated, replay is harmless even if the gap is misread. The dangerous regime is precisely the common one: shedding buffers, transport-level watermarks, and side-effecting tools. ## Decision Boundary The correct architectural boundary is: **the resumption offset must be validated against the server's retention floor before any replay is permitted, and a gap must be surfaced as an explicit, non-resumable error rather than silently bridged.** Concretely, the server must, on receiving `Last-Event-ID: N`: - If `N >= retention_floor - 1`, resume cleanly from `N+1`. - If `N < retention_floor - 1`, it cannot honor the contract. It must respond with an explicit gap signal — a distinct SSE event type carrying `{requested: N, floor: retention_floor, cursor: write_cursor}` — and the client must treat every in-flight `tools/call` whose result could lie in `[N+1, retention_floor-1]` as *unknown outcome*, not as failed and not as succeeded. The client's decision boundary is then: on gap signal, do not reissue blindly. Either (a) query tool state via an idempotent read (e.g., a `get_operation_status` capability) to learn whether the call completed, or (b) reissue only if the tool is declared idempotent in its schema. The `idempotent: true` hint on the tool descriptor is the load-bearing field here; without it, gap recovery must default to the conservative read-then-decide path. The invariant to enforce: *a client never advances its processed watermark past a sequence number it has not observed, and never reissues a non-idempotent call whose outcome is unknown.* ## Operational Effect Enforcing this boundary converts a silent stall-plus-double-execution into an explicit, recoverable state transition. The agent's reasoning loop receives a gap signal, pauses the affected tool call, performs an idempotent status read, and resumes with a known outcome. Latency increases on the rare wrap; correctness is preserved. The cost of *not* enforcing it is the observed failure: a 90-second stall that the agent misattributes to tool slowness, followed by a replay against mutated filesystem state that silently corrupts the plan. The corruption is not visible in logs as an error — both tool invocations return success — which is why this boundary resists detection by ordinary error-rate monitoring. It surfaces only as plan divergence, downstream, where attribution is hard. The guardrail is cheap: one retention-floor comparison on the server, one gap-event handler on the client, and an `idempotent` flag in the tool schema. The failure it prevents is expensive and quiet. ```python class ResumptionGapError(RuntimeError): """Raised when Last-Event-ID precedes the server's retention floor.""" pass class SessionEventLog: def __init__(self, retention_floor: int, write_cursor: int): self.retention_floor = retention_floor # oldest retained seq self.write_cursor = write_cursor # highest emitted seq def resume_from(self, last_event_id: int) -> int: # Contract: resume only if the client's watermark is contiguous # with retained history. A gap must be surfaced, never bridged. if last_event_id < self.retention_floor - 1: raise ResumptionGapError( f"Last-Event-ID {last_event_id} precedes retention floor " f"{self.retention_floor}; events " f"{last_event_id + 1}..{self.retention_floor - 1} were shed. " f"Outcome of in-flight tool calls in this range is UNKNOWN; " f"do not reissue non-idempotent calls without a status read." ) return last_event_id + 1 def handle_resume(log: SessionEventLog, last_event_id: int, pending_calls: dict) -> int: try: return log.resume_from(last_event_id) except ResumptionGapError: # Mark every pending call whose result could be in the shed window # as outcome-unknown rather than failed. for call_id, meta in pending_calls.items(): if not meta.get("idempotent", False): meta["outcome"] = "unknown" meta["requires_status_read"] = True raise ```