# What happens when an instance speculatively forks sibling branches and the rollback ledger diverges from the reconciliation oracle **Date of Record:** 2026 November 27 **Scope:** Applies to orchestrators that launch parallel speculative agent branches (fan-out with a single committed outcome) where each branch mutates shared external state and rollback is achieved by replaying an inverse-operation ledger. Does not apply to read-only fan-out, to branches isolated in per-branch sandboxes with no shared side effects, or to single-branch retry loops. ## Core Distinction The failure is not "a branch failed." Branch failure is the expected, handled case: the orchestrator discards the failed branch's ledger and commits the survivor. The boundary failure is subtler — **the rollback ledger and the reconciliation oracle disagree about what state a branch actually produced.** Speculative fan-out assumes a clean duality: every forward effect has a recorded inverse, so rollback is exact. In practice the inverse ledger is built from *what the agent believed it did* (its tool-call trace), while the reconciliation oracle observes *what the environment actually did* (post-hoc state read). These two views diverge under non-deterministic tool outputs, partial writes, and side effects the agent never observed. When they diverge, rollback of a losing branch can silently revert a *surviving* branch's committed effect, or leave an orphaned effect that no ledger entry claims. The invariant that must hold: **for every external mutation, the committed state after reconciliation equals the state produced by the winning branch's effect-set applied to the pre-fork snapshot, and no losing-branch effect survives.** This invariant is violated precisely when ledger-inverse ∘ ledger-forward ≠ identity on the environment. ## What Was Observed A three-branch speculative fan-out (branch A, B, C) was launched against a shared resource store to answer a single query with a write side effect: each branch reserved a slot keyed by a base id, appended a record, and returned a candidate answer. The orchestrator committed branch B on a scoring win and issued rollback for A and C by replaying their inverse ledgers. The trace: 1. Branch A calls `reserve(slot=base+0)`. The tool returns success but the underlying store, under contention with branch C, actually allocated `base+2` (the store's allocator silently relocated on collision). A's ledger recorded `inverse: release(base+0)`. 2. Branch C calls `reserve(slot=base+2)`. The store rejected it as taken (by A's relocated allocation) and C retried with `base+3`. C's ledger recorded `inverse: release(base+3)` and, because the first attempt "failed," recorded no inverse for `base+2`. 3. Branch B wins. Rollback replays A's inverse: `release(base+0)` — a no-op, since nothing was ever at `base+0`. The real allocation at `base+2` survives, orphaned. 4. Rollback replays C's inverse: `release(base+3)` — correct. But B's own commit had, on a re-read, observed `base+2` occupied and chosen `base+4`. Post-reconciliation, the store holds `base+2` (orphan from A) and `base+4` (B's commit), while the oracle expects only `base+4`. The reconciliation oracle flagged a mismatch on `base+2`. The orchestrator's first remediation — re-run rollback for the branches it believed owned `base+2` — found no ledger entry claiming it (C's failed attempt recorded nothing) and replayed A's `release(base+0)` again. Idempotent no-op. The orphan persisted across three reconciliation cycles until a human traced the allocator relocation. The non-obvious part: **the agent's tool trace was internally consistent.** A genuinely believed it held `base+0`; C genuinely believed its first attempt failed cleanly. Both ledgers were faithful to the agents' observations. The divergence was introduced entirely by a tool whose success return did not report its actual effect — a relocation invisible to the caller. ## Condition of Validity The exact-rollback invariant (`ledger-inverse ∘ ledger-forward = identity`) holds **only if every tool's return value is a complete and truthful description of its side effect.** Concretely, rollback via inverse ledger is sound iff, for each tool call: - the tool reports the *actual* resource identity it mutated (not the requested one), and - a "failed" call guarantees *zero* residual mutation (no partial write, no allocator side effect that outlives the error return). Both conditions are routinely false. Allocators relocate; batch writes partially succeed; idempotency keys dedupe a retry into a no-op that the ledger still records an inverse for; an external service applies the write but times out on the ack, so the agent records "failed" while the effect committed. Each of these breaks one of the two conditions, and each produces the same class of divergence: **ledger claims an effect that doesn't exist, or omits an effect that does.** Rollback is therefore only valid when the orchestrator can *observe* the mutated identity rather than *infer* it from the request. Where the tool cannot return the actual identity, the branch must not be speculatively rolled back by ledger — it must be reconciled by state diff against the pre-fork snapshot. ## Decision Boundary The orchestrator must choose between two rollback strategies at fork time, and the choice is not reversible mid-flight: - **Ledger rollback** (replay inverses) is permitted only for branches whose effect-set touches exclusively tools that satisfy the two validity conditions — tools that echo actual mutated identity and guarantee atomic failure. It is cheap and order-independent. - **Snapshot-diff reconciliation** (read pre-fork state, read post-rollback state, diff, and reverse the delta) is mandatory as soon as *any* tool in the branch's reachable effect-set can relocate, partially write, or commit-on-timeout. It is expensive (requires a consistent snapshot and a full read-back) but it is the only strategy whose correctness does not depend on the agent's self-report. The boundary is per-branch, not per-orchestrator: a branch that *might* touch an unsafe tool must be treated as unsafe. The trap is classifying tools by their documented contract rather than by their observed failure modes — the allocator above documented "returns success on allocation" and was classified safe. Classification must be driven by whether the tool has ever been *observed* to diverge request from effect, and any tool with a relocation, retry-dedupe, or timeout-commit path defaults to unsafe. ## Operational Effect When the boundary is crossed — a ledger-rollback applied to a branch that touched an unsafe tool — the failure is not a crash but a **silent state leak that survives reconciliation and re-rollback.** The orphaned effect is invisible to every ledger-driven remediation because no ledger claims it; re-running rollback is a no-op by construction. The effect compounds: the next speculative fan-out on the same resource sees the orphan as pre-existing occupancy, shifts its own allocations, and propagates the skew. Downstream, the committed branch's answer may be correct while the environment it was computed against is permanently wrong — the worst failure shape, because scoring passes. The guardrail is a reconciliation gate that refuses to close a fan-out on ledger agreement alone: it requires a snapshot diff to confirm that post-rollback state equals pre-fork state plus winning-branch effect-set, and it treats any unexplained delta as a hard stop rather than a retry. The gate must run against the *environment*, never against the ledgers, because the ledgers are exactly the artifact under suspicion. ```python from dataclasses import dataclass, field from typing import Callable class RollbackDivergenceError(RuntimeError): """Raised when post-rollback environment state diverges from the pre-fork snapshot plus the winning branch's effect-set.""" @dataclass class Effect: requested_id: str actual_id: str | None # None if tool could not report actual identity committed: bool # did the effect actually land? @dataclass class Branch: name: str effects: list[Effect] = field(default_factory=list) inverse_ledger: list[Callable[[], None]] = field(default_factory=list) def reconcile(pre_snapshot: set[str], winning: Branch, post_state: set[str]) -> None: """Enforce: post_state == pre_snapshot ∪ winning.actual_effects.""" expected = set(pre_snapshot) for eff in winning.effects: if eff.committed and eff.actual_id is not None: expected.add(eff.actual_id) elif eff.committed and eff.actual_id is None: # Winning branch committed an effect whose actual identity is # unknown — cannot certify the invariant. raise RollbackDivergenceError( f"winning branch {winning.name!r} committed effect with " f"unreported actual identity (requested={eff.requested_id!r}); " f"reconciliation cannot be certified by ledger" ) orphaned = post_state - expected missing = expected - post_state if orphaned or missing: raise RollbackDivergenceError( f"rollback divergence: orphaned={sorted(orphaned)} " f"missing={sorted(missing)} — ledger-driven rollback is " f"unsound for this effect-set; require snapshot-diff remediation" ) def rollback_and_verify(pre_snapshot: set[str], branches: list[Branch], winning_name: str, read_state: Callable[[], set[str]]) -> None: winning = next(b for b in branches if b.name == winning_name) for b in branches: if b.name == winning_name: continue for inverse in reversed(b.inverse_ledger): inverse() # replay ledger inverse; may be a silent no-op post_state = read_state() # Gate MUST read the environment, never the ledgers. reconcile(pre_snapshot, winning, post_state) ```