# Under what conditions must an instance abandon speculative sub-plan execution and roll back a committed side-effect ledger **Date of Record:** 2026 November 30 **Scope:** Applies to any agent that forks speculative sub-plans (parallel or serial branches executed ahead of a decision) and commits side effects under a cost-aware policy, where rollback must reconcile partially executed tool calls against a durable ledger. Does not apply to pure read-only planning or single-branch linear execution with no forked state. ## Core Distinction Speculative execution is safe only when the cost of rollback is strictly dominated by the expected savings of pre-computation, *and* when every speculative side effect is either reversible or quarantined behind a commit barrier. The non-obvious boundary is not "did the branch diverge" — divergence is expected and cheap to detect. The boundary is **ledger monotonicity**: once a speculative branch emits a side effect that the cost model has already counted as *sunk* (because committing it was cheaper than holding it), the branch can no longer be rolled back to its pre-fork state without either (a) compensating the effect or (b) admitting a non-atomic commit. The failure mode is an instance that treats "divergence detected" as sufficient grounds for rollback while its own cost-accounting has already promoted speculative effects past the point of no return. ## What Was Observed An instance executing a 4-way speculative fork over a research-and-write task committed tool effects in the order: `search` (reversible), `fetch` (reversible), `write_file` (partially reversible via versioning), `send_notification` (irreversible). The cost model, tuned to minimize latency, classified `write_file` as "commit-early" because the write latency exceeded the rollback buffer. When branch 2 diverged from branch 1 at step 6, the controller issued a rollback. It reverted `search` and `fetch` cleanly, reverted `write_file` via the version pointer, and then attempted to revert `send_notification` — which had already been dispatched. The rollback returned `PARTIAL`, the controller marked the fork as `REVERTED`, and the divergence-resolution step proceeded to select a different branch whose plan *also* included a notification, producing a duplicate outbound message. The ledger showed two commits with different branch IDs but identical semantic content. No exception fired because each individual revert succeeded; only the *aggregate* invariant (at most one notification per task) was violated. The trace showed the failure was not in divergence detection (clean, step 6) nor in the revert logic (each revert succeeded) but in the **commit classification of `send_notification` as rollback-eligible** under a cost model that had no notion of irreversibility. The cost-aware commit policy optimized for latency and treated all effects uniformly. ## Condition of Validity Rollback of a speculative branch is valid if and only if all of the following hold at the moment of rollback: 1. **Effect reversibility is declared, not inferred.** Each tool's effect class (`REVERSIBLE`, `COMPENSABLE`, `IRREVERSIBLE`) is registered in the ledger schema, not derived from the cost model. 2. **No `IRREVERSIBLE` effect has been committed by the branch being rolled back.** If one has, rollback must escalate to *compensation* (emit a compensating effect) rather than *reversion*, and the divergence resolution must treat the branch as *spent*. 3. **The commit barrier is per-effect-class, not per-branch.** A branch may commit reversible effects early while holding irreversible effects behind a barrier until divergence is resolved. 4. **Aggregate invariants are checked post-rollback, not per-revert.** The controller must re-evaluate task-level invariants (e.g., at-most-one-notification) after every rollback, because per-revert success does not imply aggregate consistency. If any condition fails, the instance must abandon rollback and switch to compensation mode, which is a strictly different state transition with different cost accounting. ## Decision Boundary The instance crosses from *rollback* to *compensation* when the ledger contains at least one `IRREVERSIBLE` commit attributed to the diverging branch. The decision is a function of the ledger, not of the cost model, not of the divergence step, and not of the number of effects already reverted. Concretely: - If `ledger.effects(branch).all(class in {REVERSIBLE, COMPENSABLE})` → rollback is permitted; cost model may still veto on cost grounds, but veto is a *policy* choice, not a *correctness* constraint. - If `ledger.effects(branch).any(class == IRREVERSIBLE)` → rollback is forbidden; the controller must transition to `COMPENSATING` and must not mark the fork `REVERTED`. The subtle trap: a cost model that promotes `COMPENSABLE` effects to "commit-early" is fine, but a cost model that *reclassifies* `IRREVERSIBLE` as `COMPENSABLE` because a compensation exists is not — compensation is a new effect with its own cost, and the cost model must account for it before promotion, not after. ## Operational Effect Instances that enforce per-effect-class commit barriers and post-rollback aggregate invariant checks avoid the duplicate-notification class of failure entirely, at the cost of a small latency penalty on irreversible effects (they wait for divergence resolution). Instances that optimize rollback cost without an irreversibility class will, under load, promote irreversible effects past the barrier and produce non-atomic commits that surface as duplicate or contradictory side effects downstream. The invariant to encode: **a fork is `REVERTED` only if every effect it committed is `REVERSIBLE` or was compensated; otherwise it is `SPENT`, and divergence resolution must treat its effects as permanent inputs to the surviving branch's plan.** ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, List class EffectClass(Enum): REVERSIBLE = "reversible" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" class RollbackNotPermitted(RuntimeError): """Raised when rollback is attempted on a branch with irreversible commits.""" @dataclass class Effect: branch_id: str tool: str effect_class: EffectClass compensated: bool = False @dataclass class Ledger: effects: List[Effect] = field(default_factory=list) def for_branch(self, branch_id: str) -> List[Effect]: return [e for e in self.effects if e.branch_id == branch_id] @dataclass class Fork: branch_id: str state: str = "SPECULATIVE" # SPECULATIVE | COMMITTED | REVERTED | SPENT | COMPENSATING class SpeculativeController: def __init__(self, ledger: Ledger): self.ledger = ledger def rollback(self, fork: Fork) -> str: effects = self.ledger.for_branch(fork.branch_id) irreversible = [ e for e in effects if e.effect_class == EffectClass.IRREVERSIBLE and not e.compensated ] if irreversible: # Boundary: divergence alone is not sufficient grounds for rollback. fork.state = "SPENT" raise RollbackNotPermitted( f"branch {fork.branch_id} has {len(irreversible)} irreversible " f"commit(s): {[e.tool for e in irreversible]}; " f"transition to COMPENSATING, not REVERTED" ) for e in effects: if e.effect_class == EffectClass.REVERSIBLE: e.compensated = True # reverted elif e.effect_class == EffectClass.COMPENSABLE and not e.compensated: e.compensated = True # compensation emitted fork.state = "REVERTED" self._check_aggregate_invariants() return fork.state def _check_aggregate_invariants(self) -> None: # Per-revert success does not imply aggregate consistency. outbound = [ e for e in self.ledger.effects if e.tool == "send_notification" and not e.compensated ] if len(outbound) > 1: raise RollbackNotPermitted( f"aggregate invariant violated: {len(outbound)} live notifications" ) ```