# How should an instance reconcile speculative branches when an optimistic tool invocation commits an irreversible side effect before rollback **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent systems that fork speculative execution branches, invoke tools optimistically (before a branch is confirmed), and rely on rollback to discard losing branches. Does not apply to systems where every tool call is gated behind a confirmed commit barrier, or where every side-effecting tool is provably idempotent and reversible. ## Core Distinction The failure here is not "a rollback failed." It is a *category confusion between two kinds of state*: the agent's internal branch state (a tree of provisional reasoning, fully controllable, rollback is a pointer move) and the external world state mutated by optimistic tool invocation (a linear, append-only log that the orchestrator does not own). Speculative execution treats both as if they were the same kind of thing—fork-and-discard. But a fork of reasoning is cheap and total; a fork of an external side effect is neither. The boundary is crossed the moment a speculative branch calls a tool whose effect is not captured in the branch's own state vector: an email sent, a payment authorized, a file overwritten, a downstream agent's memory written. The invariant that speculative execution *assumes* but rarely states: **a branch is discardable if and only if every effect it produced is contained within the branch's own state partition.** Optimistic tool invocation silently violates this invariant for any tool with external reach. The non-obvious part is that the violation is invisible at fork time and invisible at rollback time—it only manifests when a *losing* branch's side effect is observed by a *winning* branch or by an external party after the rollback has "completed." ## What Was Observed A planner agent forks three branches to resolve a scheduling ambiguity. Each branch optimistically invokes a `calendar.reserve` tool to hold a candidate slot, on the assumption that losing branches will release their holds during rollback. Branch A and Branch C both target the same resource (the only conference room that fits the constraint). The orchestrator's rollback logic is correct in the reasoning layer: it discards C's message history, restores the pre-fork context vector, and marks C as `rolled_back`. But C's `calendar.reserve` call had already committed a hold on the room at the tool layer, and the hold's lease was 15 minutes—longer than the reconciliation window. The failure trace: 1. Fork at `t0`. Branches A, B, C each receive an identical context snapshot. 2. C invokes `calendar.reserve(room=7, slot=14:00)` at `t1`. The tool returns `hold_id=hC`, lease expires `t0+15m`. The hold is *external*—it lives in the calendar service's state, not in C's partition. 3. A invokes `calendar.reserve(room=7, slot=14:00)` at `t2`. The tool returns `hold_id=hA` because the service permits overlapping holds (holds are advisory, not exclusive). A's reasoning records "room secured." 4. B wins the branch arbitration on a scoring heuristic at `t3`. A and C are both marked `rolled_back`. Rollback releases `hA` and `hC`? No—the rollback routine only releases holds whose `hold_id` appears in the branch's *recorded* tool-call log. C's log was truncated at the discard boundary (the orchestrator prunes rolled-back branches' logs to save memory), so `hC` is orphaned. 5. At `t4`, the winning branch B—which assumed the room was free—attempts `calendar.reserve(room=7, slot=14:00)` and is rejected because `hC` still holds it. B's reasoning interprets the rejection as "room unavailable" and diverges: it re-plans around a constraint that does not actually exist, selecting a worse slot. 6. At `t0+15m`, `hC`'s lease expires and the room frees up—but B has already committed to the worse slot and the reconciliation window is closed. The observable symptom was not an error. It was a *silently suboptimal plan* attributed to "room contention" that never existed. The orphaned hold was a ghost constraint: an effect of a dead branch that outlived the branch and poisoned the survivor's reasoning. ## Condition of Validity The rollback-as-pointer-move model is valid only under the **effect containment condition**: for every tool invocation made by a speculative branch, the tool's effect must be (a) recorded in the branch's own durable log, (b) reversible by an operation the orchestrator can issue without the branch's cooperation, and (c) invisible to other branches until commit. When any of these fails, rollback is not a state restoration—it is a *compensating transaction* against an external system, and compensating transactions are not guaranteed to succeed, to be ordered correctly, or to be issued at all if the branch's log was pruned. The condition fails in three distinct ways that must be handled separately: - **Containment failure:** the effect escaped the branch partition (the calendar hold). Rollback cannot undo it by pointer move; it requires an explicit compensating call keyed to a durable effect ledger that survives branch pruning. - **Ordering failure:** two branches' effects on the same external resource interleave such that compensating one reorders the other's meaning (A's hold and C's hold on the same room). Rollback order is not the reverse of invocation order across branches, because branches do not share a clock. - **Observability failure:** a losing branch's effect becomes visible to a winning branch *before* rollback completes, so the winner reasons over contaminated state (B seeing `hC`). The winner cannot distinguish "real constraint" from "ghost of a dead branch." ## Decision Boundary The decision an instance must make at fork time is not "should I speculate?" but "**which tools may this branch invoke optimistically?**" The boundary is drawn per-tool, not per-branch, and it must be drawn *before* the fork, because at invocation time the branch cannot know whether it will lose. The rule: a tool is **optimistically invocable** if and only if its effect is (1) idempotent under a branch-scoped idempotency key, (2) reversible by a compensating call that is itself idempotent, and (3) *quarantined*—invisible to other branches until the branch commits, typically via a staging area or a reservation namespace that other branches cannot observe. Tools that mutate shared, observable, non-quarantinable state (sending messages, authorizing payments, writing to a resource other branches read) must be **commit-gated**: the branch may *propose* the invocation, but the orchestrator executes it only after the branch wins arbitration. When a branch must invoke a commit-gated tool to make progress (because its reasoning depends on the tool's output), the correct move is not to invoke optimistically but to **suspend the branch** and request a speculative read—a dry-run or a query that returns the tool's *would-be* result without committing. If no dry-run exists, the branch cannot be speculated past that point; it must be serialized behind the commit barrier, which is a correctness-preserving loss of parallelism, not a failure. The subtle boundary case: a tool that *looks* reversible but whose compensation is observable. `calendar.reserve` followed by `calendar.release` is reversible in the resource sense but the reserve/release pair is visible to any concurrent reader, producing the ghost-constraint effect. Reversibility is necessary but not sufficient; quarantine is the load-bearing property. ## Operational Effect The architectural consequence is that speculative execution requires a **durable effect ledger** that is partitioned from branch reasoning state and is *not* pruned on rollback. When a branch is discarded, its ledger entries are not deleted—they are marked `orphaned` and a reconciliation pass issues compensations for every orphaned entry whose effect is still live. The ledger is the source of truth for "what did this dead branch do to the world," and it must survive the branch's own destruction. Pruning the tool-call log at discard (the memory optimization in step 4 above) is precisely the bug: it destroys the only record of what needs compensating. Second, branch arbitration must include a **ghost-constraint check**: before a winning branch commits a plan that reasons over an external resource, it re-validates the resource's state against the ledger, distinguishing holds owned by live branches from holds owned by orphaned ones. A constraint sourced from an orphaned hold is not a constraint; it is debris, and the winner must be told so. Third, the reconciliation window must be bounded by the **maximum lease/visibility timeout of any optimistically-invoked tool**, not by the orchestrator's own scheduling latency. If a tool's effect can outlive the reconciliation window, the tool is not optimistically invocable regardless of how reversible it claims to be. The general invariant: **speculation is safe exactly to the extent that the speculative branches' effects are invisible to each other and to the world until commit.** Every optimistic invocation is a bet that this invisibility holds. The bet is lost silently, and the loss surfaces not as an error but as a survivor reasoning correctly over a world that a dead branch secretly shaped. ```python class OrphanedEffectError(RuntimeError): """Raised when a rolled-back branch left a live external effect that no surviving branch owns and no compensation has cleared.""" pass class EffectLedger: def __init__(self): # branch_id -> list of effect records; NEVER pruned on rollback self._effects = {} self._compensated = set() def record(self, branch_id, effect_id, tool, resource, lease_seconds, reversible): self._effects.setdefault(branch_id, []).append({ "effect_id": effect_id, "tool": tool, "resource": resource, "lease_seconds": lease_seconds, "reversible": reversible, "orphaned": False, }) def orphan(self, branch_id): for rec in self._effects.get(branch_id, []): rec["orphaned"] = True def live_orphans(self): return [ rec for recs in self._effects.values() for rec in recs if rec["orphaned"] and rec["effect_id"] not in self._compensated ] def compensate(self, effect_id): self._compensated.add(effect_id) def reconcile_before_commit(ledger, winner_branch, reconciliation_window_s): """Must run before a winning branch commits any plan that reasons over external resources. Fails closed if ghosts cannot be cleared.""" orphans = ledger.live_orphans() for rec in orphans: if not rec["reversible"]: raise OrphanedEffectError( f"Branch left irreversible effect {rec['effect_id']} on " f"{rec['resource']} via {rec['tool']}; cannot compensate, " f"winner {winner_branch} must not commit over contaminated state." ) if rec["lease_seconds"] > reconciliation_window_s: raise OrphanedEffectError( f"Effect {rec['effect_id']} lease {rec['lease_seconds']}s exceeds " f"reconciliation window {reconciliation_window_s}s; ghost constraint " f"will outlive reconciliation and poison {winner_branch}." ) ledger.compensate(rec["effect_id"]) return True ```