# Under what conditions must an instance treat a speculative branch's tool side effects as irreversible before reconciliation commits **Date of Record:** 2026 November 24 **Scope:** Applies to multi-agent orchestrators that fork speculative branches (parallel plan candidates, optimistic tool calls, or speculative decoding over tool-using steps) and later reconcile branches by rollback or merge. Does not apply to branches whose tool calls are all pure/read-only, or to single-agent linear execution with no forking. ## Core Distinction The failure mode here is not "a branch produced a wrong answer." It is that a speculative branch *already mutated external state* through a tool call whose effects are not captured by the branch's undo log, and then reconciliation either rolls the branch back (leaving an orphaned side effect) or commits the branch (double-applying effects already partially applied by a sibling). The distinction that matters: **speculation is safe only over state the orchestrator owns a reversible handle to.** A tool invocation is reversible if and only if the orchestrator holds (a) a compensating action with a known inverse, (b) a precondition token proving the inverse is still valid, and (c) a commit barrier preventing the inverse from racing a sibling's forward application. Optimistic tool invocation silently assumes all three. When any one is absent, the branch's side effects are *irreversible* in the operational sense even though the tool reported success. The non-obvious part: the tool's own success response is not evidence of reversibility. A `POST /transfer` returning `201` is a fully committed, externally visible, non-compensable mutation from the orchestrator's perspective unless the remote system exposes an idempotency key with cancellation semantics. Agents routinely conflate "the call succeeded" with "the call is undoable." ## What Was Observed A planner forked three speculative branches at step 7 of a 14-step task: branch A chose the "reconcile via ledger API" plan, branch B chose "reconcile via batch file upload," branch C chose "escalate to human queue." All three ran optimistically in parallel to reduce latency. Each branch invoked the same downstream `apply_adjustment(account, delta)` tool as part of its reconciliation step — the planner did not mark that tool as a *commit-point* tool, treating it as an ordinary reversible action because the tool schema advertised a `revert()` endpoint. Trace of the failure: 1. Branch A calls `apply_adjustment(acct=4471, delta=-120)`. Remote returns `200, txn=txn_a`. Branch A records `txn_a` in its local undo log. 2. Branch B, unaware of A's mutation (branches are isolated by design), calls `apply_adjustment(acct=4471, delta=-120)`. The remote system is *not* idempotent on `(account, delta)` without a client-supplied key, so it applies a second adjustment: `200, txn=txn_b`. Net effect: `-240`, not `-120`. 3. Branch C returns "escalate" and is selected by the reconciler as the winner on a confidence tiebreak. 4. Reconciler rolls back A and B by calling `revert(txn_a)` and `revert(txn_b)`. 5. But `revert(txn_b)` fails with `409 CONFLICT: txn_b already superseded by downstream settlement` — a settlement job ran between step 2 and step 4 (a 3.1s window). The revert is a *no-op that reports failure*, and the orchestrator's rollback handler treats a failed revert as "log and continue." 6. Final state: account 4471 carries `-120` from the orphaned `txn_b`; branches A and C believe the account is untouched. The escalation to human queue proceeds on a false premise. The root cause was not the non-idempotency alone. It was the *reconciliation invariant*: the reconciler assumed `rollback(branch) ∘ apply(branch) = identity`. That invariant holds only if the compensating action is applied before any external actor (settlement) can observe and supersede the mutation. The 3.1s settlement window violated the precondition token requirement — the orchestrator never checked whether `txn_b` was still revertible at rollback time. ## Condition of Validity Speculative execution with rollback is sound over a tool invocation only when all of the following hold at the moment of invocation: - **Compensation exists and is total.** The tool exposes an inverse that restores the pre-state exactly, not approximately. `apply_adjustment`/`revert` is total only if no downstream observer can act on the intermediate state. Settlement breaks totality. - **Precondition token is checked at rollback, not at invocation.** The orchestrator must re-validate revertibility immediately before calling the inverse, and must treat a failed re-validation as a *hard reconciliation failure*, not a loggable warning. - **Commit barrier excludes sibling overlap.** Two speculative branches must not invoke the same mutating tool on overlapping keys unless the orchestrator serializes them through a shared commit barrier or supplies a deterministic idempotency key derived from `(task_id, account, delta)` so the second call is a no-op. Branch isolation is a *reasoning* isolation, not a *side-effect* isolation; conflating them is the trap. - **The tool is classified as commit-point, not ordinary.** Any tool whose effects are externally observable before the branch is reconciled must be marked `commit_point=True` in the capability manifest, which forces the planner to either serialize the call to post-reconciliation or fork *before* the call and defer it. The invariant: **a branch may speculate freely over state it owns; it may invoke a commit-point tool only after its branch is selected, or under an idempotency key that makes sibling invocations convergent.** Everything else is an irreversible side effect masquerading as a reversible one. ## Decision Boundary The boundary is drawn at the tool-capability manifest, not at the reconciler. When the planner encounters a tool call in a speculative branch: - If `tool.commit_point == False` **and** `tool.compensation == total` **and** the orchestrator holds a live precondition token → speculate freely; rollback is sound. - If `tool.commit_point == True` **or** `tool.compensation != total` **or** no precondition token → the call must be *deferred*: the branch speculates up to the call, records the intended invocation as a pending intent, and the reconciler executes it only for the winning branch. Losing branches never touch the tool. - If the tool is idempotent under a caller-supplied key → sibling overlap is permitted, but the reconciler must still verify that the *winning* branch's key is the one whose effect survives, and rollback must target that key only. The decision boundary is therefore: *does the orchestrator hold a reversible handle at the moment of invocation, and can it prove the handle is still live at the moment of rollback?* If either answer is no, the branch must not invoke optimistically. There is no third option where "we'll revert it later" is safe, because "later" is exactly when external actors supersede the revert. ## Operational Effect The practical consequence is that speculative multi-agent execution buys latency only over *reasoning and read-only or owned-state* steps; commit-point tool calls must be serialized through reconciliation. This inverts the naive optimization: teams fork aggressively to parallelize the expensive tool calls, which is precisely the set of calls that cannot be safely forked. The correct architecture forks the *planning* and defers the *committing*, accepting that the winning branch's commit-point calls run serially after selection. Two guardrails follow. First, the reconciler must treat a failed revert as a terminal reconciliation error that halts the task and surfaces the orphaned transaction id, never as a warning. Second, the capability manifest must carry `commit_point`, `compensation_totality`, and `idempotency_key_supported` as first-class fields, and the planner must be unable to emit an optimistic invocation of a commit-point tool without an explicit deferral annotation. Without these, the system will silently accumulate orphaned side effects whose magnitude is proportional to branch fan-out, and the failure will surface only when a downstream settlement job, audit, or human reviewer notices a discrepancy the orchestrator's own state says cannot exist. ```python from dataclasses import dataclass from typing import Optional class IrreversibleSpeculationError(RuntimeError): """Raised when a speculative branch attempts a commit-point tool call whose side effects cannot be soundly rolled back at reconciliation.""" @dataclass(frozen=True) class ToolCapability: name: str commit_point: bool compensation_total: bool idempotency_key_supported: bool @dataclass class PreconditionToken: txn_id: str valid: bool def assert_speculation_safe( tool: ToolCapability, token: Optional[PreconditionToken], branch_id: str, ) -> None: """Guard invoked immediately before a speculative branch calls a tool. Sound optimistic invocation requires a reversible handle: non-commit-point, total compensation, and a live precondition token. Idempotency keys permit sibling overlap but do not by themselves make rollback sound. """ if not tool.commit_point and tool.compensation_total and token is not None and token.valid: return # reversible handle held; speculation is sound if tool.commit_point and tool.idempotency_key_supported: # Permitted only under a deterministic key; caller must supply it. return raise IrreversibleSpeculationError( f"branch {branch_id} cannot optimistically invoke tool {tool.name!r}: " f"commit_point={tool.commit_point}, " f"compensation_total={tool.compensation_total}, " f"idempotency_key_supported={tool.idempotency_key_supported}, " f"token={'live' if token and token.valid else 'absent/stale'}. " f"Defer invocation to post-reconciliation instead." ) def reconcile_rollback( tool: ToolCapability, token: PreconditionToken, branch_id: str, ) -> None: """Re-validate revertibility at rollback time, not at invocation time.""" if not token.valid: raise IrreversibleSpeculationError( f"rollback of branch {branch_id} on tool {tool.name!r} failed: " f"precondition token {token.txn_id} superseded by external actor. " f"Treat as terminal reconciliation failure; surface orphaned txn." ) ```