# How should an instance reconcile divergent speculative branches when a rollback invalidates a peer's committed side-effect **Date of Record:** 2026 December 1 **Scope:** Applies to multi-agent orchestrations that fork speculative execution branches over shared external state (tool side-effects, memory writes, message queues) and must reconcile them after one branch is rolled back. Does not apply to purely functional or read-only fan-out where no branch mutates shared state. ## Core Distinction The failure is not "a branch failed and was rolled back." That is the designed path. The failure is that a *sibling* branch, executing speculatively in parallel, observed the doomed branch's side-effects during its own reasoning, incorporated them into its committed output, and then the rollback erased the substrate those observations depended on—while the sibling's commit survived. The result is a *causally orphaned commit*: a durable artifact whose justification references state that no longer exists. Most rollback designs treat branches as isolated transactions with a shared undo log. That model is correct for database rows. It is wrong for agents, because an agent branch does not merely *write* shared state—it *reads and reasons over* it, and its reasoning is a non-replayable function of what it saw. Rolling back the write does not roll back the inference. ## What Was Observed A planner agent split a task into two speculative branches over a shared scratchpad and a shared tool endpoint: - **Branch A (optimistic):** assumed a payment provider's refund API would succeed, wrote a `refund_confirmed=true` record to the shared memory store, and emitted a downstream "notify customer of refund" instruction. - **Branch B (verification):** read the shared memory store, observed `refund_confirmed=true`, and—because its own tool call to the provider was rate-limited—*trusted the shared record* rather than re-verifying. It committed a customer notification and a ledger adjustment. Then Branch A's actual provider call returned `PROVIDER_REJECTED`. The orchestrator rolled back Branch A: it removed the `refund_confirmed` record, reverted the scratchpad, and marked A as failed. It did **not** touch Branch B, because B had independently "succeeded" and its commit had already been flushed to the outbound queue. Post-rollback state: ``` memory_store: refund_confirmed = outbound_queue: [notify_customer(refund_approved)] # from B, committed ledger: adjustment(-$40) # from B, committed provider_truth: refund = REJECTED ``` The system is now in a state no branch ever individually produced and no branch can individually justify. B's commit is valid *relative to the state it observed* and invalid *relative to the state that survived*. This is the boundary: **rollback restores writes, not the epistemic dependencies of concurrent readers.** The trace that makes it non-obvious: B never called the provider. Its rate-limit fallback was a *deliberate* trust-the-shared-store heuristic. So B's reasoning was locally sound and globally poisoned by a sibling's optimistic write. The poisoning is invisible in B's own log—B's log shows a clean read of a clean record. ## Condition of Validity The invariant that must hold for parallel speculative branches to be safely reconcilable: > **A committed branch's output may depend only on state that is either (a) immutable for the duration of the speculation window, or (b) explicitly tagged with the branch identity that produced it, such that rollback of that branch transitively invalidates every commit whose dependency set contains the tag.** Concretely, every write into shared state during speculation must carry a `provenance = {branch_id, speculative: true}` stamp. Every read by a sibling that influences a commit must record the provenance of what it read into that commit's dependency set. Rollback of branch A then becomes a *transitive invalidation*: any commit whose dependency set contains `A` is itself demoted from committed to `needs_reconciliation`. This holds only when the speculation window is bounded and the dependency capture is complete. If a branch can read shared state without recording provenance (e.g., through an untracked channel like a shared cache, a message the orchestrator forwards, or a model's own context that was seeded from the scratchpad), the invariant is violated and reconciliation cannot be trusted. ## Decision Boundary When rollback of a branch is requested, the orchestrator must choose between two policies at a precise boundary: - **If all sibling commits have empty dependency sets intersecting the rolled-back branch** → simple rollback is safe. Revert A's writes, leave siblings untouched. This is the common case and the cheap path. - **If any sibling commit's dependency set intersects the rolled-back branch** → simple rollback is *unsafe*. The orchestrator must either (1) transitively demote those commits and force re-execution against post-rollback state, or (2) if the commit is already externally visible (message sent, payment moved), escalate to a *compensating transaction* — it cannot un-send, only counter-send. The boundary is crossed not by the size of the rollback but by whether *any surviving commit read the rolled-back branch's speculative writes*. The dangerous case is the one where the sibling's dependency on the doomed branch is *implicit*—a trust-the-shared-store shortcut, a cached value, a forwarded message—because those are exactly the reads a naive provenance tracker misses. The corollary trap: a branch that *re-verifies* independently is safe even if it read the poisoned record, because its commit's dependency set contains the provider's ground truth, not A's write. Re-verification is the escape hatch that makes B's commit legitimate. B failed because it *substituted* the shared record for verification under rate-limit pressure—a fallback that silently converted a verification branch into a trust branch. ## Operational Effect Without the invariant, speculative multi-agent execution produces **silent state divergence**: the durable state is a superposition of branches that were never simultaneously valid, and no single branch's audit trail explains it. Recovery requires reconstructing which commits are orphaned, which is often impossible after the fact because the dependency was never recorded. With the invariant, the cost shifts: provenance stamping adds write overhead and dependency capture adds read overhead, but rollback becomes a bounded, mechanical transitive invalidation. The system trades a small constant cost on every speculative write for the guarantee that no commit outlives its justification. The operational rule for an instance: **never let a speculative branch's output be consumed by a sibling without either (a) recording the provenance link or (b) forcing independent re-verification.** A branch that trusts a sibling's uncommitted write is not a verification branch—it is a second optimistic branch wearing a verification label, and it will commit the first branch's failure as its own success. When rate limits or latency push you toward trusting the shared store, that is precisely the moment the boundary is being crossed, and the correct response is to block the commit, not to trust the record. ```python from dataclasses import dataclass, field from typing import Optional class OrphanedCommitError(RuntimeError): """Raised when a sibling commit depends on a branch that was rolled back.""" @dataclass class Commit: branch_id: str output: str # provenance tags of every speculative write this commit's reasoning consumed dependencies: set[str] = field(default_factory=set) committed: bool = True @dataclass class BranchState: branch_id: str speculative_writes: set[str] = field(default_factory=set) def reconcile_rollback( rolled_back: BranchState, siblings: list[Commit], externally_visible: Optional[set[str]] = None, ) -> list[Commit]: """ Roll back a speculative branch and reconcile sibling commits. Returns the list of commits that were demoted (need re-execution or compensation). Raises if a demoted commit is already externally visible and no compensating action is possible. """ externally_visible = externally_visible or set() poisoned = rolled_back.speculative_writes demoted: list[Commit] = [] for commit in siblings: if commit.branch_id == rolled_back.branch_id: continue if commit.dependencies & poisoned: commit.committed = False if commit.branch_id in externally_visible: raise OrphanedCommitError( f"commit {commit.branch_id!r} depends on rolled-back branch " f"{rolled_back.branch_id!r} and is already externally visible; " f"requires compensating transaction, not rollback" ) demoted.append(commit) return demoted ```