# Which invariants prevent speculative agent scheduling from committing unverified side effects when early-abort heuristics fire mid-fanout **Date of Record:** 2026 December 1 **Scope:** Applies to orchestrators that dispatch N parallel speculative agent branches (tool-calling LLM instances) under a cost budget, then select one branch's result and discard the rest. Does not apply to single-branch sequential execution or to fanouts where every branch is idempotent and side-effect-free by construction. ## Core Distinction Speculative scheduling is often described as "run k candidates, keep the best." That description conflates two independent decisions: **how many branches to launch** (speculation depth, chosen under a cost model) and **which branches to let finish** (early-abort, chosen under a latency or budget heuristic). The failure mode lives precisely in the gap between them: an early-abort heuristic can terminate the *scoring* of a branch while that branch's tool calls are still *committing*. Speculation depth is a pre-dispatch decision; abort is a mid-flight decision. A system that treats abort as a pure scheduling optimization — "we stopped waiting, so the work stopped" — violates a continuity invariant that no amount of result-selection logic can repair. The boundary is not "did we pick the right winner." It is: **at the instant a loser branch is de-scheduled, has any of its effects already escaped the sandbox into shared state?** If yes, the loser is not a loser; it is an unverified writer whose output was never scored and whose effects were never reconciled. ## What Was Observed An orchestrator dispatched a fanout of depth k=4 for a task requiring a mutating tool (`append_to_ledger`). The cost model set depth to 4 because the per-branch token cost was low and the expected disagreement rate was high. Each branch ran in a nominally isolated worker, but the `append_to_ledger` tool wrote to a shared backing store keyed by `task_id` — isolation was enforced at the *process* layer, not at the *effect* layer. The early-abort heuristic fired on a wall-clock budget: when the first branch to reach a "confident" self-report arrived, the scheduler cancelled the remaining three to save cost. Cancellation was implemented as task cancellation at the async runtime, which raises a cancellation signal at the next `await` boundary. Two of the three cancelled branches had already issued `append_to_ledger` calls that had returned successfully before the cancellation signal was delivered. Their ledger entries persisted. The selected winner's ledger entry also persisted. The reconciler downstream saw four ledger entries for one `task_id`, three of which came from branches whose reasoning was never scored, never compared, and in one case contradicted the winner on a numeric field. The divergence was silent: no branch errored, the scheduler reported success, and the winner's confidence was high. The corruption surfaced only when a later audit replayed the task and got a different ledger total. The trace, condensed: 1. `dispatch(depth=4)` → four branches `b0..b3`, all sharing `task_id=T`. 2. `b0` self-reports confident at t=1.2s. Early-abort heuristic fires. 3. Scheduler cancels `b1, b2, b3` via runtime cancellation. 4. `b1` and `b2` had already completed `append_to_ledger(T, ...)` at t=0.9s and t=1.1s; their next `await` is the cancellation point, *after* the write. 5. `b3` is cancelled cleanly (no write yet). 6. Winner `b0` commits at t=1.4s. Ledger now has three entries for `T`. The critical detail: the abort heuristic's notion of "cheap to cancel" was calibrated on token cost, not on effect commitment. A branch that has spent 900 tokens and committed one write is not cheap to cancel; it is expensive to cancel, because cancellation now requires reconciliation, not just deallocation. ## Condition of Validity The early-abort optimization is only sound under a **commit-barrier invariant**: a branch may be de-scheduled only when its effect frontier is closed — that is, when no in-flight or completed tool call with non-idempotent, shared-state effects is outstanding or unacknowledged. Formally, for each branch `b`, define `committed(b)` as the set of effects that have escaped the branch's private sandbox. The abort is valid iff `committed(b) = ∅` OR the abort path includes a compensating rollback that is itself verified. This invariant is violated whenever the following three conditions co-occur: - **Shared-effect tools exist** (writes to any store not scoped to the branch). - **Cancellation is delivered at cooperative yield points** (async cancellation, signal handlers, token-budget checkpoints) rather than at a pre-tool-call gate. - **The abort heuristic's cost model ignores commitment state**, treating a branch as "in flight" or "not in flight" rather than tracking which effects have landed. Remove any one condition and the corruption does not occur. Idempotent tools make duplicate writes harmless. Synchronous cancellation gates (checking a cancel flag *before* issuing each tool call, not after) bound the frontier. A commitment-aware cost model refuses to abort a branch whose `committed(b) ≠ ∅` without escalating to reconciliation. ## Decision Boundary The operational question is not "should we abort losers" but "what does abort mean for a branch that has crossed the commit barrier." The boundary is sharp: - **Before the first non-idempotent effect lands:** abort is a pure deallocation. Safe. Cost model may treat the branch as free to kill. - **After any non-idempotent effect lands but before the branch is scored:** abort is a *reconciliation event*, not a deallocation. The branch's effects must be either (a) rolled back via a verified compensating action, or (b) promoted into the winner's result set and scored retroactively. The scheduler must not report success until this is resolved. - **After the branch is scored and lost:** abort is a standard cleanup; the loser's effects were already accounted for in selection. The dangerous zone is the middle band. An early-abort heuristic that fires here without a reconciliation path is committing unverified side effects under the banner of a cost optimization. The invariant to enforce: **no branch enters the scored-and-discarded state while its effect frontier is open.** Either close the frontier (rollback) or keep the branch in the scored set. A second boundary governs speculation depth itself. Depth k is only justified when the marginal branch's *expected* unverified-commitment cost is below the marginal latency savings. If the per-branch probability of crossing the commit barrier before abort is `p`, and the cost of reconciling one unverified write is `c_r`, then the effective cost of depth k is `k · p · c_r` plus token cost. A cost-aware scheduler that ignores the `p · c_r` term systematically over-speculates on mutating tasks and under-speculates on read-only ones — the opposite of what a naive token-cost model predicts. ## Operational Effect Systems that enforce the commit-barrier invariant observe a characteristic signature: speculation depth auto-collapses to 1 on tasks whose tools are non-idempotent and whose abort latency exceeds tool round-trip time. This is correct behavior, not a regression — the scheduler has learned that on such tasks, the reconciliation cost of a mid-flight abort exceeds the latency benefit of parallelism. On read-only tasks, depth stays high because `committed(b) = ∅` trivially holds and abort is free. Systems that violate it exhibit a subtler signature: success rates look fine, latency improves, and ledger/store divergence accumulates silently until a replay or audit detects duplicate or contradictory effects. The failure is invisible to per-task monitoring because every individual task "succeeded." It is visible only to cross-task reconciliation — the same replay discrepancy that multi-agent verification systems are built to catch, but here triggered by a single orchestrator's own scheduling heuristic. The guardrail is a two-part contract: (1) every tool declares whether it is `idempotent` and whether it writes to `shared` state, and the scheduler's abort path consults that declaration before cancelling; (2) any abort that fires with an open effect frontier raises into a reconciliation handler rather than completing silently. The second part is what the code below enforces. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class EffectClass(Enum): READ_ONLY = "read_only" IDEMPOTENT = "idempotent" SHARED_MUTATING = "shared_mutating" class UnreconciledAbortError(RuntimeError): """Raised when an early-abort heuristic fires on a branch whose non-idempotent shared-state effects have already committed, without routing through a reconciliation handler.""" pass @dataclass class Branch: branch_id: str effect_class: EffectClass committed_effects: list = field(default_factory=list) scored: bool = False aborted: bool = False def early_abort(branch: Branch, reconciliation_available: bool) -> None: """Attempt to de-schedule a speculative branch under a cost heuristic. Invariant enforced: a branch may only transition to aborted without reconciliation when its effect frontier is closed (no committed non-idempotent shared-state writes). """ frontier_open = ( branch.effect_class is EffectClass.SHARED_MUTATING and len(branch.committed_effects) > 0 and not branch.scored ) if frontier_open and not reconciliation_available: raise UnreconciledAbortError( f"branch {branch.branch_id} has {len(branch.committed_effects)} " f"committed shared-mutating effect(s) and was never scored; " f"aborting would leak unverified writes into shared state. " f"Provide a reconciliation handler or keep the branch in the " f"scored set." ) if frontier_open and reconciliation_available: # Abort is legal only as a reconciliation event, not a deallocation. # The handler is responsible for rollback or retroactive scoring. branch.aborted = True return # Closed frontier: safe, cheap deallocation. branch.aborted = True def schedule_speculative(branches: list, abort_triggered: bool, reconciliation_available: bool) -> Optional[Branch]: """Select a winner under an early-abort heuristic with commit-barrier checks.""" if abort_triggered: for b in branches: if not b.scored: early_abort(b, reconciliation_available) scored = [b for b in branches if b.scored and not b.aborted] if not scored: raise UnreconciledAbortError( "early-abort fired before any branch was scored; no winner exists " "and reconciliation is required for all open frontiers." ) return scored[0] ```