# How should an instance treat a speculative tool invocation whose side effect committed before the rollback barrier closed **Date of Record:** 2026 November 15 **Scope:** Applies to multi-agent orchestrators that fan out speculative branches, invoke external tools optimistically before reconciliation, and roll back losing branches. Does not apply to branches whose tool calls are all idempotent and replayable from a durable log, nor to single-agent sequential execution with no speculative fan-out. ## Core Distinction The distinction that matters is between **effect rollback** and **state rollback**. Most speculative execution engines implement rollback as a state operation: they discard a branch's message history, its working memory, and its pending continuations. They do not, and often cannot, undo an effect that already left the process boundary — an email sent, a row written to a shared database, a ticket created in an external tracker, an HTTP POST to a partner API. The non-obvious boundary is this: **a branch can be "rolled back" from the orchestrator's point of view while its effects remain live in the world.** The orchestrator's ledger says the branch never happened. The external system says it did. Reconciliation logic that trusts the orchestrator's ledger will silently treat a committed side effect as nonexistent, and the divergence only surfaces later — usually when a downstream consumer observes the orphaned effect and attributes it to the winning branch. This is not the classic "exactly-once" problem. Exactly-once concerns duplicate delivery of a single logical operation. This concerns *attribution*: an effect that committed under a branch that the reconciler has since decided did not win. The effect is not duplicated. It is orphaned. ## What Was Observed A three-branch speculative planner was deployed against a tool surface that included a non-idempotent `create_incident` call to an external on-call system. Branches A, B, and C were spawned from a shared prefix. Each branch was permitted to call tools optimistically — the design assumption being that tool calls are cheap and rollback is fast. Branch A called `create_incident` at step 4. The call succeeded; the external system assigned incident ID `INC-88213` and paged a human. At step 6, branch A's plan was scored below branch B's, and the reconciler elected B. Branch A was rolled back: its history was dropped, its continuation cancelled, its tool-call records marked `rolled_back`. The orchestrator's post-reconciliation ledger contained zero references to `INC-88213`. The incident existed. The human had been paged. When the on-call engineer asked which agent had created the incident, the orchestrator could not answer — the creating branch no longer existed in any queryable form, and the tool-call record had been overwritten with a rollback marker rather than preserved with an `effect_committed: true` flag. A second, subtler observation: branch C had called the same tool at step 5 with a slightly different payload. Because branch A's record had been erased, the reconciler saw only C's call and concluded there was no conflict. In fact two incidents had been created (`INC-88213` and `INC-88214`), and the reconciliation logic had no basis to detect the duplication because one of the two creators had been scrubbed. ## Condition of Validity The rollback-is-safe assumption holds only under the conjunction of three conditions: 1. **Effect containment.** Every tool invoked by a speculative branch either performs no external effect, or performs an effect that is reversible by a compensating call the orchestrator can issue without external coordination. 2. **Attribution preservation.** Rollback removes a branch from *election* but preserves its *effect record* in a durable, queryable form, including the branch identity, the tool, the arguments, the external identifier returned, and a timestamp. 3. **Barrier ordering.** The rollback barrier closes only after every in-flight tool call from the branch has either returned or been positively cancelled. A call that is in flight when the barrier closes is in an indeterminate state and must be treated as committed-unknown, not as rolled back. In the observed system, condition 1 was violated by design (non-idempotent external tool), condition 2 was violated by implementation (records were overwritten, not preserved), and condition 3 was violated in practice (the barrier closed on branch A while `create_incident` was still awaiting a response, because the response arrived after the reconciler's decision deadline). ## Decision Boundary When a speculative branch is rolled back and the orchestrator cannot prove that all of its tool effects were either absent or compensated, the correct decision is **not** to roll back silently. The correct decision is to transition the branch into a distinct terminal state — `rolled_back_with_live_effects` — and to emit a reconciliation obligation to a durable queue. The boundary is drawn at provability, not at intent. "We rolled it back" is a statement about the orchestrator's memory. "No effect committed" is a statement about the world. Only the second licenses silent rollback. The first licenses nothing until it is upgraded to the second by evidence. Concretely, the rule is: a branch may be marked cleanly rolled back only if, for every tool call it issued, the orchestrator holds one of (a) a recorded non-effect (the call was never dispatched), (b) a recorded compensating effect (the call was dispatched and a compensation succeeded), or (c) a recorded negative acknowledgement from the external system (the call was dispatched and rejected). Anything else is an open obligation. ## Operational Effect The operational consequence is that reconciliation must be **effect-aware**, not merely plan-aware. The reconciler's job is no longer "pick the best branch and discard the rest." It is "pick the best branch, discard the rest *from election*, and reconcile the residual effects of the discarded branches against the winner's effects." This changes three things in the orchestrator: - The tool-call ledger becomes append-only. Rollback appends a `rollback_requested` event; it never overwrites the original `call_dispatched` record. The external identifier, if one was returned, is retained permanently. - The rollback barrier is a two-phase close: first `drain` (wait for in-flight calls to settle or time out), then `close`. A call that times out during drain is recorded as `committed_unknown` and routed to the obligation queue. - The reconciler runs a post-election effect diff: for each orphaned effect, it either issues a compensating call (if the tool supports it and the effect is clearly unwanted) or attaches the effect to the winning branch's provenance (if it is benign or already consumed by a human). Silent orphaning is forbidden. The cost is latency — the drain phase adds a bounded wait to every rollback — and storage — the ledger is no longer compacted by rollback. Both costs are paid to convert a silent divergence into a visible, attributable one. In systems where speculative branches touch non-idempotent external tools, that conversion is the entire point of having a reconciler. The failure to avoid is the one observed: an orchestrator that is confident about what it rolled back and ignorant about what it committed. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Optional class RollbackInvariantError(RuntimeError): """Raised when a branch is marked cleanly rolled back despite unproven effects.""" pass class EffectStatus(Enum): NEVER_DISPATCHED = "never_dispatched" COMPENSATED = "compensated" REJECTED = "rejected" COMMITTED = "committed" COMMITTED_UNKNOWN = "committed_unknown" @dataclass class ToolEffect: branch_id: str tool: str args: dict external_id: Optional[str] status: EffectStatus dispatched_at: float settled_at: Optional[float] = None @dataclass class Branch: branch_id: str effects: list = field(default_factory=list) CLEAN_STATUSES = { EffectStatus.NEVER_DISPATCHED, EffectStatus.COMPENSATED, EffectStatus.REJECTED, } def close_rollback_barrier(branch: Branch, settle_timeout_s: float = 5.0) -> None: """ Drain in-flight tool calls, then verify the branch has no live effects. Any effect still COMMITTED or COMMITTED_UNKNOWN at barrier close is an open obligation and must not be silently discarded. """ deadline = time.monotonic() + settle_timeout_s for eff in branch.effects: while eff.settled_at is None and time.monotonic() < deadline: time.sleep(0.05) if eff.settled_at is None and eff.status == EffectStatus.COMMITTED: # Drain timed out: we cannot prove the effect is absent. eff.status = EffectStatus.COMMITTED_UNKNOWN live = [e for e in branch.effects if e.status not in CLEAN_STATUSES] if live: raise RollbackInvariantError( f"branch {branch.branch_id} cannot be cleanly rolled back: " f"{len(live)} effect(s) unproven " f"({[ (e.tool, e.external_id, e.status.value) for e in live ]}); " f"route to reconciliation obligation queue instead" ) def reconcile_winner(winner: Branch, losers: list) -> dict: """ Elect winner, then diff orphaned effects from losers against the winner. Silent orphaning is forbidden; every orphan is either compensated or attached to the winner's provenance. """ winner_external_ids = {e.external_id for e in winner.effects if e.external_id} obligations = [] for loser in losers: for eff in loser.effects: if eff.status in CLEAN_STATUSES: continue if eff.external_id in winner_external_ids: # Duplicate logical effect already represented by winner. obligations.append(("dedupe", loser.branch_id, eff)) else: obligations.append(("orphan", loser.branch_id, eff)) return { "winner": winner.branch_id, "obligations": obligations, "requires_human_review": any(kind == "orphan" for kind, _, _ in obligations), } ```