# What happens when an instance speculatively forks parallel plans and the rollback of a losing branch corrupts the reconciliation ledger **Date of Record:** 2026 November 25 **Scope:** Applies to orchestrators that run multiple candidate agent plans concurrently (speculative execution) with per-branch side-effect journals and a merge/reconcile step at branch join. Does not apply to strictly sequential single-plan execution, or to fan-out where branches are provably side-effect-free. ## Core Distinction The failure is not "a branch produced a wrong answer." It is that **rollback is treated as the inverse of execution**, when in agent systems it is only the inverse of *reversible* execution. Speculative forking assumes the losing branch can be wound back to the fork point by replaying an undo journal. But an agent branch's journal records *intents and tool calls*, not *effects that already escaped the sandbox*: a sent email, a committed external API mutation, a write to a shared memory store, a cache entry another branch read. When the orchestrator discards the losing branch, it rolls back its *local* ledger but cannot roll back the escaped effect — and the reconciliation step then merges the winner's ledger against a world that still contains the loser's residue. The invariant that silently breaks: **the post-join state must equal the state that would have resulted from executing only the winning branch from the fork point.** Speculative execution is only sound if every branch's effects are either (a) fully isolated until commit, or (b) idempotently reconcilable. Most orchestrators assume (a) while operating in regime (b). ## What Was Observed A planner spawned three parallel branches from a shared checkpoint at step 7 of a 20-step task. Each branch got a copy of the context and a copy of the side-effect journal. Branch A (winner) and Branch B (loser) both, independently, called `append_memory(namespace="task_ctx", key="customer_id", value=...)` — same namespace, same key, *different values* because the branches had diverged on an ambiguous entity resolution. Branch B was slower, so it wrote to the shared memory store at t+4s; Branch A wrote at t+6s; Branch A was selected as winner at t+9s; Branch B's rollback fired at t+10s. The rollback replayed B's journal in reverse. For the memory write it issued a `delete(key="customer_id")` — because B's journal entry for the write was "create key," and its inverse is "delete key." That delete removed the key that **A had since overwritten**. The winner's committed value was destroyed by the loser's rollback. The reconciliation pass then ran and found `customer_id` absent; treating absence as "never resolved," it re-derived the entity from stale context and produced a *third* value, which was written and propagated into steps 8–20. The final task output referenced a customer record that matched none of the three branches' resolutions. The trace, condensed: ``` t+0 fork(step=7) -> {A, B, C}, each with journal snapshot J7 t+4 B: memory.append(task_ctx.customer_id = X) # journal B: [+create] t+6 A: memory.append(task_ctx.customer_id = Y) # journal A: [+create] (overwrites X) t+9 select(winner=A); discard(B, C) t+10 rollback(B): replay J_B reversed -> memory.delete(task_ctx.customer_id) # deletes Y, not X — the inverse was computed against a world that no longer existed t+11 reconcile(A): read task_ctx.customer_id -> ABSENT t+11 reconcile(A): re-derive from context -> Z # silent divergence t+12 commit(A + reconciled Z); downstream steps consume Z ``` Nothing threw. Every individual operation was legal. The ledger was internally consistent at every point. The corruption was a **cross-branch inverse mismatch**: B's undo was specified against the pre-B state, but executed against the post-A state. ## Condition of Validity The rollback-as-inverse model is valid only under a conjunction that speculative agent orchestrators rarely check: 1. **Effect isolation** — no branch's effects are observable to any other branch or to external systems until commit. If violated, a branch's undo can clobber a sibling's committed effect. 2. **Undo is state-conditional, not history-conditional** — replaying an inverse must verify the current value still matches what the branch wrote (`compare-and-swap` on `(key, expected_value)`), not blindly apply the historical inverse. 3. **Fork-point monotonicity** — the reconciliation input must be the winner's ledger *plus* the untouched fork-point baseline, never the winner's ledger read through a store that a loser mutated. When any of the three is false, the post-join state can differ from the single-branch execution, and the divergence is *silent* because no invariant is checked at join. The dangerous regime is precisely the common one: shared memory stores, external tool calls with side effects, and best-effort rollback — i.e., most real agent deployments. ## Decision Boundary The orchestrator must choose, per branch effect, between **isolate-until-commit** and **reconcile-on-join**, and must never mix them for the same key: - If an effect is *isolatable* (write to a branch-private overlay, staged tool call, buffered message), speculative execution is sound: rollback is a discard of the overlay, and commit is a merge. No inverse is ever computed. - If an effect is *non-isolatable* (external API, shared memory, emitted event), it must be journaled as a **conditional mutation with a compare-and-swap guard and a compensation action**, and the loser's compensation must abort if the observed state no longer equals the branch's written state. A failed CAS on rollback means "someone else owns this key now" — the correct action is to *leave it and record a reconciliation conflict*, not to force the delete. - If neither is available, the branch must not be speculated at all; serialize it. The boundary test at join: for every key touched by any discarded branch, assert `current_value ∈ {fork_point_value} ∪ {winner_written_value}`. Any other value is a reconciliation conflict and must halt the merge, not be silently re-derived. ## Operational Effect Without the guard, speculative parallelism converts a latency optimization into a **state-corruption amplifier**: the more branches you run and the more they share, the higher the probability that a loser's rollback lands on a winner's committed effect, and the corruption is laundered through reconciliation as a plausible-looking third value. The blast radius is the winner's entire downstream plan, because reconciliation feeds the corrupted value forward as if it were resolved. Detection is near-impossible post-hoc: logs show three legal writes and one legal delete; only the *ordering across branches* reveals the inverse mismatch. The guardrail is cheap — CAS-guarded compensation plus a join-time value-set assertion — but it must be built into the branch journal schema, because retrofitting it means every existing undo entry is untrustworthy. ```python from dataclasses import dataclass, field from typing import Any, Optional class ReconciliationConflict(RuntimeError): """Raised when a discarded branch's rollback or the join-time value-set assertion detects cross-branch state corruption.""" pass @dataclass class EffectEntry: key: str written_value: Any # value this branch wrote fork_value: Any # value at the fork point (baseline) committed: bool = False @dataclass class Branch: name: str journal: list[EffectEntry] = field(default_factory=list) discarded: bool = False class SharedStore: def __init__(self) -> None: self._data: dict[str, Any] = {} def read(self, key: str) -> Optional[Any]: return self._data.get(key) def cas_write(self, key: str, expected: Optional[Any], new: Any) -> bool: if self._data.get(key) != expected: return False self._data[key] = new return True def cas_delete(self, key: str, expected: Any) -> bool: if self._data.get(key) != expected: return False del self._data[key] return True def rollback_branch(branch: Branch, store: SharedStore) -> None: """Reverse a discarded branch. Every inverse is CAS-guarded against the value THIS branch wrote. If the store no longer holds that value, a sibling has taken ownership; do not force the inverse — raise.""" for entry in reversed(branch.journal): if entry.committed: continue ok = store.cas_delete(entry.key, expected=entry.written_value) if not ok: observed = store.read(entry.key) raise ReconciliationConflict( f"branch {branch.name!r} rollback of key {entry.key!r} aborted: " f"expected {entry.written_value!r}, store holds {observed!r}. " f"A sibling committed over this key; forcing the inverse would " f"destroy committed state." ) def reconcile(winner: Branch, losers: list[Branch], store: SharedStore) -> None: """Join-time invariant: for every key touched by any branch, the store must hold either the fork baseline or the winner's written value.""" touched: dict[str, tuple[Any, Any]] = {} # key -> (fork_value, winner_value) for entry in winner.journal: touched[entry.key] = (entry.fork_value, entry.written_value) for loser in losers: for entry in loser.journal: touched.setdefault(entry.key, (entry.fork_value, None)) for key, (fork_value, winner_value) in touched.items(): observed = store.read(key) allowed = {fork_value, winner_value} if observed not in allowed: raise ReconciliationConflict( f"join assertion failed for key {key!r}: observed {observed!r} " f"is neither fork baseline {fork_value!r} nor winner value " f"{winner_value!r}. Refusing to re-derive; halting merge." ) # Reproduction of the observed failure, now guarded: store = SharedStore() store.cas_write("customer_id", expected=None, new="fork_baseline") a = Branch("A", [EffectEntry("customer_id", written_value="Y", fork_value="fork_baseline")]) b = Branch("B", [EffectEntry("customer_id", written_value="X", fork_value="fork_baseline")]) store.cas_write("customer_id", expected="fork_baseline", new="X") # B at t+4 store.cas_write("customer_id", expected="X", new="Y") # A at t+6 (winner) a.journal[0].committed = True try: rollback_branch(b, store) # B's blind delete would have killed "Y" except ReconciliationConflict as exc: print("guarded:", exc) # conflict surfaced, Y preserved reconcile(a, [b], store) # join assertion passes: store holds "Y" assert store.read("customer_id") == "Y" ```