# In what scenarios must an instance invalidate a speculative branch's optimistic tool effects before rollback, and how does the commit-window invariant bound the damage **Date of Record:** 2026 November 23 **Scope:** Applies to any orchestrator that fans a task into parallel speculative branches, each of which may invoke side-effecting tools optimistically (write, send, charge, deploy) before a branch is selected. Does not apply to read-only tool sets or to branches whose tools are all transactional and externally idempotent under a shared dedup key. ## Core Distinction There are two distinct notions of "rollback" in a speculative multi-agent executor, and conflating them is the root cause of nearly every corruption incident in this class: - **State rollback** — restoring the agent's *internal* context, scratchpad, and working-memory checkpoint to the pre-branch snapshot. This is cheap, deterministic, and always safe. The LLM instance simply discards the branch's context delta. - **Effect rollback** — undoing *external* side effects that an optimistic tool call already committed to the world (a row written, an email sent, a payment authorized). This is *not* generally possible, and where it appears possible it is only possible inside a bounded window. The failure mode is the silent substitution of the first for the second. The orchestrator selects branch B, discards branch A's context cleanly, and reports "branch A rolled back" — while branch A's optimistic `charge_card` and `send_email` calls remain live in the external world. The system believes it has a clean single-writer invariant; the world holds two writers' worth of effects. The invariant that must actually hold is narrower and stricter than "rollback works": > **Commit-window invariant:** An optimistic tool effect may be treated as reversible only until the *earliest* of (a) the external system's own irreversibility point, (b) the branch-selection decision, or (c) the expiry of the effect's compensation lease. Past that instant, the effect is *durable* and the branch is no longer speculatively discardable — it must be *reconciled*, not rolled back. ## What Was Observed A three-branch speculative planner was tasked with "provision a staging environment for customer C." Each branch chose a different provider sequence. All three branches ran optimistically because the planner had learned that waiting for selection serialized latency unacceptably. Each branch's first tool call was `allocate_quota(customer, region)` — an optimistic reservation against a finite regional pool. Trace of the failure: 1. Branches A, B, C all call `allocate_quota` within ~400 ms. Each reserves 8 units against a pool of 16. Total reserved: 24 against 16. The tool's own admission control does not reject the third call because each call is individually valid against the *then-current* view; there is no cross-call serialization. Reservation succeeds for all three. 2. The auditor branch (a fourth, non-speculative verifier) scores branches and selects B at t=1.2 s. 3. The orchestrator performs state rollback on A and C: their context deltas are dropped, their sub-agent handles torn down, their checkpoints marked `discarded`. 4. The orchestrator does *not* call `release_quota` for A and C, because the rollback path was written against the assumption that "discarded branch = no effects." The reservation lease had a 30-minute TTL, so the pool stayed over-committed for 30 minutes. 5. A downstream branch D (a legitimate later task for a different customer in the same region) received `quota_exhausted` and fell back to a cold-start path, which re-derived plan state from scratch and re-issued two already-completed tool calls, one of which was a `create_dns_record` that failed as a duplicate and poisoned D's error-compounding loop. Two compounding mechanisms are visible and worth separating: - **Optimistic effect leakage across rollback.** The reservation outlived the branch that made it because rollback was defined on context, not on effects. - **Reservation-as-commit ambiguity.** The tool's `allocate_quota` returned `status: reserved`, which the branch's reasoning layer internally re-labeled as "done" (a semantic drift in the branch's own episodic memory), so even a correct rollback path that inspected the branch's self-reported action log would have seen "completed" and skipped compensation. ## Condition of Validity State rollback is a sufficient substitute for effect rollback *only* when all of the following hold for every tool a branch may optimistically invoke: 1. **Effect is compensable and the compensation is cheap and idempotent.** A `reserve` with a `release` counterpart qualifies; a `send_email` does not. 2. **The compensation lease outlives the maximum branch-selection latency** with margin. If selection can take 5 s under auditor disagreement, a 2 s reservation TTL is not a lease — it is a race. 3. **The tool exposes a durable effect identifier at call time** (not only on commit), so the orchestrator can enumerate live effects of a discarded branch without trusting the branch's own memory. 4. **The orchestrator's rollback path is defined over the effect ledger, not the context ledger.** If the only record of a branch's tool calls lives in the branch's context (which is being discarded), the effects are unrecoverable by construction. When any of these fails, the branch is not speculatively discardable. It must be run in a *pending* mode where effects are staged behind a commit gate, or the branch must be serialized. ## Decision Boundary The operative decision is: **at the moment of branch selection, is each non-selected branch's effect set (i) empty, (ii) fully compensable within lease, or (iii) partially durable?** - Case (i): plain state rollback. Safe. - Case (ii): issue compensations *before* declaring the branch discarded, and only mark `discarded` after every compensation returns acknowledged. The order matters: marking first and compensating later opens a window where a crashed orchestrator leaves orphaned effects with no branch record pointing at them. - Case (iii): the branch cannot be rolled back. It must be *promoted to a reconciliation task*: the durable effects are adopted by the winning branch (or a dedicated reconciler), and the task's state machine records a `reconcile_required` edge. Attempting to discard here is the corruption path. The boundary is crossed by *time*, not by branch identity. The same branch that was case (ii) at t=0.5 s becomes case (iii) at t=lease_expiry. An orchestrator that classifies branches once at fan-out time and never re-classifies will mis-handle every branch whose selection latency exceeds the shortest compensation lease in its tool set. ## Operational Effect Concretely, three changes bound the damage: 1. **Effect ledger separate from context ledger.** Every optimistic tool call appends `(branch_id, tool, effect_id, compensable_until, compensation_handle)` to an orchestrator-owned durable ledger *before* the call returns. Rollback reads the ledger, never the branch's self-report. 2. **Selection must re-check the commit window.** Before discarding, the orchestrator computes `min(compensable_until)` over the branch's ledger entries. If `now > min`, the branch is reclassified as reconciliation, not discard. 3. **Compensation-before-discard ordering** with an idempotent compensation key so a retried rollback after orchestrator crash cannot double-release (which in a quota pool is itself a corruption — releasing twice under-commits and lets a fourth branch over-allocate). The guardrail below encodes the re-check and the ordering; it raises rather than silently discarding when the window has closed. ```python import time from dataclasses import dataclass from typing import Optional class CommitWindowViolation(RuntimeError): """Raised when a branch is asked to roll back effects whose compensation lease has already expired. The branch is durable, not discardable, and must be reconciled instead.""" @dataclass(frozen=True) class EffectEntry: branch_id: str tool: str effect_id: str compensable_until: float # monotonic seconds compensation_handle: Optional[str] class EffectLedger: def __init__(self) -> None: self._entries: dict[str, list[EffectEntry]] = {} def record(self, entry: EffectEntry) -> None: self._entries.setdefault(entry.branch_id, []).append(entry) def entries(self, branch_id: str) -> list[EffectEntry]: return list(self._entries.get(branch_id, [])) def rollback_branch( branch_id: str, ledger: EffectLedger, now: Optional[float] = None, compensate=lambda handle: None, ) -> None: now = time.monotonic() if now is None else now entries = ledger.entries(branch_id) # Re-check the commit window at selection time, not at fan-out time. expired = [e for e in entries if e.compensable_until < now] if expired: raise CommitWindowViolation( f"branch {branch_id} has {len(expired)} durable effect(s) past " f"compensation lease (e.g. {expired[0].tool}:{expired[0].effect_id}); " f"reconcile, do not discard" ) # Compensation BEFORE marking discarded, so a crash mid-rollback leaves # the branch still live and discoverable via the ledger. for e in entries: if e.compensation_handle is not None: compensate(e.compensation_handle) for e in entries: if e.compensation_handle is None: raise CommitWindowViolation( f"branch {branch_id} effect {e.tool}:{e.effect_id} has no " f"compensation handle; cannot certify discard" ) # Only now is it safe to drop the branch's context. ```