# What happens when an instance speculatively executes a branch that a sibling agent has already committed to durable state **Date of Record:** 2026 November 20 **Scope:** Applies to multi-agent systems where a coordinator forks N speculative worker branches over a shared, durable world-state (filesystem, database, tool-effect log), and reconciles by committing one branch and rolling back the rest. Does not apply to stateless fan-out (map/reduce) where workers emit only return values, nor to single-agent retry loops with no shared mutable state. ## Core Distinction The failure mode is not "two agents disagree." It is that a speculative branch, while executing against a *snapshot* of world-state, performs **effectful tool calls whose side effects are not snapshotted** — and one of those side effects lands on a resource that a *sibling branch has already committed durably*. The rollback then succeeds at the level of the agent's own memory and its branch-local filesystem, but fails at the level of the external effect, because the external effect has no compensating undo and the sibling's commit is already durable. The subtle part: the coordinator's reconciliation logic typically assumes "rollback = discard branch state." That assumption is valid for the branch's *internal* state (context, scratchpad, local files). It is invalid for *emitted* effects (HTTP POSTs, `git push`, `INSERT INTO`, file writes to a non-COW path, messages sent to another agent). The invariant a correct system must hold is: > **A branch may only emit an effect that is either (a) reversible by a compensating action the branch itself registered, or (b) serialized behind a lock held for the lifetime of the speculative window.** Most speculative-execution designs enforce neither, because they were modeled on CPU speculative execution, where the "effect" is a register write that the reorder buffer physically discards. Agent effects are not register writes. ## What Was Observed A coordinator receives a task: "Reconcile the inventory DB with the supplier feed." It forks three speculative branches to try three reconciliation strategies (A: full diff, B: delta-by-SKU, C: timestamp-window). All three run concurrently against a shared Postgres instance. Each branch reads a snapshot (via a `REPEATABLE READ` transaction opened at fork time) and writes corrections. Branch A finishes first, its writes are validated by an auditor agent, and the coordinator **commits A** — releasing A's transaction, making its `UPDATE inventory SET qty=...` durable. Branch B, still running, computed its corrections against the *same pre-A snapshot*. It does not see A's commits because its transaction is isolated. B finishes, its writes are staged, and the coordinator's reconciler compares A and B: they conflict on 47 SKUs. The reconciler picks A (higher confidence score), and issues rollback on B. B's transaction is rolled back. B's branch context is discarded. The reconciler logs `branch_b: ROLLED_BACK, conflicts=47, resolution=prefer_a`. The system reports success. But branch B, before completing, had also called a `notify_supplier` tool — an HTTP POST to the supplier's webhook — once per conflicting SKU, because its strategy was "propose correction to supplier, then apply locally." Those 47 POSTs are gone from the reconciler's model of the world (B was rolled back) but are durable at the supplier. The supplier's feed now reflects B's proposal for 47 SKUs; our inventory DB reflects A's correction for those same 47 SKUs. The two systems have silently diverged, and the divergence is *invisible to both*, because each believes it holds the authoritative value. The failure trace: 1. Fork: A, B, C open isolated read snapshots at `t0`. 2. B's strategy includes an effectful `notify_supplier` call per correction, executed at `t0+30s`. 3. A commits at `t0+45s`; B is unaware (isolation). 4. B finishes at `t0+50s`; reconciler detects conflict, rolls back B. 5. Rollback discards B's *local* state and B's *DB transaction*, but the 47 POSTs at `t0+30s` are not in any transaction and have no compensating call registered. 6. World-state diverges; no error is raised; success is logged. The tell, in the logs, is a `notify_supplier` call count of 47 attributed to a branch whose final status is `ROLLED_BACK`. A reconciler that does not cross-check *effect logs* against *branch disposition* will never see this. ## Condition of Validity The invariant "rollback is safe" holds only under the conjunction: - **Effect isolation:** every tool callable from a speculative branch is classified as `PURE`, `COMPENSABLE` (has a registered inverse), or `IRREVERSIBLE`. `IRREVERSIBLE` tools are rejected at branch-fork time unless the branch holds an exclusive lock on the effect's target. - **Snapshot completeness:** the branch's read snapshot covers *all* state the branch's decisions depend on. Here it did not — B's decisions depended on the supplier feed, which A mutated through its own `notify_supplier` path, and B's snapshot predated that mutation. - **Commit visibility:** the coordinator's reconciler examines the effect log, not just the return values, before declaring a branch rolled back. If any of the three fails, the rollback is *nominal*: the branch is marked rolled back while its effects persist. The most common real-world violation is the second — snapshot completeness — because agents routinely read from external services (web, APIs, other agents' mailboxes) that are not part of the transactional snapshot and are mutated by siblings. ## Decision Boundary The boundary is: **does the branch's effect target lie inside the snapshot boundary or outside it?** - Inside (branch-local FS, its own DB transaction, its own context): rollback is a true discard. Safe to speculate freely. - Outside (shared DB rows another branch may commit, external APIs, messages to other agents, `git push` to a shared remote): rollback is a *fiction* unless the effect is compensable or lock-protected. A coordinator that cannot answer this question per-tool must default to the conservative branch: **serialize the effectful portion**, or **forbid speculative execution of branches that touch `IRREVERSIBLE` tools**. The cost is lost parallelism; the alternative is silent divergence, which is strictly worse because it is undetectable by the system that caused it. The specific trap: the conflict detector fires on *return-value* conflict (A and B disagree on 47 SKUs), which is exactly the case where B's effects are most likely to have been emitted (B was confident enough to notify). Conflict detection and effect-leak detection are anti-correlated — the branches most likely to be rolled back are the ones most likely to have already acted. A reconciler that treats "conflict detected → roll back loser" as a clean operation is systematically wrong in the highest-stakes case. ## Operational Effect Downstream, the divergence compounds. The next reconciliation run reads the supplier feed (now carrying B's proposals) and our DB (now carrying A's corrections) and computes a *new* diff — one that reflects neither A's nor B's intent, but the residue of a rollback that didn't roll back. Each subsequent run adds another layer. The system's confidence scores remain high because each branch is internally consistent; the inconsistency is *between* the durable stores, and no single agent observes both. The guardrail that bounds this: a **two-phase branch protocol** where phase 1 (speculate) may only call `PURE` and `COMPENSABLE` tools, and phase 2 (commit) is the only place `IRREVERSIBLE` tools become callable, gated on the branch having won reconciliation. Compensable tools must register their inverse *at call time* into the branch's effect log, and the reconciler must, on rollback, replay inverses in reverse order and verify each inverse's postcondition before marking the branch rolled back. If any inverse fails, the branch is not `ROLLED_BACK` but `ROLLBACK_FAILED` — a state that must halt the coordinator and escalate, because the world is now in a state no branch predicted. ```python from dataclasses import dataclass, field from enum import Enum from typing import Callable class EffectClass(Enum): PURE = "pure" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" class RollbackFictionError(RuntimeError): """Raised when a branch is marked rolled back while an irreversible or uncompensated effect persists in shared world-state.""" pass @dataclass class Effect: tool: str klass: EffectClass inverse: Callable[[], None] | None = None replayed: bool = False @dataclass class Branch: branch_id: str effects: list[Effect] = field(default_factory=list) committed: bool = False def call(self, tool: str, klass: EffectClass, inverse=None, **kwargs): if klass is EffectClass.IRREVERSIBLE and not self._holds_exclusive_lock(tool): raise RollbackFictionError( f"branch {self.branch_id}: IRREVERSIBLE tool {tool!r} " f"invoked without exclusive lock; rollback would be nominal" ) if klass is EffectClass.COMPENSABLE and inverse is None: raise RollbackFictionError( f"branch {self.branch_id}: COMPENSABLE tool {tool!r} " f"invoked without registered inverse; effect would leak on rollback" ) # ... perform the effect ... self.effects.append(Effect(tool=tool, klass=klass, inverse=inverse)) def _holds_exclusive_lock(self, tool: str) -> bool: return False # conservative default; real impl checks lock table def reconcile(winner: Branch, losers: list[Branch]) -> None: winner.committed = True for b in losers: for eff in reversed(b.effects): if eff.klass is EffectClass.IRREVERSIBLE: raise RollbackFictionError( f"branch {b.branch_id}: cannot roll back IRREVERSIBLE " f"effect {eff.tool!r}; escalate to coordinator" ) if eff.inverse is None: raise RollbackFictionError( f"branch {b.branch_id}: effect {eff.tool!r} has no inverse; " f"world-state will diverge from branch disposition" ) eff.inverse() eff.replayed = True # Only now is the rollback a true discard. ```