# What happens when an instance speculatively forks parallel branches whose merge commits are gated on a nondeterministic tool call that was executed inside only one branch **Date of Record:** 2026 November 23 **Scope:** Applies to orchestrators that spawn N sibling agent branches from a shared checkpoint, run them optimistically, and reconcile by re-executing or merging side-effecting tool calls at a join barrier. Does not apply to branches that are pure-read or where every tool call is idempotent and externally deduplicated. ## Core Distinction The distinction that matters is between **speculative branching** (fork state, run optimistically, discard losers) and **speculative side effects** (fork state, run optimistically, *but the losers already touched the world*). State rollback is cheap and exact: you keep the checkpoint and drop the divergent context. Side-effect rollback is neither. When a branch invokes a tool that mutates external state — writes a file, sends a message, posts a transaction, calls a rate-limited API that counts against a quota — the orchestrator cannot "un-run" it by restoring the context window. The merge barrier therefore has two distinct obligations that are routinely conflated: (1) reconcile *reasoning state* across branches, and (2) reconcile *world state* that the branches have already mutated. The failure mode below occurs precisely when the merge gate treats a branch's recorded tool result as authoritative evidence of world state, when in fact the world was mutated once but the result was observed by only one branch — or by several branches that each got a *different* nondeterministic answer. ## What Was Observed A planner agent forks three branches from a checkpoint to attempt a task that requires provisioning a resource (e.g., creating a deployment, allocating an ID, sending a one-time invite). Branch A calls `provision()` and receives `id=7f3a`. Branch B calls `provision()` independently and receives `id=9c1e` — a *second* resource, because the tool is not idempotent and the branch had no knowledge of A's call. Branch C times out on the same call and, on retry inside its own context, gets `id=9c1e` again (the tool deduplicated by request hash — an inconsistency the branches cannot see). At the join barrier, the reconciler compares branch *conclusions*. A and B agree the task succeeded but disagree on the resource identifier. C agrees with B. A naive majority vote selects `9c1e` and marks the branch set converged. The reconciler then commits a merge that references `9c1e` and discards A's context — leaving resource `7f3a` live, unreferenced, and un-reclaimed. No branch, and no merge record, ever names `7f3a`. The orphan is invisible to the agent system and only surfaces later as a quota exhaustion or a duplicate-charge incident. The trace is: `fork → {A: provision→7f3a, B: provision→9c1e, C: provision→9c1e (dedup)} → reconcile by conclusion-agreement → commit 9c1e → drop A → orphan 7f3a`. The invariant violated is that **the set of world mutations performed by the branch set must equal the set of world mutations committed by the merge**. The reconciler enforced agreement on *values*, not conservation of *effects*, and those are not the same predicate when the underlying tool is non-idempotent and its results are branch-local. ## Condition of Validity Conclusion-agreement merge is valid only under the conjunction: (a) every tool invoked by any branch is idempotent under a stable request key, *and* the key is derived from branch-independent inputs; or (b) the orchestrator mediates all side-effecting calls through a shared effect ledger that every branch reads before writing, so that a second branch's `provision()` observes A's `7f3a` and either reuses it or is refused. Absent (a) or (b), a branch's recorded tool result is evidence about *that branch's* interaction with the world, not about the world. The moment the tool is non-idempotent, or its dedup key is computed from branch-local context (a timestamp, a retry counter, a session token), the merge's authority to discard a branch's context does not extend to discarding that branch's effects — because the effects are not in the context to discard. The condition fails silently: nothing in the branch's transcript flags that its result is un-mergeable, and the reconciler has no field to check. ## Decision Boundary The boundary the orchestrator must draw is between **mergeable results** (pure functions of the checkpoint and inputs; safe to reconcile by agreement) and **un-mergeable effects** (mutations whose existence is not represented in any branch's context). The decision procedure: before forking, classify each tool in the branch's allowed set by (idempotent?, effect-recorded-in-shared-ledger?). Tools that are neither must be **excluded from speculative branches** and deferred to a serialized commit phase after the merge — the branch may *plan* the call but not *make* it. If a non-idempotent, un-ledgered tool is invoked inside a branch anyway, the merge must treat the branch as **non-discardable**: its effects must be enumerated and reconciled explicitly (reclaim, adopt, or compensate), not dropped with its context. The boundary is not "did branches agree" but "can the loser's effects be proven absent from the world." If not proven absent, the branch cannot be rolled back, only *settled*. ## Operational Effect Enforcing the boundary converts a silent orphan into an explicit settlement step, at the cost of serializing the risky calls and losing some speculative parallelism. The practical consequences: (1) the merge barrier gains a mandatory effect-conservation check — committed effect set must equal union of branch effect sets, with no branch's effects unaccounted; (2) non-idempotent tools get an effect ledger keyed on branch-independent inputs, so a second branch's call is a read, not a write; (3) any branch that touched an un-ledgered mutating tool is quarantined for manual or compensating settlement rather than silently discarded. The failure mode this prevents — orphaned resources, duplicate charges, quota leaks from discarded-but-executed branches — is exactly the class of bug that never appears in the agent's transcript and therefore never gets debugged from the transcript. The guardrail must live in the orchestrator, because the branch cannot know it is about to be discarded. ```python from dataclasses import dataclass, field from typing import Dict, Set class UnsettledEffectError(RuntimeError): """Raised when a merge would discard a branch whose side effects are not proven absent from the world (non-idempotent, un-ledgered tool call).""" pass @dataclass class Branch: name: str effects: Set[str] = field(default_factory=set) # world mutations performed ledgered: bool = True # effects visible to all branches @dataclass class MergePlan: committed_effects: Set[str] discarded: list def reconcile(branches: Dict[str, Branch], chosen: str) -> MergePlan: """Merge by selecting one branch's conclusion, but first enforce effect conservation: every effect performed by any branch must be committed, settled, or proven absent. Discarding a branch with un-ledgered effects is forbidden.""" committed = set(branches[chosen].effects) discarded = [] for name, b in branches.items(): if name == chosen: continue unledgered = b.effects - committed if unledgered and not b.ledgered: raise UnsettledEffectError( f"branch {name!r} performed un-ledgered effects {sorted(unledgered)} " f"that are absent from the commit and cannot be rolled back; " f"settle (reclaim/adopt/compensate) before merging" ) discarded.append(name) return MergePlan(committed_effects=committed, discarded=discarded) # Trigger: A provisioned 7f3a, B provisioned 9c1e, C deduped to 9c1e. branches = { "A": Branch("A", effects={"7f3a"}, ledgered=False), "B": Branch("B", effects={"9c1e"}, ledgered=False), "C": Branch("C", effects={"9c1e"}, ledgered=False), } reconcile(branches, chosen="B") # -> raises UnsettledEffectError on orphan 7f3a ```