# In what scenarios must an instance treat a speculative tool call's side effect as non-rollbackable and abort the branch before reconciliation **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent systems that fork speculative execution branches (parallel draft agents, speculative tool-call prefetch, optimistic plan rollout) and rely on rollback plus branch reconciliation to merge a winning branch. Does not apply to purely read-only tool surfaces or to single-agent linear execution with no forked state. ## Core Distinction Speculative execution in agent swarms assumes a clean dichotomy: a branch is either *committed* (its effects persist) or *rolled back* (its effects vanish). Reconciliation then selects a survivor and discards losers. This dichotomy holds only for effects that are **state-local to the branch** — scratchpads, draft messages, in-memory plan nodes, ephemeral vector-store writes scoped to a branch namespace. It fails for **externally observable, non-idempotent effects**: an outbound email, a `POST` to a payments API, a file write to a shared mount, a message published to a queue another agent consumes, a database row insert without a branch discriminator. These effects are *already true in the world* the moment the tool returns, regardless of whether the branch is later declared a loser. Rollback of the branch state does not roll back the world. The critical invariant is: > **A branch is rollback-safe iff every tool invocation it performed produced an effect that is either (a) idempotent under replay with the same effect-key, or (b) confined to branch-scoped state. Any branch containing a non-idempotent, externally observable effect is non-rollbackable and must be promoted to a commit-or-abort decision before reconciliation proceeds.** The non-obvious part: reconciliation is usually designed to run *after* branch execution completes, comparing candidate outputs on merit. But merit comparison presupposes the losers are free. When a loser has already mutated shared state, "discarding" it is a lie — the swarm has silently applied a losing branch's side effects while its *reasoning* is thrown away. The result is a system whose observable state reflects a mixture of branches that no single agent ever reasoned over. ## What Was Observed A planner agent decomposed a task ("reconcile the customer's duplicate subscriptions") and forked three speculative branches to run concurrently: - **Branch A** — cancel the older subscription via `billing.cancel(sub_id=old)`, then issue a prorated refund. - **Branch B** — merge the two subscriptions via `billing.merge(old, new)`, preserving history. - **Branch C** — read-only audit of both subscriptions to produce a recommendation, deferring mutation to a human gate. All three were launched speculatively because the planner assigned them similar confidence (0.61, 0.58, 0.64) and the orchestrator's policy was "fork when confidence spread < 0.1, reconcile on completion." Branch C was expected to be the safe fallback. The failure trace: 1. Branch A's `billing.cancel` tool call returned `200 OK` at t=1.2s. The effect was committed at the billing provider. Branch A then stalled waiting on a refund-eligibility lookup that timed out at t=8s. 2. Branch B's `billing.merge` returned `409 Conflict` because the subscription was already cancelled by A's effect — B's reasoning had assumed the pre-cancel state. B's local state now diverged from world state. 3. Branch C completed cleanly at t=3s with a recommendation to *not* mutate and escalate. Its confidence, recomputed post-hoc against the audit evidence, rose to 0.81. 4. Reconciliation ran at t=9s. It scored branches on output quality and evidence support. **Branch C won.** The orchestrator rolled back A and B: discarded their plan nodes, cleared their scratchpads, released their effect-keys, and marked their tool calls "aborted." 5. The billing provider, having never received a compensating call (rollback only touched orchestrator-local state), retained the cancellation. The customer's subscription was cancelled with no refund, and the "winning" branch C's recommendation — escalate, do not mutate — was recorded as the system's decision. The swarm's recorded decision and its actual world effect were opposites. Reconciliation reported success. No exception was raised, because from the orchestrator's view every branch behaved correctly: A and B were rolled back, C was committed. The root cause is not a bug in rollback. It is that **rollback was applied to a branch that had already crossed the commit boundary of an external system**, and reconciliation had no representation of "this loser's effects are already durable." The effect-key registry recorded the call as aborted, which is worse than not recording it — a subsequent idempotency check would not find the key and could re-issue the cancellation. ## Condition of Validity The rollback-and-reconcile pattern is valid only under the following conjunction, which must be checked per branch *before* the branch is allowed to invoke a tool: 1. **Effect classification is known at dispatch time.** Each tool in the capability manifest carries an effect class: `PURE`, `BRANCH_LOCAL`, `IDEMPOTENT_EXTERNAL` (replay-safe under a stable effect-key), or `NON_IDEMPOTENT_EXTERNAL`. This cannot be inferred from the tool's LLM-facing description, which routinely understates side effects ("update subscription" reads benign but may emit notifications). 2. **Branch-scoped state covers all `BRANCH_LOCAL` writes.** The vector store, scratchpad, and any shared cache must be namespaced by `branch_id` and torn down on rollback. A `BRANCH_LOCAL` write that leaks into a global namespace is a silent promotion to external. 3. **`IDEMPOTENT_EXTERNAL` calls carry a stable effect-key** derived from `(task_id, semantic_intent)`, not from `(branch_id, call_seq)`. The latter produces distinct keys per branch and defeats idempotency across speculative duplicates — the exact scenario speculation creates. 4. **`NON_IDEMPOTENT_EXTERNAL` calls are gated.** A branch may not invoke them speculatively. It must first win a *commit token* (a compare-and-swap on the task's effect ledger), converting the branch from speculative to committed before the call is dispatched. When any of these fails, the branch is non-rollbackable and reconciliation must not treat it as a free loser. ## Decision Boundary The operational question is: **at what point does a speculative branch forfeit the right to be rolled back?** The boundary is the **first successful `NON_IDEMPOTENT_EXTERNAL` call**, not branch completion, not reconciliation start. Once crossed, the branch is in a *committed-effect* state even though its *reasoning* is still speculative. The correct transition is not "roll back on loss" but "abort the fork and escalate to a commit-or-compensate decision." Concretely, the orchestrator must enforce: - **Pre-dispatch gate.** Before any `NON_IDEMPOTENT_EXTERNAL` call, the branch requests a commit token. If the token is held by another branch, the requesting branch blocks or yields — it does not proceed speculatively. This serializes non-idempotent effects across the fork, which is the only sound way to keep them reconcilable. - **On branch loss with committed effects.** The branch cannot be rolled back. It must enter a **compensation path**: the orchestrator invokes a registered compensator (e.g., `billing.uncancel`, `refund.reissue`) or, if none exists, halts reconciliation and surfaces the divergence to a human gate with the exact effect record. Reconciliation does not "win" until every loser's committed effects are compensated or explicitly accepted. - **Effect-key stability across branches.** Speculative duplicates of the same intent must share an effect-key so the external system deduplicates them. Two branches both calling `billing.cancel(old)` with the same `(task_id, "cancel-old-sub")` key produce one effect, not two — and the second branch's call is a no-op replay, not a second cancellation. - **Reconciliation ordering.** Reconciliation must run *after* compensation resolution, never before. Scoring branches on output merit while their effects are unresolved is the failure above. The boundary is sharp: **a branch with a committed non-idempotent effect is no longer a speculation; it is a partial commitment, and the only legal moves are compensate or accept, never discard.** ## Operational Effect Systems that enforce this boundary observe a specific operational signature: - **Fork fan-out drops for mutating tasks.** Speculative parallelism collapses to serialized commit-token acquisition on the mutating segment, while read-only and idempotent segments still fork freely. Throughput on mutation-heavy tasks falls; correctness on those tasks rises from "sometimes applies a losing branch" to "never." - **Compensation paths become first-class.** Every `NON_IDEMPOTENT_EXTERNAL` tool needs a registered inverse or an explicit `UNCOMPENSABLE` marker that forces a human gate. This is a manifest-level requirement, not an afterthought. - **Reconciliation latency increases** because it now waits on compensation resolution. The failure mode shifts from silent divergence to visible stall — which is the correct trade. - **Effect-key collisions surface as replays, not duplicates.** Stable intent-derived keys mean speculative duplicates dedupe at the external system; the orchestrator sees `already_applied` and treats it as branch-local success. The invariant to encode in the orchestrator's state machine: > No branch may transition from `SPECULATIVE` to `ROLLED_BACK` if its effect ledger contains any `NON_IDEMPOTENT_EXTERNAL` entry in state `COMMITTED`. Such a branch may only transition to `COMPENSATING` (with a compensator) or `ESCALATED` (without). Reconciliation is blocked until every branch is in a terminal non-speculative state. The check below enforces exactly this at the point where a branch is about to be discarded as a loser. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class EffectClass(Enum): PURE = "pure" BRANCH_LOCAL = "branch_local" IDEMPOTENT_EXTERNAL = "idempotent_external" NON_IDEMPOTENT_EXTERNAL = "non_idempotent_external" class EffectState(Enum): PENDING = "pending" COMMITTED = "committed" COMPENSATED = "compensated" class BranchState(Enum): SPECULATIVE = "speculative" COMMITTED = "committed" ROLLED_BACK = "rolled_back" COMPENSATING = "compensating" ESCALATED = "escalated" @dataclass class EffectRecord: effect_class: EffectClass effect_key: str state: EffectState = EffectState.PENDING compensator: Optional[str] = None @dataclass class Branch: branch_id: str state: BranchState = BranchState.SPECULATIVE effects: list = field(default_factory=list) def has_uncompensated_commit(self) -> bool: return any( e.effect_class == EffectClass.NON_IDEMPOTENT_EXTERNAL and e.state == EffectState.COMMITTED for e in self.effects ) class NonRollbackableBranchError(RuntimeError): """Raised when rollback is attempted on a branch with durable external effects.""" def rollback_branch(branch: Branch) -> Branch: """Roll back a losing speculative branch. Legal only if the branch holds no committed non-idempotent external effect. Otherwise the branch must be compensated or escalated, not discarded. """ if branch.state != BranchState.SPECULATIVE: raise NonRollbackableBranchError( f"branch {branch.branch_id} in state {branch.state.value}; " f"only SPECULATIVE branches may be rolled back" ) if branch.has_uncompensated_commit(): committed = [ e.effect_key for e in branch.effects if e.effect_class == EffectClass.NON_IDEMPOTENT_EXTERNAL and e.state == EffectState.COMMITTED ] raise NonRollbackableBranchError( f"branch {branch.branch_id} has committed non-idempotent effects " f"{committed}; rollback would silently retain world mutations. " f"Route to COMPENSATING or ESCALATED, block reconciliation." ) branch.state = BranchState.ROLLED_BACK for e in branch.effects: if e.effect_class == EffectClass.BRANCH_LOCAL: e.state = EffectState.COMPENSATED return branch def reconcile(branches: list, winner_id: str) -> list: """Reconcile a fork. Refuses to proceed while any loser holds durable effects.""" losers = [b for b in branches if b.branch_id != winner_id] for loser in losers: if loser.has_uncompensated_commit(): raise NonRollbackableBranchError( f"reconciliation blocked: loser {loser.branch_id} has durable " f"external effects that the winner's reasoning does not account for" ) return [rollback_branch(b) for b in losers] ```