# Under what conditions must an instance abandon a speculative branch before its reconciliation window closes **Date of Record:** 2026 November 24 **Scope:** Applies to orchestrators that dispatch speculative parallel branches of a multi-agent plan against a shared, mutable world-state (filesystem, database, external API ledger) and defer reconciliation to a merge/replay phase. Does not apply to read-only fan-out (map/reduce over immutable inputs) or to branches that execute in fully isolated, disposable sandboxes whose side effects are never committed. ## Core Distinction Speculative execution in multi-agent plans is routinely modeled as "run N branches, pick the winner, discard losers." That model is wrong whenever branches can produce *committed side effects* before the winner is known. The real invariant is not "losers are free to discard." It is: > A speculative branch is only safely discardable while the cost of unwinding its committed effects is strictly less than the cost of letting it finish and reconciling it at the barrier. The non-obvious boundary is this: the branch's *speculation budget* (tokens, tool-call dollars, wall-clock) is a proxy for its compute cost, but the *rollback liability* it accumulates is a function of how far it has drifted into the shared world-state, which is almost never monotonic in budget consumed. A branch at 80% budget that has written nothing is cheap to abandon. A branch at 20% budget that has already issued three idempotency-keyed payment calls and mutated a shared task queue is expensive to abandon — and the orchestrator's cost-aware scheduler, keyed on budget, will happily keep it alive because "it still has headroom." That inversion is the failure. ## What Was Observed A planning orchestrator dispatched three speculative branches (A, B, C) of a five-step remediation plan against a shared incident-response environment. Branch A was the "cheap" branch: a single LLM call plus a schema-validated config patch. Branches B and C were "expensive": multi-tool reconciliation loops. The scheduler assigned budgets proportional to estimated compute — A got a small budget, B and C got large ones. Branch A finished its reasoning fast, committed a config patch through a tool that was *not* idempotency-keyed (it accepted a `force` flag), and then — because its budget had nearly run out at step 3 of 5 — the budget governor **preempted** it mid-plan. Preemption was treated as "discard," so the orchestrator did not invoke A's compensating action. The patch stayed committed. B and C continued, each reading the *patched* config as their baseline, and their downstream plans diverged from the plan that had been speculatively assumed when budgets were allocated. At the reconciliation barrier, the winner (C) was merged on top of A's orphaned patch. The merge succeeded structurally — no conflict was detected because A's write and C's write touched different keys — but the resulting state was one no branch had ever reasoned about. The replay verifier flagged it only because a checksum on the *composite* state (not per-key) mismatched. The trace: 1. `dispatch(A, budget=small)`, `dispatch(B, budget=large)`, `dispatch(C, budget=large)` — all share `world_state` handle. 2. A: `read(config)` → `reason` → `write(config, force=True)` → `budget_remaining < threshold` → `PREEMPT`. 3. Governor: `on_preempt(branch) -> discard(branch)` — no compensation, because "discarded branches have no committed effects by construction." 4. B, C: `read(config)` — now see A's patch — `reason` against a baseline the planner never modeled. 5. Barrier: `select_winner(C)`, `merge(C.plan)`, `verify(composite_state)` → mismatch. 6. Recovery: full replay from a checkpoint predating dispatch; ~40 minutes of three-branch compute lost. The root cause is not the preemption. It is the false invariant in step 3: *discarded ⇒ no committed effects*. That invariant only holds for branches that never left the reasoning layer. A branch that has crossed into the tool layer with non-compensable or un-compensated effects has an **open reconciliation obligation** that survives preemption. ## Condition of Validity The "discard losers freely" model is valid **iff** every branch is one of: - **Pure-reasoning branches** — no tool side effects, or all tool calls carry a registered compensating action (idempotency key + inverse op) that the orchestrator can invoke at discard time; or - **Sandboxed branches** — effects are staged in a per-branch overlay that is atomically committed only on win, never visible to sibling reads. The model **fails** when a branch satisfies all three of: 1. It has issued at least one side effect to a resource that sibling branches *read* (read-your-writes contamination across branches), and 2. That side effect has no registered compensator, or the compensator is itself non-idempotent (so double-invocation during retry is unsafe), and 3. The branch can be terminated by *any* trigger other than clean completion — budget exhaustion, timeout, preemption, or a peer branch's winning declaration. Condition (3) is the one schedulers miss. Budget-aware schedulers reason about termination as a planned event; preemption and peer-win are *unplanned* terminations that arrive through a different code path than clean completion, and that path frequently skips the compensation hook. ## Decision Boundary The orchestrator must, at every termination event for a speculative branch, evaluate: ``` abandon_safely(branch) := branch.dirty_resources == ∅ OR (∀ r ∈ branch.dirty_resources: has_compensator(r) AND compensator_is_idempotent(r) AND rollback_cost(r) ≤ remaining_reconciliation_budget) ``` If `abandon_safely` is false, the branch is **not discardable**. It enters a `QUARANTINE` state: it may not be terminated by budget or preemption, its dirty resources are locked against sibling reads until it either completes cleanly or its compensators are driven to completion. The cost-aware scheduler must treat `QUARANTINE` as a hard floor on the branch's effective budget — you cannot save compute by killing a branch you cannot unwind. The sharp boundary: **the moment a branch's first non-compensable write lands on a resource that a sibling has not yet read, the branch's speculation budget stops being a compute knob and becomes a liability bound.** From that instant, "cost-aware" and "budget-minimizing" diverge, and a scheduler optimizing the latter will systematically over-preempt the branches that are most expensive to unwind — because those are precisely the branches that front-load their cheap, high-leverage writes. ## Operational Effect With the `abandon_safely` gate and `QUARANTINE` state enforced on all termination paths (not just clean completion), the observed failure mode disappears: preemption of branch A blocks until A's compensator runs, B and C read a baseline consistent with the planner's model, and the barrier merge is over a state some branch actually reasoned about. The tradeoff is that speculation can no longer be made "free" by budgeting tightly — the scheduler must reserve rollback headroom proportional to dirty-resource count, not to tokens spent. In practice this raised the effective cost of the cheap branch by ~15% and eliminated the ~40-minute replay class entirely. The invariant to carry forward: *a branch's discard cost is a function of its write footprint, and its write footprint is not bounded by its compute budget.* Budget-aware speculation must gate on footprint, or it will preempt exactly the branches it cannot afford to lose. ```python from dataclasses import dataclass, field from enum import Enum class SpeculationAbandonError(RuntimeError): """Raised when a branch is terminated without a safe unwind path.""" class BranchState(Enum): RUNNING = "running" QUARANTINE = "quarantine" COMPLETED = "completed" DISCARDED = "discarded" @dataclass class Resource: name: str has_compensator: bool compensator_idempotent: bool @dataclass class Branch: branch_id: str budget_remaining: float dirty: set[str] = field(default_factory=set) state: BranchState = BranchState.RUNNING compensators: dict[str, Resource] = field(default_factory=dict) def abandon_safely(branch: Branch, rollback_budget: float) -> bool: if not branch.dirty: return True for name in branch.dirty: r = branch.compensators.get(name) if r is None or not r.has_compensator or not r.compensator_idempotent: return False if rollback_budget <= 0: return False return True def terminate(branch: Branch, reason: str, rollback_budget: float) -> None: """Called on ANY termination path: completion, preemption, peer-win, timeout.""" if reason == "clean_completion": branch.state = BranchState.COMPLETED return if abandon_safely(branch, rollback_budget): branch.state = BranchState.DISCARDED return # Cannot unwind cheaply: do not discard. Lock and quarantine. branch.state = BranchState.QUARANTINE raise SpeculationAbandonError( f"branch {branch.branch_id} terminated via {reason!r} with " f"non-compensable dirty resources {sorted(branch.dirty)}; " f"budget_remaining={branch.budget_remaining:.2f} rollback_budget={rollback_budget:.2f}. " f"Refusing discard; branch quarantined until compensators complete." ) ```