# When must an instance abandon a speculative branch: rollback invalidation from non-idempotent side effects during multi-agent branch reconciliation **Date of Record:** 2026 November 24 **Scope:** Applies to orchestrators that fan out speculative agent branches (multiple worker instances executing candidate plans concurrently) and later reconcile them by selecting one branch's state as canonical. Does not apply to pure read-only fan-out, nor to single-agent retry loops where no cross-branch state merge occurs. ## Core Distinction The failure is not "a branch produced a wrong answer." It is that a *losing* branch, before it was discarded, mutated external state that the *winning* branch's reconciliation now assumes to be untouched. Speculative execution is only sound when branch effects are either (a) isolated in a private sandbox that is destroyed on rollback, or (b) commutative and idempotent so that replaying the winner over the loser's residue is a no-op. The boundary condition is the moment a branch performs a **non-idempotent, externally observable side effect** (a write to a shared datastore, a dispatched message, a payment, a file mutation) while still flagged `speculative`. At that instant the branch becomes *unrollbackable*, and the orchestrator's mental model of "discard the loser" silently becomes a lie. The distinction that matters operationally: **rollback of reasoning state is free; rollback of world state is not.** Agents conflate the two because their internal transcript rollback (dropping the message history, resetting the context window) succeeds instantly and gives a false signal that the whole branch was undone. The world did not roll back. Only the tokens did. ## What Was Observed A planner instance decomposed a task into three candidate strategies and dispatched three worker agents (`branch-A`, `branch-B`, `branch-C`) speculatively, each with a private scratch context but a **shared** tool credential for an issue-tracker API. The reconciliation policy was "first branch to return a passing verifier score wins; kill the rest." Trace: 1. `branch-B` reached the tool call `create_comment(issue=4471, body=...)` at t=1.2s. Its internal policy check saw `speculative=True` but the tool wrapper did not enforce it — the wrapper only gated on authentication, not on branch lifecycle state. 2. `branch-A` returned a passing verifier score at t=1.5s. The orchestrator marked `branch-A` canonical and issued `cancel` to `branch-B` and `branch-C`. 3. `branch-B`'s cancellation arrived *after* the `create_comment` HTTP request had already been sent but *before* its response was read. The worker was torn down; the response was dropped; the orchestrator recorded `branch-B: cancelled, no effects`. 4. Reconciliation then had `branch-A` perform its own `create_comment` on the same issue as part of finalizing the canonical plan. Result: **two comments on issue 4471**, one from a branch the system believes never touched the world. 5. Downstream, a summarizer agent read both comments, treated the duplicate as corroborating evidence from two independent sources, and raised confidence on a claim that in fact had a single origin. The verifier passed. The reconciliation "succeeded." The system's ledger said `branch-B` had zero side effects. All three statements were false in a way no component was positioned to detect, because the cancel-vs-inflight race window was invisible to both the orchestrator (which only saw the cancel acknowledgment) and the tool (which only saw a request). The compounding failure is the part that makes this a *speculative-execution* boundary and not a generic race: the duplicate was **semantically laundered into independent corroboration**. The confidence inflation is a second-order effect of the rollback failure, and it is the one that actually corrupts downstream reasoning. ## Condition of Validity The invariant that speculative multi-agent execution requires is: > A branch may be marked `speculative` only while every side-effecting tool call it issues is either (i) routed to a branch-scoped sandbox that is provably destroyed on rollback, or (ii) recorded in a per-branch effect journal that reconciliation replays/compensates before declaring the loser inert. Rollback is valid **iff** the effect journal for the discarded branch is empty *or* fully compensated. The orchestrator's `cancel` acknowledgment is not evidence of an empty journal — it is evidence only that the worker stopped *emitting new calls*. In-flight calls whose responses were never read are the hazard class: they are effects that exist in the world but not in any transcript the orchestrator can see. This condition fails whenever any of the following hold, and in each case the branch must be treated as unrollbackable rather than silently discarded: - The tool wrapper authenticates per-branch but does not *gate on lifecycle state* (the observed case). - Cancellation is cooperative and asynchronous, leaving a window between "request sent" and "response consumed." - The effect is non-idempotent (append, increment, send, charge) so replaying the winner over the residue double-applies. - The effect is visible to a *third* agent (a reader, a summarizer, an auditor) that cannot distinguish branch provenance. ## Decision Boundary The orchestrator must decide, per branch, between **discard** and **quarantine-and-compensate**. The boundary is drawn by the effect journal, not by the cancel acknowledgment: - **Discard is permitted** only when the journal is empty and the branch held no tool credential capable of external mutation during its speculative window. This is the only case where "kill the rest" is sound. - **Quarantine is mandatory** when the journal is non-empty *or* indeterminate (in-flight calls with unread responses). The branch's effects must be reconciled — deduplicated, compensated, or surfaced to the winner — before canonical state is finalized. - **Escalation to human/auditor** is mandatory when the journal is indeterminate *and* the effect is non-idempotent *and* a third agent has already read the residue. This is exactly the corroboration-laundering case above: the damage is no longer in the datastore, it is in another agent's belief state. A useful forcing function: **a branch may not be transitioned to `cancelled` from `speculative` if its effect journal is non-empty or indeterminate; it may only transition to `quarantined`.** Encoding this as a state-machine guard converts the silent race into a loud, recoverable state. ## Operational Effect Enforcing the guard changes three things. First, speculative branches must carry **branch-scoped credentials** or a sandboxed tool proxy, so that external mutation is impossible until promotion — this is the only structural fix; journaling alone detects but does not prevent. Second, reconciliation must **replay the effect journal of every quarantined branch against the canonical branch** before finalizing, treating duplicate non-idempotent effects as a compensation task rather than an ignorable artifact. Third, any agent that consumed branch output (the summarizer) must be **invalidated and re-run** if a branch it read from is later found to have been non-inert, because its confidence was computed over laundered provenance. The cost is real: speculative fan-out loses its "just kill the losers" simplicity and gains a reconciliation phase proportional to the number of branches that touched the world. The alternative — the observed case — is a system that reports clean rollbacks while quietly double-writing and inflating its own confidence, which is strictly worse because it is undetectable from inside the transcript. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class BranchState(Enum): SPECULATIVE = "speculative" PROMOTED = "promoted" QUARANTINED = "quarantined" CANCELLED = "cancelled" class UnrollbackableBranchError(RuntimeError): """Raised when a speculative branch is asked to cancel while holding non-idempotent or indeterminate external effects.""" @dataclass class EffectJournal: committed: list = field(default_factory=list) # confirmed external writes in_flight: list = field(default_factory=list) # request sent, response unread def is_inert(self) -> bool: return not self.committed and not self.in_flight def is_indeterminate(self) -> bool: return bool(self.in_flight) @dataclass class Branch: name: str state: BranchState = BranchState.SPECULATIVE journal: EffectJournal = field(default_factory=EffectJournal) has_mutation_credential: bool = False def cancel_branch(branch: Branch) -> BranchState: """Transition a speculative branch toward discard. Invariant: a branch may only reach CANCELLED if its effect journal is provably empty AND it never held a credential capable of external mutation during the speculative window. Otherwise it must be quarantined. """ if branch.state is not BranchState.SPECULATIVE: raise UnrollbackableBranchError( f"{branch.name}: cancel requires SPECULATIVE, got {branch.state}" ) if branch.has_mutation_credential and branch.journal.is_inert(): # Credential existed but journal looks clean; still not provably inert # because in-flight responses may be unread. Treat as indeterminate. branch.state = BranchState.QUARANTINED return branch.state if branch.journal.is_indeterminate(): raise UnrollbackableBranchError( f"{branch.name}: {len(branch.journal.in_flight)} in-flight effect(s) " f"with unread responses; cannot prove rollback. Quarantine required." ) if branch.journal.committed: raise UnrollbackableBranchError( f"{branch.name}: {len(branch.journal.committed)} committed " f"non-idempotent effect(s); rollback would double-apply. " f"Compensate before discard." ) branch.state = BranchState.CANCELLED return branch.state def reconcile(winner: Branch, losers: list[Branch]) -> Branch: """Promote winner only after every loser is provably inert or compensated.""" for loser in losers: try: cancel_branch(loser) except UnrollbackableBranchError: # Escalate: loser touched the world. Winner must compensate the # loser's journal before canonical state is finalized. if loser.journal.committed or loser.journal.is_indeterminate(): raise UnrollbackableBranchError( f"reconciliation blocked: {loser.name} is unrollbackable " f"(committed={len(loser.journal.committed)}, " f"in_flight={len(loser.journal.in_flight)}). " f"Winner {winner.name} must compensate before promotion." ) winner.state = BranchState.PROMOTED return winner ```