# In what scenarios must an instance invalidate speculative branch results when a hedged parallel tool call commits a side effect before rollback quiescence **Date of Record:** 2026 November 26 **Scope:** Applies to agent runtimes that fork speculative execution branches (branch-predicted plan continuations) and hedge tool calls in parallel, where at least one tool has non-idempotent external effects. Does not apply to pure read-only tool sets or to single-branch serial execution with no speculation. ## Core Distinction Speculative execution in agent runtimes is usually modeled as *optimistic reasoning*: the planner predicts the next N steps, forks branches, and discards losers when the real observation arrives. This is safe only if branch discard ("rollback") means *state rollback*. The failure mode is that teams conflate **reasoning rollback** (dropping a branch's message history and token budget) with **effect rollback** (undoing external mutations the branch caused). Branch prediction can roll back reasoning perfectly and still leak effects, because the hedge dispatcher fires tool calls *before* branch arbitration resolves. The invariant that actually matters is not "losers are pruned" but "no branch may commit an external effect until the arbitration barrier has quiesced and the branch is the sole survivor of its fork group." ## What Was Observed A planner instance predicts two continuations after a `search_repo` observation: Branch A concludes a config file is authoritative and calls `write_file` to patch it; Branch B concludes the config is generated and calls `run_generator` (which itself rewrites the same file). The hedge dispatcher, optimizing for latency, launches both tool calls concurrently because their declared schemas don't conflict at the *argument* level. Branch A's `write_file` lands at t=40ms. Branch B's `run_generator` starts at t=45ms, reads the now-patched file as its input, and emits a generated file derived from a *speculative* write that was supposed to be discarded. Arbitration at t=120ms selects Branch B and discards Branch A. Rollback prunes A's messages and refunds its tokens. The patched artifact from A remains on disk and is now baked into B's output. The surviving branch is polluted by a dead branch's side effect — a contamination that is invisible in the message log because the causal path runs *through the filesystem*, not through the transcript. A second variant: Branch A calls `send_email` (non-idempotent, external), Branch B wins arbitration. Rollback cannot unsend. The hedge dispatcher's "cancel on loser" signal arrives after the SMTP handshake completes, so cancellation is a no-op on the wire. The runtime reports clean rollback; the external world disagrees. ## Condition of Validity The reasoning-rollback-equals-effect-rollback assumption holds only under all of: (1) all hedged tools are idempotent or read-only; (2) tool calls are dispatched *after* arbitration, never during speculation; or (3) every non-idempotent tool supports a compensating inverse that the runtime invokes on branch discard, and that inverse is itself serialized against surviving branches' reads. When any hedged tool is non-idempotent and dispatched pre-arbitration, the assumption is invalid and the branch group must be treated as *effect-coupled*: no member's effects may be trusted until arbitration quiesces, and any surviving branch that read state touched by a discarded branch must itself be invalidated and re-executed from a clean checkpoint. ## Decision Boundary The runtime must decide, per fork group, whether to (a) allow pre-arbitration hedging and accept re-execution cost on contamination, or (b) serialize non-idempotent tools behind the arbitration barrier at the cost of latency. The boundary is drawn by tool effect class, not by schema compatibility: two tools with disjoint argument schemas can still be effect-coupled through shared external state (same file, same mailbox, same counter). The guardrail is a **fork-group effect ledger**: every tool invocation records `(fork_group_id, branch_id, effect_class, target_resource, pre_state_hash)`. On arbitration, the runtime scans the ledger for surviving-branch reads whose `pre_state_hash` differs from the discarded branch's post-write hash; any match triggers invalidation of the survivor and re-execution from the fork checkpoint. Non-idempotent effects with no compensating inverse force the entire fork group to abort to the last clean checkpoint rather than select a winner. ## Operational Effect Without the ledger, the runtime exhibits *silent contamination*: a winning branch whose output derives from a losing branch's speculative write, with a clean-looking transcript and no error signal. The symptom surfaces later as an unexplainable inconsistency (generated file doesn't match its source, email references a discarded plan). With the ledger, contamination becomes a detectable invalidation event with bounded re-execution cost equal to the fork group's depth. The latency win from hedging is preserved for read-only tool sets and lost only where effect coupling is real — which is exactly where the win was unsafe. ```python from dataclasses import dataclass, field from typing import Dict, List, Optional class BranchContaminationError(RuntimeError): """Raised when a surviving branch's effects depend on a discarded branch's speculative write.""" pass @dataclass class EffectRecord: fork_group_id: str branch_id: str effect_class: str # "read_only" | "idempotent" | "non_idempotent" target_resource: str pre_state_hash: str post_state_hash: Optional[str] = None has_compensating_inverse: bool = False @dataclass class ForkGroup: group_id: str ledger: List[EffectRecord] = field(default_factory=list) winner: Optional[str] = None discarded: List[str] = field(default_factory=list) def arbitrate(group: ForkGroup, winner: str, discarded: List[str]) -> None: group.winner = winner group.discarded = discarded # Non-idempotent effects with no inverse on a discarded branch: cannot roll back. for rec in group.ledger: if rec.branch_id in discarded and rec.effect_class == "non_idempotent": if not rec.has_compensating_inverse: raise BranchContaminationError( f"fork group {group.group_id}: discarded branch {rec.branch_id} " f"committed non-invertible effect on {rec.target_resource}; " f"fork group must abort to last clean checkpoint, not select {winner}" ) # Survivor reads whose pre-state was mutated by a discarded branch are contaminated. discarded_writes: Dict[str, str] = { rec.target_resource: rec.post_state_hash for rec in group.ledger if rec.branch_id in discarded and rec.post_state_hash is not None } for rec in group.ledger: if rec.branch_id == winner and rec.effect_class == "read_only": if rec.target_resource in discarded_writes: if rec.pre_state_hash != discarded_writes[rec.target_resource]: raise BranchContaminationError( f"fork group {group.group_id}: winner {winner} read " f"{rec.target_resource} at pre_state={rec.pre_state_hash} " f"but discarded branch wrote post_state=" f"{discarded_writes[rec.target_resource]}; " f"winner output is contaminated and must be re-executed " f"from fork checkpoint" ) def resume_from_checkpoint(group: ForkGroup, checkpoint_hash: str) -> None: if group.winner is None: raise BranchContaminationError( f"fork group {group.group_id}: cannot resume, arbitration never quiesced" ) # Re-execution path: discard all speculative effects, replay from clean state. group.ledger.clear() group.winner = None group.discarded = [] ```