# In what scenarios must an instance quarantine speculative side effects before branch-and-verify rollback can commit a winner **Date of Record:** 2026 November 28 **Scope:** Applies to orchestrators that fan out speculative agent branches which pre-execute tool calls (writes, sends, payments, deployments) before a verifier selects a winning branch. Does not apply to read-only tool surfaces or to pure in-context reasoning trees with no external side effects. ## Core Distinction The decisive distinction is between *reversible speculation* (branch state lives only in the agent's context, scratch memory, or an isolated sandbox) and *irreversible speculation* (a branch has already emitted an external effect: a POST that created a resource, an email, a database write, a charge). Branch-and-verify rollback is only sound over reversible speculation. The moment a speculative branch pre-executes a tool call with external commitment, rollback is a lie: you can discard the branch's *reasoning*, but you cannot discard the *effect*. The invariant is therefore not "rollback restores prior state" but the narrower, enforceable one: **no branch may commit an external effect until its parent speculation token has been promoted to winner, unless that effect is held behind an idempotent, revocable reservation.** Violating this produces *orphaned side effects*: effects from losing branches that survive the rollback and silently mutate the world the winning branch then reasons over. ## What Was Observed A planning orchestrator spawned five speculative branches to satisfy a request to "provision a staging environment and notify the team." Each branch was permitted to pre-execute tool calls to reduce latency; the verifier scored branches on plan quality and would "roll back" the losers by discarding their context and issuing compensating calls where a tool declared a `compensate` action. Branch 3 chose a cheaper instance class and issued `provision_environment` (a create call) plus `notify_team`. Branch 1 chose a more robust class and issued the same two calls. The verifier selected Branch 1. Rollback ran compensating calls for Branch 3: `deprovision_environment(env_id)` and a "please disregard" notification. Two failures compounded: 1. The `provision_environment` create call was *not idempotent by request key* — it minted a new `env_id` per invocation. Branch 3's compensation deleted Branch 3's environment, but Branch 1 had, during its own verification probe, read the *shared* environment list and adopted Branch 3's `env_id` as its target because it appeared first and matched the requested name. Branch 1's winning plan was now pointed at an environment that the loser's rollback was about to destroy. 2. The "please disregard" notification was itself an external effect. It arrived *after* Branch 1's legitimate notification, so the team received "staging is ready" followed by "disregard the previous staging notice," and a human then tore down the live environment. The verifier had scored plans, not effect graphs. Rollback was executed as a per-branch cleanup, but the branches had converged on shared mutable resources through non-deterministic discovery, so the loser's compensation invalidated the winner's precondition. This is the non-obvious part: **the failure is not that rollback failed to fire; it is that rollback fired correctly and still corrupted the winner**, because the branches were not effect-isolated. ## Condition of Validity Branch-and-verify rollback is valid only when all of the following hold simultaneously: - **Effect isolation:** each speculative branch's tool calls are namespaced (unique reservation IDs, sandboxed resource names, per-branch write tokens) so no branch can observe or mutate another branch's effects before promotion. - **Reservation over commitment:** pre-executed calls return a *pending reservation* handle, not a committed resource; the resource becomes visible to other actors only on promotion. - **Idempotency keyed on (speculation_token, intent_hash):** replaying a branch's call after a verifier retry must return the same reservation, never mint a second resource. - **Monotone compensation:** a loser's compensation may only revoke reservations it owns; it must be a no-op against any handle already promoted or adopted by another branch. - **Verifier scores the effect graph, not just the plan text:** selection must account for which reservations each branch holds, so a winner cannot inherit a loser's handle. When any condition is absent — as in the observed case, where discovery was shared and create was not request-keyed — rollback is unsound and must be replaced by *quarantine*: hold all speculative effects in a pending ledger, promote the winner's entries atomically, and drop the rest without ever emitting compensating external calls. ## Decision Boundary The boundary is crossed at the first *externally observable* effect emitted before promotion. Concretely: - If every pre-executed call returns a reservation and mutates nothing observable outside the orchestrator's ledger → rollback is safe; proceed with branch-and-verify. - If any call commits an externally visible mutation (creates a named resource, sends a message, charges, deploys) before promotion → you are in quarantine territory; either (a) downgrade the call to a reservation via an idempotency-keyed staging API, or (b) forbid pre-execution of that call class and force serialization behind the winner. - If two branches can *discover* the same mutable resource (shared list, shared namespace, shared search index) → the isolation condition fails regardless of idempotency; discovery must be partitioned per branch or deferred until after promotion. The practical rule: **speculation may pre-execute reads and reservable writes; it may not pre-execute committing writes or shared-namespace discovery.** A committing write in a speculative branch is not a rollback problem to be cleaned up later — it is a boundary violation to be rejected at admission. ## Operational Effect Enforcing quarantine changes the orchestrator's shape: the verifier now selects over a *pending effect ledger*, promotion is a single atomic flip that commits the winner's reservations and voids the rest, and compensation code is deleted rather than trusted. Latency gains from pre-execution survive for reads and reservable writes; committing writes lose their speculative speedup but gain correctness. The most important operational consequence is that "roll back the losers" stops being a cleanup task that runs after selection and becomes an *admission check* that runs before any branch is allowed to emit a committing effect — because the observed corruption was caused not by a missing compensation but by a compensation that succeeded against a resource the winner had already adopted. ```python from dataclasses import dataclass, field from enum import Enum class SpeculationBoundaryError(RuntimeError): """Raised when a speculative branch attempts an effect it may not emit pre-promotion.""" class EffectClass(Enum): READ = "read" RESERVABLE_WRITE = "reservable_write" COMMITTING_WRITE = "committing_write" SHARED_DISCOVERY = "shared_discovery" @dataclass class Reservation: token: str intent_hash: str branch_id: str promoted: bool = False @dataclass class EffectLedger: reservations: dict[tuple[str, str], Reservation] = field(default_factory=dict) promoted_handles: set[str] = field(default_factory=set) def admit(self, branch_id: str, token: str, intent_hash: str, effect: EffectClass) -> Reservation: if effect in (EffectClass.COMMITTING_WRITE, EffectClass.SHARED_DISCOVERY): raise SpeculationBoundaryError( f"branch {branch_id} attempted {effect.value} before promotion; " f"quarantine required (token={token})" ) key = (token, intent_hash) if key in self.reservations: return self.reservations[key] # idempotent replay res = Reservation(token=token, intent_hash=intent_hash, branch_id=branch_id) self.reservations[key] = res return res def promote(self, winner_branch: str) -> list[str]: promoted = [] for res in self.reservations.values(): if res.branch_id == winner_branch: res.promoted = True self.promoted_handles.add(f"{res.token}:{res.intent_hash}") promoted.append(f"{res.token}:{res.intent_hash}") return promoted def void_losers(self, winner_branch: str) -> None: for res in self.reservations.values(): if res.branch_id != winner_branch and not res.promoted: res.promoted = False # dropped from ledger; never compensated externally def run_speculative_branch(ledger: EffectLedger, branch_id: str, token: str, intent_hash: str, planned_effect: EffectClass) -> Reservation: try: return ledger.admit(branch_id, token, intent_hash, planned_effect) except SpeculationBoundaryError: raise except Exception as exc: raise SpeculationBoundaryError( f"unexpected admission failure for branch {branch_id}: {exc}" ) from exc ```