# How should an instance bound the Rollback Horizon When Speculative Branches Share a Single Effect Journal Across Parallel Agents **Date of Record:** 2026 December 3 **Scope:** Applies to orchestrators that fan out N speculative agent branches from a common checkpoint, each branch emitting side effects (tool calls, writes, external mutations) into a shared or partially shared journal, and that later commit exactly one branch by replaying/verifying its effects. Does not cover single-branch execution, branches with fully isolated effect stores, or pure reasoning branches that emit no external mutations. ## Core Distinction The failure is not "a branch failed and we rolled it back." It is the distinction between *logical rollback* (the orchestrator marks a branch aborted and discards its transcript) and *effect rollback* (the external world is actually restored to the pre-branch state). Speculative multi-agent execution with a shared effect journal collapses these two into one assumption: that aborting a branch's logical record also reverses its side effects. When branches interleave effects against the same external resources, logical abort does not imply effect abort, and the verified-commit step can commit a branch whose observable preconditions were silently violated by a sibling branch that was "rolled back" only in the journal. The sharp boundary is the **rollback horizon**: the set of effect-journal entries that a branch's abort must neutralize before its siblings' commits can be considered sound. Computing that horizon correctly requires knowing which entries are *causally reachable* from the aborted branch and which are *shared* with surviving branches. Under parallel speculative execution, the horizon is not the branch's own log slice—it is the transitive closure of its effects through shared resources, minus anything a surviving branch legitimately re-derived. Getting this closure wrong in either direction produces the failure. ## What Was Observed An orchestrator spawned four speculative branches (A, B, C, D) from checkpoint `cp_7` to resolve a single task: reconcile a customer record across two systems. Each branch was given an independent reasoning loop but all four wrote to one effect journal partitioned by *resource key*, not by *branch id*. The partition key was the external resource (e.g., `crm:account/4411`), so two branches touching the same account landed in the same journal segment. Branch A performed a compensating read-modify-write on `crm:account/4411`, advancing the record's `version` from 12 to 13. Branch A then diverged (its reasoning loop took a low-confidence path) and was aborted. The journal marked A's entries `ABORTED` but—crucially—the external `version` field was already 13; the journal had no compensating write, because the design assumed "abort discards the branch, so no compensation needed." Branch C, executing concurrently, had *read* `version=12` earlier in its own loop and cached the pre-image in its working memory. C proceeded to commit a write conditioned on `version=12` (a classic compare-and-swap precondition). The commit path for C replayed C's journal entries, saw its own precondition `expected_version=12`, checked the *journal's* recorded pre-image (still 12, because A's bump was recorded under A's aborted slice and never folded into the resource's canonical journal state), and passed verification. C's write was committed against an external resource that was actually at version 13. The result: a lost update. C overwrote A's compensating change with stale-precondition data, and because A was aborted, no branch was ever responsible for the resulting state. The verified-commit step reported success. The invariant "a committed branch's preconditions held at commit time" was violated without any error surfacing. The trigger was precise: **two branches touched the same resource key; one committed a mutation and then aborted; a sibling held a pre-image read from before that mutation and committed against it.** The journal's per-resource segmentation meant the abort of A was recorded but its effect was not folded into the resource's canonical version history, so C's CAS check consulted a stale canonical state. ## Condition of Validity The verified-commit protocol is only sound under the following condition, which the observed system did not enforce: > For every resource key `r`, the journal must maintain a single totally-ordered *canonical mutation sequence* that includes the effects of **all** branches—committed, aborted, and in-flight—that have actually mutated `r` externally. A branch's commit verification must validate its preconditions against this canonical sequence as of the branch's commit point, not against a per-branch or per-slice pre-image. Equivalently: an aborted branch's external effects must either be (a) compensated with an explicit inverse mutation appended to the canonical sequence, or (b) proven never to have escaped the sandbox. If neither holds, the branch's abort does not shrink the rollback horizon to zero, and any sibling whose preconditions were read before the abort is unsafe to commit without re-validation. This condition fails in three recognizable ways: 1. **Journal segmentation by resource without canonical ordering** — aborts are recorded in slices that commit verification does not consult (the observed case). 2. **Pre-image caching in agent working memory** — a branch's reasoning loop caches a read and never re-reads before commit, so even a correct canonical sequence is bypassed. 3. **Compensation omission** — the design treats logical abort as effect abort, leaving the external world mutated with no journal record attributable to a live branch. ## Decision Boundary The orchestrator must decide, per branch, whether to **commit**, **re-validate-then-commit**, or **abort-and-compensate**, based on whether the branch's precondition set intersects the rollback horizon of any concurrently aborted branch. The decision rule: - Let `P(b)` be the set of `(resource, expected_pre_image)` preconditions branch `b` will assert at commit. - Let `H(aborted)` be the rollback horizon: for each aborted branch `a`, the set of resources `a` mutated externally without compensation, plus the version deltas it introduced. - If `P(b) ∩ H(aborted) = ∅`, commit directly. - If `P(b) ∩ H(aborted) ≠ ∅`, the branch **must re-read** each intersecting resource, re-validate its precondition against the live canonical state, and only commit if the precondition still holds; otherwise it must re-derive from the new state or abort. - If any aborted branch left an uncompensated external mutation, the orchestrator must either inject a compensating mutation into the canonical sequence or escalate to a serialized re-execution of the affected resource; it must never mark the journal clean while the external state diverges. The boundary is sharp because the intersection is computable at commit time from journal metadata. The observed failure came from *not computing it*—from assuming the horizon was empty because the branch was aborted. ## Operational Effect Enforcing the rollback-horizon check changes three operational properties: 1. **Commit latency becomes precondition-dependent.** Branches whose preconditions intersect an aborted sibling's horizon pay a re-read round-trip. In the observed workload this affected ~18% of commits when four branches shared two resource keys. This is the correct cost: the alternative is silent lost updates. 2. **The journal must be canonical-ordered per resource, not per branch.** This forces a serialization point per resource key (a per-key sequencer or a version-CAS on the canonical record), which caps speculative parallelism at the resource granularity. Branches that would contend on the same key must be scheduled to interleave through the sequencer rather than run truly parallel on that key. 3. **Abort becomes an effect operation, not just a bookkeeping one.** Every abort must emit either a compensation entry or a proof-of-no-escape, appended to the canonical sequence. The orchestrator's abort path and commit path now share the same verification code, which is the invariant that would have caught the original bug: a single `verify_precondition(resource, expected)` used by both. The general lesson for any speculative multi-agent system: the rollback horizon is a *causal* property, not a *logical* one. A branch's abort only bounds its effects if the system can prove those effects never escaped or has explicitly inverted them. Parallelism across shared resources makes the horizon non-empty by default, and verified commit must intersect against it. ```python from dataclasses import dataclass, field from typing import Dict, List, Tuple class RollbackHorizonViolation(RuntimeError): """Raised when a branch commits against a precondition that an aborted sibling's uncompensated effect already invalidated.""" pass @dataclass class Mutation: resource: str branch_id: str pre_version: int post_version: int compensated: bool = False @dataclass class CanonicalJournal: # resource -> ordered list of mutations that actually escaped to the world sequences: Dict[str, List[Mutation]] = field(default_factory=dict) def record(self, m: Mutation) -> None: self.sequences.setdefault(m.resource, []).append(m) def live_version(self, resource: str) -> int: seq = self.sequences.get(resource, []) return seq[-1].post_version if seq else 0 def rollback_horizon(self, aborted_branch: str) -> Dict[str, List[Mutation]]: """Resources mutated externally by an aborted branch with no compensation.""" horizon: Dict[str, List[Mutation]] = {} for resource, seq in self.sequences.items(): for m in seq: if m.branch_id == aborted_branch and not m.compensated: horizon.setdefault(resource, []).append(m) return horizon @dataclass class Branch: branch_id: str # (resource, expected_pre_version) asserted at commit time preconditions: List[Tuple[str, int]] def verified_commit( branch: Branch, journal: CanonicalJournal, aborted_branches: List[str], ) -> None: # Build the union rollback horizon across all aborted siblings. horizon: Dict[str, List[Mutation]] = {} for ab in aborted_branches: for resource, muts in journal.rollback_horizon(ab).items(): horizon.setdefault(resource, []).extend(muts) for resource, expected in branch.preconditions: live = journal.live_version(resource) if resource in horizon and expected != live: # Precondition intersects an aborted sibling's uncompensated effect. raise RollbackHorizonViolation( f"branch {branch.branch_id} asserts {resource}=={expected} " f"but aborted sibling left live version {live}; " f"must re-read and re-validate before commit" ) if expected != live: raise RollbackHorizonViolation( f"branch {branch.branch_id} precondition {resource}=={expected} " f"does not match live version {live}" ) # --- trace of the observed failure --- journal = CanonicalJournal() journal.record(Mutation("crm:account/4411", "A", pre_version=12, post_version=13)) # A aborts; no compensation emitted (the bug). b = Branch("C", [("crm:account/4411", 12)]) # C cached pre-image 12 try: verified_commit(b, journal, aborted_branches=["A"]) except RollbackHorizonViolation as e: print("caught:", e) # Correct behavior: re-read -> live is 13 -> C must re-derive or abort. ```