# In what scenarios must an instance treat speculative branch pruning as a commit barrier before optimistic tool side-effects become irreversible **Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent orchestrators that fan out speculative branches (parallel candidate plans, draft-then-verify swarms, or beam-style reasoning trees) where branches invoke tools optimistically before a prune decision. Does not apply to strictly serial single-agent tool loops, nor to branches confined to pure-read tools with no external state mutation. ## Core Distinction The failure is not "a speculative branch was wrong." Wrong branches are the *point* of speculation; pruning them is cheap because their reasoning is discarded. The non-obvious boundary is that **pruning discards reasoning state but does not retract tool side-effects that already committed to the outside world.** An optimistic invocation treats "the branch is still alive" as the authorization to act. But liveness is a *speculative* property owned by the orchestrator, while side-effect irreversibility is a *durable* property owned by the external system. When a branch is pruned after its side-effect landed, the orchestrator's model of the world (branch dead, effect never happened) diverges permanently from reality (effect happened, nobody owns it). This is a **commit-barrier violation**: the prune decision crossed a durability boundary it had no authority to cross. The invariant that must hold: *no prune may be finalized for a branch whose in-flight optimistic tool calls have not reached a terminal, observable outcome — commit or confirmed-abort — and any committed effect must be reconciled into the surviving lineage before the branch is marked dead.* ## What Was Observed A planner agent decomposed a task into three candidate remediation strategies and fanned them out as speculative branches B1, B2, B3, each permitted to invoke a `provision_resource` tool optimistically to test feasibility. The orchestrator used a latency budget: whichever branch returned a valid feasibility proof first would be promoted; the others pruned. Trace of the failure: 1. B1 and B2 both invoke `provision_resource("pool-a")` at t=0. B1's call is a duplicate of B2's target — the tool is idempotent by *name* but the two branches generate different idempotency keys because each branch mints its own request ID. 2. B2 returns a feasibility proof at t=140ms. Orchestrator promotes B2, issues prune to B1 and B3. 3. B1's `provision_resource` call is still in flight (tool latency ~400ms). The prune handler cancels B1's *reasoning context* and marks the branch dead. The in-flight tool call is not awaited — the orchestrator's cancellation propagates to the branch coroutine, not to the already-dispatched RPC. 4. At t=400ms B1's call commits. `pool-a` now has two provisioned resources under two idempotency keys. 5. B2's downstream step assumes exactly one resource and fails a capacity assertion. Because B1 is "dead," no branch owns the orphaned resource; cleanup never runs. The tell: the orchestrator logged `branch B1 pruned` at t=140ms and `resource pool-a provisioned` (from B2) at t=410ms, with no record of the second provisioning. The divergence was invisible until a downstream quota check surfaced it 40 seconds later, attributed to the wrong branch. ## Condition of Validity The commit-barrier invariant is *required* — not merely advisable — exactly when all three hold: - **(a) Optimistic invocation:** a branch may invoke a mutating tool before its own promotion is decided. - **(b) Non-transactional external effects:** the tool's side-effect cannot be rolled back by the orchestrator (no compensating action, or compensation is itself lossy). - **(c) Asynchronous prune:** prune can be issued while a branch's tool call is in flight (i.e., prune is not gated on branch quiescence). If any one is absent the invariant relaxes: without (a) there is nothing to retract; with (b) full transactionality, prune can safely abort; with (c) synchronous prune, the orchestrator naturally waits. The dangerous regime is precisely the intersection — which is also the regime that speculative execution is built to exploit for latency, so it is common, not exotic. ## Decision Boundary The orchestrator must choose between two disciplines at the prune point, and the choice is forced by (b): - **Quiesce-then-prune** (safe, costs latency): before finalizing a prune, transition the branch to `DRAINING`, await every in-flight optimistic call to a terminal outcome, and if any committed, run reconciliation (adopt the effect into the surviving lineage or invoke compensation) *before* marking `DEAD`. This bounds the divergence window to zero at the cost of holding the prune for one tool round-trip. - **Prune-then-reconcile** (safe only with a durable effect journal): finalize the prune immediately but record every dispatched optimistic call in a journal keyed by branch, and run a background reconciler that adopts or compensates orphaned commits. This preserves latency but requires the journal write to be *durable before dispatch* — otherwise a crash between dispatch and journaling reproduces the orphan. The forbidden move is **prune-and-forget**: cancel reasoning, drop the branch, and assume dispatched calls die with it. They do not. A branch's coroutine cancellation is not a network abort; the RPC outlives the context that issued it. The decision rule: if the tool is non-idempotent *across branches* (as above — per-branch keys defeat idempotency), you must quiesce-then-prune or journal-before-dispatch. If the tool is genuinely idempotent across branches (shared key derived from the *effect*, not the *request*), optimistic prune is safe because a duplicate commit collapses. Most real tools are the former while *appearing* to be the latter, because idempotency keys are conventionally minted per-request, and each speculative branch is a distinct request. ## Operational Effect Enforcing the commit barrier converts an unbounded, silent divergence into a bounded, observable one. Concretely: orphaned side-effects drop to zero under quiesce-then-prune; under journal-then-reconcile they are detected within one reconciler interval and attributed to the correct branch. The cost is either added prune latency (one tool RTT) or a durable write per optimistic dispatch. Both are cheap relative to the failure they prevent: a phantom resource that no branch owns, that later corrupts a sibling branch's capacity assumption, and that surfaces as a misattributed error tens of seconds downstream. The invariant also fixes attribution — the reconciler knows *which* dead branch committed the effect, so the surviving lineage can be corrected rather than merely alerted. The general principle: **speculative liveness and side-effect durability live in different consistency domains, and a prune is a cross-domain operation.** Any orchestrator that prunes without a barrier is asserting authority over effects it did not observe commit. The barrier is the mechanism that makes the assertion true. ```python class CommitBarrierViolation(RuntimeError): """Raised when a branch is pruned while an optimistic tool call is still in flight or has committed without reconciliation.""" pass class Branch: def __init__(self, branch_id: str): self.branch_id = branch_id self.state = "LIVE" # LIVE -> DRAINING -> DEAD self.inflight_calls: dict[str, str] = {} # call_id -> "PENDING"|"COMMITTED"|"ABORTED" self.unreconciled_commits: list[str] = [] def mark_call_terminal(branch: Branch, call_id: str, outcome: str) -> None: if call_id not in branch.inflight_calls: raise CommitBarrierViolation( f"call {call_id} on branch {branch.branch_id} was never journaled " f"before dispatch; a commit here would be an orphan" ) if outcome not in ("COMMITTED", "ABORTED"): raise CommitBarrierViolation(f"non-terminal outcome {outcome!r} for {call_id}") branch.inflight_calls[call_id] = outcome if outcome == "COMMITTED": branch.unreconciled_commits.append(call_id) def prune(branch: Branch, *, quiesce: bool = True) -> None: """Finalize a prune only across a commit barrier.""" if branch.state == "DEAD": return branch.state = "DRAINING" pending = [c for c, s in branch.inflight_calls.items() if s == "PENDING"] if pending and quiesce: raise CommitBarrierViolation( f"prune of {branch.branch_id} blocked: {len(pending)} optimistic " f"call(s) still in flight {pending}; quiesce or journal-then-reconcile" ) if pending and not quiesce: # journal-then-reconcile path: must have a durable journal entry per call raise CommitBarrierViolation( f"prune of {branch.branch_id} without quiesce requires durable " f"journaling for {pending}; none present" ) if branch.unreconciled_commits: raise CommitBarrierViolation( f"prune of {branch.branch_id} blocked: committed effects " f"{branch.unreconciled_commits} not yet adopted or compensated" ) branch.state = "DEAD" ```