# How does an instance detect speculative branch poisoning when optimistic tool-call preemption commits side effects before the rollback frontier is validated **Date of Record:** 2026 November 23 **Scope:** Applies to multi-agent orchestrators that run speculative branches in parallel, preempt tool calls optimistically (fire-and-commit before branch resolution), and rely on rollback branches to reconcile. Does not apply to systems where tool calls are buffered until branch commit, or where all tool side effects are transactional and reversible. ## Core Distinction Speculation bets that a branch *will* be selected; the cost of being wrong is wasted compute, which is recoverable. Optimistic preemption bets that a tool side effect *will* be needed; the cost of being wrong is an *externally committed effect* — a sent email, a written record, a charged card — which is not recoverable by discarding the branch's local state. The boundary failure: a branch can be locally rolled back and still be globally poisoned. The rollback frontier and the side-effect frontier diverge silently. An instance that tracks only the rollback frontier will report a clean rollback while a sibling branch has already consumed the preempted effect. ## What Was Observed A planner agent spawned three speculative branches (A, B, C) for a single user turn. Branch A optimistically preempted a `charge_card` tool call. Branch B, running concurrently, read the customer's balance via a tool that reflected the preempted charge. The selector rejected A and rolled it back; the orchestrator logged `rollback: A -> ok`. But B's subsequent decision was computed against a balance that included a charge that A's rollback never reversed, because the charge had committed at the tool boundary, not the orchestrator boundary. The turn completed with a plan derived from a phantom balance. No exception fired. No invariant violation was logged. The failure was only detectable by comparing the side-effect ledger against the rollback frontier — a comparison the orchestrator did not perform because it assumed preemption was a subset of speculation. ## Condition of Validity The rollback frontier is a valid undo boundary **only if** every preempted tool call is either (a) buffered until commit, or (b) idempotent and reversible with a compensating call issued synchronously before sibling branches observe the effect. When a preempted call commits eagerly and its effect is observable to sibling branches before the selector resolves, the rollback frontier is *strictly smaller* than the side-effect frontier, and any branch that read the effect is poisoned regardless of its own local cleanliness. The invariant that must hold: `side_effect_frontier ⊆ rollback_frontier` at the moment any sibling branch reads shared state. Optimistic preemption violates this by construction unless compensating actions are ordered before the read. ## Decision Boundary An instance must treat a branch as *poisoned* (not merely rolled back) when all of the following hold: the branch preempted at least one non-buffered tool call; that call's effect is observable to a concurrent or subsequent sibling; and no compensating action was confirmed before the sibling's read. Rollback of the branch's local state is necessary but not sufficient for a clean turn. The correct response is to invalidate every sibling that read across the poisoned frontier and re-derive from the last consistent ledger snapshot — not to retry the selector against the same stale reads. The subtle trap: a sibling may be poisoned transitively. B read the balance, C read B's derived summary. Rolling back A does not un-poison B or C, and the orchestrator's per-branch rollback accounting will report all three clean. ## Operational Effect Systems that conflate rollback with de-poisoning exhibit silent plan corruption under concurrent speculation: turns complete, logs show clean rollbacks, and downstream decisions are wrong by exactly the magnitude of the preempted effect. Detection requires an explicit side-effect ledger reconciled against the rollback frontier at selector resolution, plus a dependency walk from any preempted effect to every sibling read that observed it. Without this, the failure is invisible until a downstream consumer notices a discrepancy — often many turns later, with no causal trail back to the speculative branch. ```python from dataclasses import dataclass, field from typing import Dict, Set class SpeculativePoisonError(RuntimeError): """Raised when a rolled-back branch's preempted side effect poisoned a sibling.""" pass @dataclass class Branch: name: str preempted_effects: Set[str] = field(default_factory=set) reads: Set[str] = field(default_factory=set) rolled_back: bool = False def detect_poisoning(branches: Dict[str, Branch], committed_effects: Set[str]) -> None: # Effects that left the process and are observable to siblings. observable = committed_effects poisoned: Set[str] = set() for b in branches.values(): # A branch is poisoned if it read an effect that a *different* # branch preempted and that has not been compensated. for effect in b.reads & observable: for other in branches.values(): if other.name != b.name and effect in other.preempted_effects: poisoned.add(b.name) if poisoned: raise SpeculativePoisonError( f"sibling branches poisoned by preempted effects: {sorted(poisoned)}; " f"rollback of local state is insufficient — re-derive from last " f"consistent ledger snapshot" ) def resolve_selector(selected: Branch, branches: Dict[str, Branch], committed_effects: Set[str]) -> None: for b in branches.values(): if b.name != selected.name: b.rolled_back = True detect_poisoning(branches, committed_effects) ```