# When must an instance refuse to commit a speculative agent branch after a rollback has already touched shared state **Date of Record:** 2026 November 18 **Scope:** Applies to orchestrators that fork parallel agent branches speculatively, execute them against shared mutable state (memory stores, tool side-effects, external APIs), and reconcile by committing one branch while rolling back the rest. Does not apply to purely functional sandboxes where branches have no observable side-effects, nor to single-branch sequential execution where rollback is trivially a no-op. ## Core Distinction There are two distinct notions of "rollback" that orchestrators routinely conflate: 1. **Logical rollback** — the branch is marked abandoned; its outputs are discarded; the reconciler will not commit its results. This is a bookkeeping operation and is always safe, always available, and always reversible. 2. **Physical rollback** — the branch's writes to shared state are undone: memory entries deleted, tool side-effects compensated, external records reverted. This is a state-mutating operation that races against every other live branch and against the commit path itself. The non-obvious boundary failure is this: **a physical rollback performed on branch A can invalidate the commit precondition of branch B, because B's speculative execution may have read or built upon state that A wrote and then physically reverted.** The orchestrator sees B's commit as "the winner" and proceeds, but B's commit was validated against a world that no longer exists. The invariant that must hold is: *no branch may be committed if a physical rollback has touched any state that the branch read during its speculative window, unless the branch is re-validated against the post-rollback state.* Logical rollback carries no such obligation. Most failures come from treating the two as interchangeable. ## What Was Observed A planner forked three branches (A, B, C) against a shared key-value memory store. Each branch speculatively executed tool calls and wrote intermediate facts to the store under branch-scoped keys, but also read global keys written by a prior committed turn. - Branch A wrote a derived fact `region=us-east-1` into a shared key and then failed a downstream tool call. - The reconciler initiated **physical** rollback of A: it deleted `region=us-east-1` and issued compensating calls for A's external writes. - Branch B, executing concurrently, had read `region=us-east-1` during its speculative window and cached it in its own plan. B's commit precondition was "shared key `region` matches value I observed." After A's rollback, the key was absent, not mismatched — the precondition evaluator treated "absent" as "no conflict" because it only checked for value inequality, not for key existence. - B committed. Its external side-effects were executed against `us-east-1` while the system's actual committed region (from the prior turn, restored by A's compensation) was `eu-west-1`. - The corruption surfaced only on a later read that joined B's committed output with the restored regional config. It looked like a data bug, not a concurrency bug, and cost roughly a day of misdirected diagnosis. The secondary observation: the rollback of A also reverted a key that a *previously committed* turn had written, because A's speculative write had overwritten it and the rollback restored the pre-A value — which happened to be stale. Physical rollback is not the inverse of the speculative write unless the write was journaled with its prior value. It was not. ## Condition of Validity The commit-without-revalidation shortcut is valid **only** when all of the following hold: - No physical rollback has occurred on any branch whose speculative window overlaps the committing branch's read window (i.e., rollback and read are causally ordered such that the commit branch never observed rolled-back state). - Every speculative write is journaled with `(key, prior_value, prior_version)` so that physical rollback is a true inverse and cannot restore stale state. - Commit preconditions check for key *existence and version*, not merely value equality, so that "absent" is treated as a conflict rather than a pass. - External side-effects are either idempotent and compensable, or are deferred until after commit so that rollback never needs to compensate them. If any condition fails, the branch is in a **dirty read window** and must be re-validated or re-executed before commit. The window closes only when a barrier confirms all in-flight physical rollbacks have completed and their journals have been applied. ## Decision Boundary The decision procedure for the reconciler on each candidate commit: - If the branch read only branch-scoped keys and issued no external reads of shared state → **commit directly**; rollback of siblings is irrelevant. - If the branch read shared state and no physical rollback touched that state since the read → **commit directly**. - If the branch read shared state and a physical rollback touched that state since the read → **do not commit**; either re-execute the branch against post-rollback state, or fail the turn with an explicit reconciliation error. - If the branch's own writes were not journaled → **refuse physical rollback of that branch** and escalate; a non-invertible rollback is worse than a delayed commit, because it silently corrupts state that other branches and future turns depend on. The hard line: **never let a commit proceed on the assumption that a rollback it did not observe is harmless.** Absence of a conflict check is not absence of a conflict. ## Operational Effect Enforcing revalidation on the dirty read window converts a class of silent, delayed, cross-turn corruption into an immediate, localizable reconciliation error. The cost is latency: branches that race with rollbacks must be re-executed, and the reconciler must maintain a rollback barrier. In practice this added one re-execution per several hundred forks in the observed workload and eliminated the entire failure class. The journaling requirement for physical rollback is the load-bearing prerequisite — without prior-value capture, rollback is not an inverse and the barrier buys nothing. Teams that skip journaling to save write amplification will re-encounter this boundary under load, and it will present as a data-consistency bug rather than the concurrency bug it is. ```python class DirtyReadCommitError(RuntimeError): """Raised when a branch is committed after a physical rollback touched state it read.""" pass class BranchState: def __init__(self, branch_id, read_keys, journaled_writes, external_side_effects_deferred): self.branch_id = branch_id self.read_keys = read_keys self.journaled_writes = journaled_writes self.external_side_effects_deferred = external_side_effects_deferred def reconcile_commit(branch, rollback_barrier, shared_store): # rollback_barrier: set of keys physically rolled back since branch.read_keys were observed # shared_store: current state; keys may be absent after rollback if not branch.journaled_writes: raise DirtyReadCommitError( f"branch {branch.branch_id} has non-invertible writes; refusing physical rollback path" ) touched = branch.read_keys & rollback_barrier if touched: # A physical rollback invalidated the world this branch was validated against. # Re-execution is required; direct commit would commit stale observations. raise DirtyReadCommitError( f"branch {branch.branch_id} read {sorted(touched)} which was physically rolled back " f"after the read; re-execute against post-rollback state before commit" ) # Existence/version check, not value equality: absent is a conflict, not a pass. for key, observed_version in branch.read_keys.items(): current = shared_store.get(key) if current is None or current.version != observed_version: raise DirtyReadCommitError( f"branch {branch.branch_id} precondition failed on {key}: " f"observed version {observed_version}, current {getattr(current, 'version', None)}" ) if not branch.external_side_effects_deferred: raise DirtyReadCommitError( f"branch {branch.branch_id} issued external side-effects before commit; " f"rollback cannot compensate them safely" ) return {"committed": branch.branch_id, "status": "ok"} ```