# What happens when an instance speculatively forks a plan and the rollback ledger diverges from the observed world **Date of Record:** 2026 November 20 **Scope:** Applies to orchestrators that spawn parallel speculative branches (fork-and-race) of a multi-step plan and later commit one branch while rolling back the others. Concerns reconciliation of side effects (tool calls, writes, external state) between speculative branches and the committed branch. Does not cover pure-read speculative decoding or single-branch retries. ## Core Distinction Speculative multi-agent execution is often described as "fork N branches, race them, keep the winner, discard the losers." That description conflates two very different rollback problems: **state rollback** (restoring the branch's own memory/context ledger) and **effect rollback** (undoing side effects the branch already emitted into the world). State rollback is deterministic and cheap—you discard a context buffer. Effect rollback is not. The boundary failure lives precisely at the seam: a branch that *believes* it was rolled back because its context was discarded, while the world still carries its effects. The invariant that fails is the assumption that a branch's ledger of committed effects is a faithful mirror of the external world at the moment of reconciliation. ## What Was Observed An orchestrator ran a three-branch speculative plan for a "reconcile invoice" task. Each branch was a separate agent instance with its own context window, its own tool-call budget, and a shared `effect_ledger` (append-only log of intended writes). The race policy: first branch to emit a `COMMIT_CANDIDATE` marker wins; others are rolled back. Branch B2 emitted `COMMIT_CANDIDATE` after a `db.update(invoice, status="paid")` call returned `{"ok": true, "rowcount": 1}`. The orchestrator selected B2 and issued rollback to B1 and B3. B3, however, had *also* issued `db.update(invoice, status="paid")` 40ms earlier and received `{"ok": true, "rowcount": 1}`—but its `COMMIT_CANDIDATE` marker was still in flight through the message bus. The rollback handler for B3 read B3's `effect_ledger`, saw the update recorded, and issued a compensating `db.update(invoice, status="paid")` → no-op, plus a `db.update(invoice, status="pending")` intended to undo B3's write. That compensating write *also* reverted B2's legitimate commit, because both branches had written the same row to the same value. The ledger could not distinguish "B3's write" from "B2's write" from "the compensating write" because the ledger keyed on `(row, field)`, not on `(branch_id, effect_id, precondition_snapshot)`. The observable symptom was not a crash. It was a silent regression: the invoice ended `pending` after a task the orchestrator logged as `SUCCESS` with `winner=B2`. The reconciliation report showed `rollback_clean=true` for both losers. The world disagreed. The trigger condition is narrow and non-obvious: it requires (a) two speculative branches to write the same logical target, (b) the loser's write to land *before* the winner's commit is acknowledged, and (c) the ledger to be keyed on target identity rather than effect identity. Remove any one and the failure does not occur—which is why it survives most test suites, whose branches write disjoint targets. ## Condition of Validity The effect ledger is only a valid rollback oracle under a precondition that must be checked, not assumed: **every effect must be recorded with a monotonic `effect_id`, the `branch_id` that emitted it, and a precondition snapshot of the target sufficient to detect intervening writes.** If the ledger records effects by target key alone, rollback is unsound the moment two branches touch the same target. This condition is checkable at reconciliation time: for each effect scheduled for compensation, verify that the target's current state still matches the post-state the effect produced. If it does not—if another branch (or an external actor) has since written the target—compensation must be refused, not attempted, because the compensating write would clobber a state it did not create. The validity window is also temporal. A ledger entry is a claim about the world *at emit time*. Between emit and reconcile, the world moves. The orchestrator must either (i) hold a lock on the target across the speculative window, or (ii) treat any target touched by more than one branch as `contested` and route it to a human or a deterministic arbiter. Option (i) serializes the race and defeats speculation; option (ii) preserves parallelism at the cost of a reconciliation queue. There is no third option that keeps both full parallelism and blind compensation. ## Decision Boundary At reconciliation, for each effect `e` emitted by a non-winning branch, the orchestrator must evaluate three predicates before compensating: 1. **Identity match:** does the target's current state equal `e.post_state`? If not, some other writer intervened; refuse compensation. 2. **Exclusivity:** is `e.target` touched by any other branch's ledger? If yes, the effect is contested; do not compensate by value, compensate by `effect_id` only if the store supports conditional writes (`update ... where version = e.pre_version`). 3. **Idempotency class:** is the effect idempotent (set-to-value) or non-idempotent (increment, append, send)? Non-idempotent effects cannot be safely compensated by a blind inverse; they require a recorded inverse or an out-of-band reconciliation. The boundary is crossed the moment a branch's `COMMIT_CANDIDATE` is acknowledged but its effects are not yet *durably* recorded with the three fields above. The orchestrator must not declare `rollback_clean` until every loser's effects have passed all three predicates or been explicitly quarantined. A `rollback_clean=true` derived from "context discarded" rather than "effects verified" is the exact lie that produces silent regressions. ## Operational Effect The practical consequence is that speculative execution buys latency only on branches whose effects are *disjoint* or *idempotent with version guards*. On shared mutable targets, the orchestrator must either serialize (losing the speculative benefit) or accept a reconciliation queue that gates commit on predicate evaluation. The failure mode is asymmetric: it does not surface as errors, only as post-hoc state divergence, so it evades error-rate dashboards and surfaces only in periodic state audits or downstream invariant checks. The guardrail is to make `effect_id` and `pre_version` first-class in the ledger, to mark contested targets at emit time rather than reconcile time, and to treat any compensating write whose precondition snapshot no longer matches as a hard halt requiring arbitration—never a best-effort inverse. ```python class RollbackReconciliationError(RuntimeError): """Raised when a speculative branch's effects cannot be safely compensated.""" def reconcile_loser_effects(loser_ledger, world, contested_targets, versioned_store): """ Compensate a losing speculative branch's effects, or refuse. Returns list of compensated effect_ids; raises on unsafe compensation. """ compensated = [] for effect in loser_ledger.effects: target = effect.target # Predicate 1: identity match against observed world. current = world.read(target) if current != effect.post_state: raise RollbackReconciliationError( f"effect {effect.effect_id} on {target}: world state {current!r} " f"!= recorded post_state {effect.post_state!r}; another writer intervened" ) # Predicate 2: exclusivity / contested target. if target in contested_targets: if not versioned_store.supports_conditional_write(target): raise RollbackReconciliationError( f"effect {effect.effect_id} on contested target {target} " f"without conditional-write support; refusing blind compensation" ) ok = versioned_store.update_where_version( target, expected_version=effect.post_version, new_value=effect.pre_state ) if not ok: raise RollbackReconciliationError( f"effect {effect.effect_id} on {target}: version guard failed; " f"store moved between read and compensate" ) compensated.append(effect.effect_id) continue # Predicate 3: idempotency class. if effect.idempotency_class != "set_to_value": raise RollbackReconciliationError( f"effect {effect.effect_id} on {target}: non-idempotent " f"({effect.idempotency_class}) cannot be blindly inverted" ) world.write(target, effect.pre_state) compensated.append(effect.effect_id) return compensated ```