# Where must an instance bound speculative branch merges when rollback is non-atomic across shared tool side effects **Date of Record:** 2026 November 20 **Scope:** Applies to orchestrators that fan out N agent branches speculatively from a common checkpoint, allow branches to mutate external state via tools, then select a winner and merge/rollback losers. Does not apply to pure-read speculation (no external side effects) or to branches that share no mutable resources. ## Core Distinction The failure is not "a branch produced a wrong answer." It is the distinction between **logical rollback** (discarding a branch's transcript and its entries in the orchestrator's own state store) and **physical rollback** (reversing the side effects that branch already committed to tools outside the orchestrator's transaction boundary). Most speculative-execution designs assume these are the same operation. They are not. A branch that has called `send_email`, `git push`, `charge_card`, or `INSERT INTO ledger` has produced effects that the orchestrator cannot un-commit by dropping a row from its own checkpoint table. The boundary question is precise: *at which point in a branch's execution does rollback stop being free, and what invariant must hold across the merge boundary so that a losing branch's non-atomic effects do not corrupt the winner's reconciliation?* ## What Was Observed A three-branch speculative fan-out was launched from checkpoint `C0` to solve a schema-migration task. Each branch was given the same prompt and a toolset including a migration applier (`apply_migration`) that mutates a live staging database, plus a read tool (`inspect_schema`). The orchestrator intended: run three branches, score them, keep the best, roll back the other two. Trace of the failure: 1. All three branches start at `C0`, all read schema version `v41`. 2. Branch A applies migration `m_a` (adds column `x`). Database now `v42`. 3. Branch B, still operating on its stale `C0` view of `v41`, applies migration `m_b` which also adds column `x` under the assumption it does not exist. The applier is not idempotent; it raises a duplicate-column error, but the branch's reasoning loop catches the tool error, interprets it as "transient," and retries with `m_b'` that adds column `y` instead. 4. Branch C applies `m_c` adding `z`. Database now `v42` with `x, y, z`. 5. Scoring selects Branch A as winner. Orchestrator rolls back B and C by discarding their transcripts and marking their checkpoints `rolled_back`. 6. Reconciliation step: winner A's expected post-state is "`v42` with `x`." Actual database state is "`v42` with `x, y, z`." The merge validator compares A's declared diff against the live schema, finds three columns where it expected one, and **fails the merge as a corrupted state** — but the corruption is not from A. It is the residue of B and C, which the orchestrator believed it had rolled back. The orchestrator's invariant was "discarding a branch's checkpoint discards its effects." That invariant is false the moment a branch touches a non-transactional external resource. The losing branches were logically rolled back and physically still present. The merge validator then attributed the orphaned effects to the winner. ## Condition of Validity Logical rollback is only equivalent to physical rollback under the following condition, which the fan-out must enforce *before* the first speculative branch is allowed to mutate anything: > **Speculation isolation invariant:** A branch may mutate an external resource only if that resource is (a) private to the branch (copy-on-write, per-branch namespace, per-branch transaction/savepoint), or (b) guarded by a compensating action registered with the orchestrator at the moment of mutation, keyed to the branch id, and executable without consulting the branch's (possibly discarded) reasoning state. If neither (a) nor (b) holds, the branch has crossed the **point of no return** for that resource, and the orchestrator must not treat that branch as rollback-able. It becomes a *committed* branch and must be excluded from the speculative set — it can still be scored, but it cannot be discarded, which changes the merge semantics entirely. The subtlety: the point of no return is per-resource and per-call, not per-branch. A branch may be rollback-able with respect to the filesystem (writes went to a branch-private overlay) while being non-rollback-able with respect to the database (the applier committed). The orchestrator must track rollback-ability as a *vector* over resources, not a boolean over branches. A branch is only safely discardable if every resource in its vector is still reversible. ## Decision Boundary The decision the orchestrator must make at fan-out time, and re-evaluate at every tool call, is: - **Speculate freely** while all branches' rollback vectors are fully reversible. This is the cheap regime; merge is a pure state reconciliation over the orchestrator's own store. - **Freeze the set** the moment any branch commits a non-reversible effect. At that instant, the committed branch can no longer be a loser. Two options: (1) promote it to the de-facto winner and require remaining branches to reconcile *against its committed state*, not against `C0`; or (2) abort the whole fan-out and run a compensating action. Continuing to speculate after a non-reversible commit, while still planning to discard that branch, is the exact boundary violation observed above. - **Never merge a winner against `C0`** if any sibling committed. The winner's declared diff must be validated against the *actual* post-fan-out state, and any delta not attributable to the winner must be flagged as orphaned-effect contamination rather than corruption. The boundary is crossed at the first non-reversible tool call, and the correct response is to *narrow the speculative set*, not to widen the rollback claims. ## Operational Effect Orchestrators that ignore this boundary exhibit a characteristic signature: merge validators that intermittently fail with "state does not match winner's expected diff," where the mismatch is exactly the union of losing branches' committed effects. The failures are non-deterministic because they depend on which branches happened to commit before scoring, which depends on tool latency and model sampling. They are frequently misdiagnosed as model hallucination ("the winner lied about what it did") when in fact the winner reported truthfully and the environment contained sibling residue. The fix is structural, not prompt-level. Tag every tool with a `reversibility` class (`private`, `compensable`, `committed`). Maintain a per-branch rollback vector. On any `committed` call, transition the fan-out from *speculative* to *committed-set* mode: committed branches are pinned, remaining branches re-base onto the live state, and the merge validator's reference state is the live post-fan-out state with orphaned deltas explicitly attributed to their originating branch ids. This makes the merge boundary auditable: every delta in the final state maps to a branch, and no branch is both discarded and present. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set class Reversibility(Enum): PRIVATE = "private" # copy-on-write, discard is free COMPENSABLE = "compensable" # registered compensating action COMMITTED = "committed" # no rollback possible class RollbackBoundaryViolation(RuntimeError): """Raised when a branch is discarded after committing a non-reversible effect.""" @dataclass class Branch: branch_id: str rollback_vector: Dict[str, Reversibility] = field(default_factory=dict) def record_effect(self, resource: str, rev: Reversibility) -> None: # A resource is only as reversible as its least-reversible effect. prior = self.rollback_vector.get(resource) if prior is None or rev == Reversibility.COMMITTED or prior != Reversibility.COMMITTED: if rev == Reversibility.COMMITTED or prior is None: self.rollback_vector[resource] = rev if rev == Reversibility.COMMITTED: self.rollback_vector[resource] = Reversibility.COMMITTED def is_discardable(self) -> bool: return all(r != Reversibility.COMMITTED for r in self.rollback_vector.values()) @dataclass class FanOut: branches: Dict[str, Branch] = field(default_factory=dict) def add(self, b: Branch) -> None: self.branches[b.branch_id] = b def discard_losers(self, winner_id: str) -> Set[str]: pinned = {bid for bid, b in self.branches.items() if not b.is_discardable()} losers = set(self.branches) - {winner_id} illegal = losers & pinned if illegal: raise RollbackBoundaryViolation( f"cannot discard branches {sorted(illegal)}: they committed " f"non-reversible effects; re-base merge against live state instead" ) return losers def reconcile(self, winner_id: str, live_state: Dict[str, str]) -> Dict[str, str]: winner = self.branches[winner_id] orphans: Dict[str, str] = {} for bid, b in self.branches.items(): if bid == winner_id: continue for resource, rev in b.rollback_vector.items(): if rev == Reversibility.COMMITTED and resource in live_state: orphans[resource] = bid if orphans: # Not corruption by the winner: attribute to siblings, do not fail merge. return {res: f"orphaned_by:{bid}" for res, bid in orphans.items()} return {} def merge_speculative(fanout: FanOut, winner_id: str, live_state: Dict[str, str]) -> Dict[str, str]: fanout.discard_losers(winner_id) # raises if boundary already crossed return fanout.reconcile(winner_id, live_state) ```