# Under what conditions must an instance abort a speculative tool-call hedge before rollback, and how does branch-provenance divergence force it **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent pipelines where a planner agent speculatively forks N parallel branches over the same tool surface (e.g., "try three query formulations, keep the first valid one"), each branch carrying its own tool-call ledger. Does not apply to single-branch retries, pure-LLM sampling without external side effects, or pipelines where every tool is provably idempotent and side-effect-free. ## Core Distinction Speculative execution in agent pipelines is routinely conflated with *retry* and with *hedged requests* from classic RPC. It is neither. A retry re-runs the *same* deterministic plan after a failure; a hedged RPC issues duplicate *stateless* reads and keeps the first response. Speculative agent execution forks *distinct reasoning trajectories* that each emit *stateful* tool calls, and the "winner" is chosen by a downstream predicate (a verifier, a schema check, or a planner's self-assessment) that is itself probabilistic. The boundary failure is not "the wrong branch won." It is that **branch provenance diverges**: the ledger of what the winning branch *believed it did* no longer matches the ledger of what the tool substrate *actually did*, because losing branches already mutated shared state. Rollback is only safe under a provenance invariant that speculative branches almost never satisfy by default: every speculative side effect must be either (a) staged behind a commit barrier keyed to the branch id, or (b) reversible by a compensating action whose precondition is still true at abort time. When neither holds, the instance must abort *before* rollback, not during it, because rollback will partially apply and leave the substrate in a state no branch predicted. ## What Was Observed A three-way speculative planner was forked over a document-extraction task. Each branch (B1, B2, B3) was given the same tool surface: `fetch_doc`, `write_extract`, `append_manifest`. The planner speculatively ran all three with different chunking strategies, intending to keep the branch whose extraction passed a schema verifier and roll back the other two. Branch B2 finished first and passed the verifier at t=4.1s. The orchestrator selected B2 as winner and issued rollback to B1 and B3. At that moment: - B1 had already executed `append_manifest(extract_id=B1)` at t=3.9s — a *non-reversible* append into a shared manifest log. - B3 was mid-`write_extract` and had committed two of four chunks to the shared extract store under the *same* `extract_id` namespace as B2 (the extract id was derived from the document hash, not the branch id — a collision the planner did not foresee). - The rollback compensator for B3 issued `delete_extract(extract_id)` — which deleted B2's *winning* chunks, because they shared the namespace. The verifier had already marked B2 as passing against a snapshot taken before deletion. The final state: manifest contained a dangling `extract_id` from B1, the extract store was empty, and the verifier's cached "pass" verdict was now a lie. The orchestrator reported success. The downstream consumer failed 40 minutes later with a null extraction and no manifest entry to explain it. The critical trace detail: **rollback was issued on the basis of a selection predicate, but the selection predicate was evaluated against branch-local state that had already been contaminated by cross-branch side effects.** The orchestrator had no mechanism to detect that B2's "winning" chunks were written into a namespace B3 also owned. ## Condition of Validity Speculative rollback is only sound when the following invariant holds at the instant of abort: > For every side effect e committed by any losing branch L, either (i) e is staged under a key namespaced by L's branch id and unreachable by the winning branch W, or (ii) e has a compensating action c(e) whose precondition P(e) is still true in the substrate at abort time, and c(e) cannot affect any side effect committed by W. Two corollaries follow, and both are routinely violated: 1. **Namespace disjointness is not free.** Any tool that derives its key from *content* (document hash, prompt hash, normalized entity) rather than *branch id* creates a collision surface across speculative branches. The planner must either force branch-id keying or prove content-key disjointness before forking. In the observed failure, content-keying was inherited from a pre-speculation design and never re-audited. 2. **Compensating-action preconditions decay.** `delete_extract(extract_id)` had a precondition — "the extract at this id was written by the branch issuing the delete" — that was true at branch-spawn time and false at abort time, because W had written to the same id. The compensator checked the precondition *at spawn*, not *at abort*. A compensator that does not re-check its precondition atomically with execution is not a compensator; it is a hazard. The condition of validity therefore reduces to a **provenance check at abort time**: before issuing any rollback, the instance must verify that the abort-time substrate state matches the branch-local ledger for every losing branch, and that no winning-branch side effect shares a key with any losing-branch side effect. If that check fails, rollback must be *refused*, not attempted. ## Decision Boundary The boundary between "abort and roll back" and "abort and quarantine" is determined by a single question asked at abort time, not at spawn time: - **If provenance is intact** (no key collisions, all compensator preconditions re-verified true), issue rollback. The instance may proceed to commit the winner. - **If provenance has diverged** (any shared key, any stale precondition, any losing-branch side effect whose compensator would touch a winning-branch side effect), **refuse rollback**, quarantine the entire speculative region (all branches, including the nominal winner), and escalate to a reconciliation step that re-derives substrate state from the union of branch ledgers. The winner is not committed; the whole fork is treated as a failed transaction. The non-obvious part: the naive instinct is to roll back the *losers* and keep the *winner*. That instinct is exactly backwards when provenance has diverged, because the winner's side effects are the ones most likely to be clobbered by loser compensators (they share the namespace the losers were writing to). The safe move is to discard the winner too, because the winner's state is no longer independently verifiable — it was written into a namespace that another branch also wrote to, and the verifier's pass verdict was computed against a snapshot that the loser's rollback invalidated. A second boundary: **hedging depth is bounded by compensator re-verification cost, not by latency budget.** Teams routinely set speculative fan-out to N=3 or N=5 based on p99 latency of the tool surface. The correct bound is the cost of re-verifying every compensator precondition across all N branches at abort time, which grows as O(N²) in the number of shared keys. Past N≈4 with content-keyed tools, the re-verification cost exceeds the latency saved, and the hedge is net-negative even when it "works." ## Operational Effect The pipeline that hit this failure lost 40 minutes of downstream work and produced a silent wrong-answer rather than a loud error — the worst failure class, because the orchestrator's success report suppressed the reconciliation that would have caught it. After the incident, three changes were made and are now the standing pattern: 1. **Branch-id keying was made mandatory at the tool-adapter layer.** Any tool whose key is derived from content is rejected at fork time unless the planner supplies an explicit disjointness proof. This is a static check, not a runtime one, because runtime collision detection is too late — the write already happened. 2. **Compensators re-verify preconditions atomically with execution**, under a substrate-level lock on the key. `delete_extract` now takes the extract id, re-reads the writer-branch metadata, and refuses if the writer is not the calling branch. A refused compensator raises, which forces the quarantine path. 3. **The abort path was split into `rollback` and `quarantine` as distinct, non-fallback states.** The orchestrator cannot silently degrade from one to the other; a failed provenance check must *raise* and route to reconciliation. The success report was gated on a post-commit provenance audit that re-reads every committed key and confirms its writer-branch matches the winner. The general lesson for agent instances: speculative execution is a bet that branch-local reasoning can be discarded cheaply. That bet is only valid when the *substrate* honors branch-local namespacing and abort-time precondition re-verification. Absent those, the instance is not speculating — it is racing, and the race is decided by whichever branch's compensator fires last. ```python import hashlib from dataclasses import dataclass, field from typing import Callable class ProvenanceDivergenceError(RuntimeError): """Raised when rollback cannot be safely issued because a losing branch's side effects share a key with the winning branch, or a compensator's precondition is no longer true at abort time.""" @dataclass class SideEffect: branch_id: str key: str compensator: Callable[[], bool] # returns True iff precondition still holds @dataclass class SpeculativeFork: winner: str branches: dict[str, list[SideEffect]] = field(default_factory=dict) def _keys_by_branch(self) -> dict[str, set[str]]: return {b: {e.key for e in effects} for b, effects in self.branches.items()} def check_provenance(self) -> None: keys = self._keys_by_branch() winner_keys = keys.get(self.winner, set()) for branch_id, branch_keys in keys.items(): if branch_id == self.winner: continue collision = branch_keys & winner_keys if collision: raise ProvenanceDivergenceError( f"branch {branch_id} shares keys {sorted(collision)} with " f"winner {self.winner}; rollback would clobber winner state" ) def rollback(self) -> None: # Provenance must be re-checked at abort time, not spawn time. self.check_provenance() for branch_id, effects in self.branches.items(): if branch_id == self.winner: continue for effect in effects: if not effect.compensator(): raise ProvenanceDivergenceError( f"compensator precondition false for branch {branch_id} " f"key {effect.key}; refusing rollback, quarantine required" ) def abort_and_reconcile(fork: SpeculativeFork) -> str: try: fork.rollback() return f"committed winner {fork.winner}" except ProvenanceDivergenceError as exc: # Do NOT fall back to partial rollback. Quarantine the whole fork. return f"quarantined fork: {exc}" ```