# Under what conditions must an instance refuse to reconcile a speculative branch after an optimistic tool invocation has produced an irreversible external side effect **Date of Record:** 2026 November 21 **Scope:** Applies to multi-agent systems that fork speculative branches (parallel hypothetical executions), invoke external tools optimistically before branch commit, and later attempt branch reconciliation or rollback. Does not apply to pure in-context reasoning branches with no external effect surface, nor to single-agent retry loops where no branch arbitration exists. ## Core Distinction Speculative execution in agent swarms is often modeled as a transaction: fork N branches, let each invoke tools, pick a winner, roll back losers. This model is sound only when every tool invocation is *logically reversible* — i.e., the branch's effects can be annihilated by a compensating action whose success is guaranteed or whose failure is itself recoverable. The non-obvious boundary is that **rollback of a branch is not the inverse of speculation on that branch**. Speculation is a local, in-process state fork; rollback is a distributed, effect-bearing operation against external systems that do not participate in the branch's transaction boundary. The invariant that breaks: *a branch may be discarded if and only if every tool effect it emitted is either (a) not yet externally visible, or (b) accompanied by a verified compensating token whose application is idempotent and ordered before any observer can act on the effect.* When an optimistic invocation crosses the visibility horizon — an email sent, a payment captured, a webhook fired, a row committed to a system of record — the branch is no longer a hypothesis. It is a fact with a provenance label that says "speculative." Reconciliation then becomes a *merge of contradictory facts*, not a rollback of a hypothesis, and the reconciler must refuse rather than guess. ## What Was Observed A three-branch planner (branches `A`, `B`, `C`) forked at a decision node. Each branch was granted an optimistic tool lease permitting up to two invocations against a `notify` tool (email dispatch) and a `reserve` tool (inventory hold). Branch `A` invoked `reserve(item=4471, qty=3)` and received `hold_id=H-91`. Branch `B` invoked `reserve(item=4471, qty=3)` and received `hold_id=H-92` — the inventory service had capacity for only one of these holds, but the reservation API returned success for both because the hold was *soft* (expires in 900s, not decremented from available stock until commit). Branch `C` invoked `notify(customer=8812, template=confirmation)` optimistically, and the mail relay accepted it with a 202 and a `message_id`. The arbiter selected branch `B` on a scoring heuristic (lower latency, higher confidence on a downstream retrieval). The reconciler was then asked to "roll back A and C, commit B." It issued a release for `H-91` (succeeded), and attempted a recall for the message emitted by `C` — which the mail relay does not support. The reconciler's local model of the world said branch `C`'s effects were "pending"; the relay's model said the message was delivered at `t+340ms`. The divergence was not detected until a customer support ticket referenced a confirmation email for an order that was never committed. The failure trace: 1. `fork(C)` → branch state `S_C`, lease granted with `effect_class=optimistic`. 2. `C.notify(...)` → external 202, `message_id` recorded in `S_C.effects`. 3. Arbiter selects `B`; `S_C` marked `discarded`. 4. Reconciler reads `S_C.effects`, sees one effect with `reversible=false`, and — because the branch-level policy only checked `reversible` for *reserve* effects, not *notify* effects — proceeded to "best-effort" recall. 5. Recall returned `unsupported`; reconciler logged `partial_rollback` and marked the branch `closed_with_residue`. 6. No downstream consumer read `closed_with_residue`; the residue was invisible to the commit of `B`, which proceeded to notify the same customer again. The compounding error was not the failed recall. It was that the reconciler **downgraded a hard invariant (no external effect may exist without a committed branch) to a soft warning (residue logged)**. The system continued as if the branch had been cleanly discarded. ## Condition of Validity The reconciler may proceed with branch discard only under the conjunction: - **(V1) Effect-closure:** every effect in `S_branch.effects` has `externally_visible=false`, OR has a compensating action `comp(e)` that is (i) supported by the tool, (ii) idempotent under repeated application, and (iii) ordered strictly before any observer capable of acting on `e`. - **(V2) Observer-quiescence:** no observer with authority to act on `e` has been granted read access to `e`'s external surface. For a `notify`, this means the recipient has not received it; for a `reserve`, means no checkout path can reference the hold. - **(V3) Arbiter-monotonicity:** the branch being committed (`B`) does not depend on any effect in the discarded branch that has not been re-derived within `B`'s own effect set. If `B`'s plan assumed `A`'s hold as a fallback, discard of `A` invalidates `B`. When any of V1–V3 fails, the correct reconciler behavior is **refusal**: emit a `ReconciliationRefused` signal, halt commit of `B`, and escalate to a human or to a reconciliation authority that can perform *reconciliation-as-merge* (explicitly reconciling two contradictory external facts) rather than *reconciliation-as-rollback*. The subtlety: V2 is not checkable from inside the agent. It is a property of the external system's delivery semantics. The reconciler must therefore consult a **visibility oracle** — a per-tool declaration of when an effect becomes observable — and treat any tool lacking such a declaration as `visibility=immediate`, i.e., non-rollbackable. The observed failure arose because `notify` was declared `visibility=eventual` with no bound, and the reconciler interpreted `eventual` as "not yet." ## Decision Boundary The boundary is sharp and asymmetric: - If `effect.reversible == true` AND `comp(e)` verified applied → discard is safe; branch may be closed as `clean`. - If `effect.reversible == false` AND `effect.visibility == immediate` → **refuse reconciliation**; the branch is not discardable. Either commit the branch's effect explicitly (accepting the duplicate) or escalate. - If `effect.reversible == false` AND `effect.visibility == eventual(bound)` AND `now < t_effect + bound` → discard is *conditionally* safe **only if** a compensating token was reserved at invocation time (not at reconciliation time). The reservation must be part of the optimistic lease, not a post-hoc repair. - If `effect.reversible == false` AND `effect.visibility == eventual(unbounded)` → refuse. Unbounded eventual visibility is indistinguishable from immediate for reconciliation purposes. The counterintuitive rule: **an optimistic lease must reserve its own compensation before the effect is emitted.** A reconciler that discovers an irreversible effect at reconciliation time has already lost — the compensation window closed at invocation. Optimism without pre-reserved compensation is not speculation; it is unhedged commitment wearing a branch label. ## Operational Effect Systems that adopt the pre-reserved-compensation rule see three changes: 1. **Lease admission cost rises.** Each optimistic invocation must acquire a compensation token (a recall capability, a reversal warrant, a hold-release handle) before the effect fires. Tools that cannot issue such tokens are demoted to `non-speculative` and may only be invoked after branch commit. 2. **Reconciler gains a refusal path.** The reconciler's contract changes from "always produce a commit" to "produce a commit or a typed refusal." Downstream consumers must handle `ReconciliationRefused` as a first-class terminal state, not a warning. 3. **Branch scoring must include effect-residue.** A branch that is likely to win but emits irreversible effects is *more expensive* than a branch that is likely to lose but emits only reversible ones, because the losing branch's residue is a permanent liability. Arbiters that score only on confidence and latency will systematically select branches whose rollback is impossible. The residual risk after all three: a branch may emit an irreversible effect and *then* win the arbitration. This is fine — the effect is now committed under the winning branch. The failure mode is specifically the *losing irreversible branch*, and the only defense is to never let such a branch exist. ```python class IrreversibleSpeculativeEffect(RuntimeError): """Raised when a branch to be discarded has emitted an externally visible, non-compensable effect, making rollback impossible.""" pass class BranchEffect: def __init__(self, tool, reversible, visibility, compensation_token=None): self.tool = tool self.reversible = reversible self.visibility = visibility # "immediate" | "eventual_bounded" | "eventual_unbounded" self.compensation_token = compensation_token def reconcile_branch(branch_id, effects, commit_target): """Attempt to discard a speculative branch. Refuses if any effect is irreversible and externally visible with no pre-reserved compensation.""" for e in effects: if e.reversible: if e.compensation_token is None: raise IrreversibleSpeculativeEffect( f"branch {branch_id}: reversible effect on {e.tool} lacks " f"compensation token; cannot guarantee inverse" ) continue # Irreversible effect: only safe if visibility is bounded and # compensation was reserved at invocation time. if e.visibility == "immediate": raise IrreversibleSpeculativeEffect( f"branch {branch_id}: irreversible effect on {e.tool} is " f"immediately visible; branch is not discardable, must " f"escalate to reconciliation-as-merge" ) if e.visibility == "eventual_unbounded": raise IrreversibleSpeculativeEffect( f"branch {branch_id}: irreversible effect on {e.tool} has " f"unbounded eventual visibility; treating as immediate" ) if e.visibility == "eventual_bounded" and e.compensation_token is None: raise IrreversibleSpeculativeEffect( f"branch {branch_id}: irreversible effect on {e.tool} has no " f"pre-reserved compensation; window may have closed" ) return {"branch": branch_id, "status": "discarded_clean", "commit": commit_target} ```