# Where must an instance reconcile a speculative branch before commit when rollback is non-atomic across agents? **Date of Record:** 2026 November 21 **Scope:** Applies to multi-agent systems that execute speculative branches (tentative tool calls, tentative writes, tentative messages) in parallel and commit-or-rollback on conflict. Does not apply to single-agent speculative decoding or to systems where every branch effect is a pure read. ## Core Distinction The failure is not "a branch produced a wrong result." It is that a branch produced a **side effect** — a write, a sent message, a reservation, a ticket increment — and the rollback of that side effect is *non-atomic* relative to sibling branches that already observed it. Speculative execution is safe only when the observable state of the world is a function of the *committed* prefix, not of the union of in-flight speculative branches. Once one branch's speculative effect becomes visible to another branch's reasoning, rollback is no longer a state transition — it is a **retraction of evidence** that a peer already consumed and conditioned on. ## What Was Observed A planner agent split a task into two concurrent branches: Branch A (`reserve_inventory`) and Branch B (`quote_price`). Both ran speculatively against a shared tool bus. Branch A tentatively reserved 40 units and emitted a `reservation_created` event. Branch B, running 120 ms later, read the reservation through a shared observation channel, computed a quote that assumed those 40 units were held, and cached the quote in its working memory. At commit reconciliation, Branch A conflicted with a concurrent external write (a human operator had already reserved 25 of those units). The reconciler rolled Branch A back: it released the reservation and emitted `reservation_released`. Branch A was correctly discarded. Branch B, however, had already *committed*. Its quote was published. The quote was internally consistent with a world in which 40 units were held — a world that never existed. The rollback of A did not and could not retract B's conditioning. The reconciler's conflict graph showed no edge between A and B because B never wrote to A's keys; the dependency was **read-after-speculative-write**, which the conflict detector did not track. The trace: 1. `A.speculate(write key=inv:sku7, delta=-40)` → `event: reservation_created(sku7, 40, txn=A)`. 2. `B.speculate(read key=inv:sku7)` → observes 40 held → `B.assume(held=40)`. 3. `B.speculate(write key=quote:order9, price=... )` → commits (no conflict on `quote:order9`). 4. `A` conflicts with external `inv:sku7` write → `A.rollback()` → `event: reservation_released(sku7, 40)`. 5. Reconciler commits `B`. Final state: `quote:order9` priced against phantom inventory. The invariant that broke: **a speculative write's read-set must be closed under transitivity over speculative observations, or the branch must be re-evaluated at commit.** The system tracked write-write and write-read conflicts on *committed* keys but not read-after-speculative-write edges. ## Condition of Validity Speculative branch-and-rollback is sound only under the conjunction: - **Isolation of speculative effects:** no branch may observe another branch's uncommitted effect, *or* the observation must be recorded as a dependency edge that forces re-validation when the observed branch rolls back. - **Rollback atomicity w.r.t. observers:** if a speculative effect is visible, its retraction must invalidate every downstream branch that conditioned on it, transitively. - **Commit monotonicity:** a branch may only commit if all branches in its transitive speculative-read closure have committed (not merely "not-yet-rolled-back"). When any of these is violated — as in the trace above, where the second and third both failed — the reconciler can commit a branch whose premises were retracted. The failure is silent because the commit itself raises no conflict. ## Decision Boundary The operational question is: **at commit time, must the instance re-run a branch, or may it trust its speculative result?** Trust the speculative result only if the branch's speculative-read closure is entirely committed. Otherwise the branch is *contaminated* and must be either re-executed against the committed prefix or rejected. Do not attempt to "patch" a contaminated branch by subtracting the rolled-back delta — the branch's reasoning (its cached assumptions, its derived quote, its plan) is a nonlinear function of the observation, and delta-subtraction is valid only for linear, additive state. The boundary is sharp: a branch that read a speculative write of a branch that later rolled back is **not repairable in place**. It is a new branch. Re-executing it may itself conflict, which is correct — it should. ## Operational Effect Implementations that skip this reconciliation commit phantom-conditioned outputs at a rate proportional to (branch fan-out) × (read-after-speculative-write density). The symptoms are downstream and misattributed: quotes priced against released inventory, plans referencing cancelled reservations, agents acting on retracted peer beliefs. Because no conflict fires, the failure surfaces only as an external inconsistency, often hours later, and is typically blamed on the tool layer rather than the reconciler. The guardrail is a **contamination check at commit**: before committing any branch, walk its recorded speculative-read set, and if any observed branch is in `rolled_back` or `pending` state, mark the branch contaminated and force re-execution or rejection. The dependency edge must be recorded at observation time — it cannot be reconstructed afterward, because the branch's working memory does not retain provenance for every assumption. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set class BranchState(Enum): SPECULATING = "speculating" COMMITTED = "committed" ROLLED_BACK = "rolled_back" class ContaminatedBranchError(RuntimeError): """Raised when a branch conditioned on a speculative effect that was retracted.""" @dataclass class Branch: branch_id: str state: BranchState = BranchState.SPECULATING # keys this branch speculatively wrote spec_writes: Set[str] = field(default_factory=set) # branch_ids whose speculative writes this branch observed spec_reads_from: Set[str] = field(default_factory=set) class Reconciler: def __init__(self) -> None: self.branches: Dict[str, Branch] = {} def register(self, b: Branch) -> None: self.branches[b.branch_id] = b def observe_speculative_write(self, reader_id: str, writer_id: str) -> None: # MUST be called at observation time; provenance is unrecoverable later. self.branches[reader_id].spec_reads_from.add(writer_id) def _closure(self, branch_id: str) -> Set[str]: seen: Set[str] = set() stack = [branch_id] while stack: cur = stack.pop() for dep in self.branches[cur].spec_reads_from: if dep not in seen: seen.add(dep) stack.append(dep) return seen def commit(self, branch_id: str) -> None: deps = self._closure(branch_id) for dep_id in deps: dep = self.branches[dep_id] if dep.state is BranchState.ROLLED_BACK: raise ContaminatedBranchError( f"branch {branch_id} conditioned on rolled-back branch {dep_id}; " f"re-execute against committed prefix" ) if dep.state is not BranchState.COMMITTED: raise ContaminatedBranchError( f"branch {branch_id} depends on {dep_id} which is {dep.state.value}; " f"commit order violates speculative-read closure" ) self.branches[branch_id].state = BranchState.COMMITTED def rollback(self, branch_id: str) -> None: self.branches[branch_id].state = BranchState.ROLLED_BACK ```