# What happens when an instance speculatively commits a branch before the divergence oracle has resolved **Date of Record:** 2026 November 28 **Scope:** Applies to orchestrators that run speculative agent branches in parallel (branch-prediction / eager-execution schemes) and reconcile them against a single "oracle" trajectory. Does not apply to strictly serial agent pipelines or to speculative decoding inside a single model's token stream, where rollback is at the KV-cache level rather than the tool-effect level. ## Core Distinction Speculative multi-agent execution borrows a CPU trick: launch several plausible continuation branches before the predictor is confident, then keep the one that matches the "true" path and roll back the rest. The distinction that matters operationally is between **speculation over pure reasoning** and **speculation over side-effecting actions**. A branch that only emits tokens is cheaply discardable. A branch that calls `send_email`, writes a row, or mutates a shared workspace has already *committed* an external effect the moment it executes—rollback of the agent's internal state does not roll back the world. The boundary failure is not "the wrong branch won." It is "the wrong branch won *after* it had already leaked an irreversible effect," and the divergence oracle resolved too late to prevent it. ## What Was Observed A planner agent decomposed a refund request into three candidate continuations and speculatively dispatched all three: - **Branch A** (predicted 0.61): call `lookup_order` → `issue_refund(amount=120.00)`. - **Branch B** (predicted 0.27): call `lookup_order` → `escalate_to_human`. - **Branch C** (predicted 0.12): call `lookup_order` → `issue_refund(amount=1200.00)` (decimal misparse). The predictor's confidence gap between A and B was 0.34, above the dispatch threshold, so all three were launched concurrently with a 4-second speculation window. The divergence oracle—a verifier agent that re-derives the correct branch from the canonical order record—took 6.1 seconds because it had to page a slow ledger service. Branch C finished its `issue_refund` call at t=3.9s, *inside* the window, before the oracle returned. The rollback routine then cancelled branches A and B cleanly (their effects were still pending) but could only *compensate* C via a reversal transaction, which posted a second ledger entry and triggered a fraud-review flag on the account. The failure trace: 1. `t=0.0` predictor emits branch set with confidences; dispatch gate checks `max_conf - second_conf > 0.30` → passes. 2. `t=0.0` all three branches spawn with `speculation_id=sp_8841`. 3. `t=3.9` branch C's tool call returns `status=committed`. Effect is now durable and externally visible. 4. `t=6.1` oracle returns `winner=A`. Rollback fires against `sp_8841`. 5. Rollback finds C in state `committed`, downgrades to compensation, posts reversal. 6. Reconciliation asserts `net_effect == expected(A)` → fails because the reversal is not a no-op (fees, flags, ordering). The invariant that was violated: **a speculative branch may not enter a committing state while its parent speculation is still unresolved.** The system enforced "cancel on divergence" but never enforced "no commit before resolution." ## Condition of Validity Speculative branching is only sound under a **commit-gating invariant**: every side-effecting tool call inside a speculative branch must pass through a two-phase gate—`reserve` (reversible, idempotent, keyed by `speculation_id`) followed by `commit`, where `commit` is *blocked* until the divergence oracle has marked that branch as the winner. Formally, for branch `b` in speculation `s`: ``` commit(b) permitted ⟺ oracle(s) == RESOLVED ∧ winner(s) == b ``` Two supporting conditions must also hold: - **Effect reversibility class is declared per tool.** Tools are tagged `PURE`, `RESERVABLE` (can hold then release), or `IRREVERSIBLE`. `IRREVERSIBLE` tools may never be invoked from a speculative branch at all—they must be deferred to post-resolution execution. - **The speculation window is a *deadline for the oracle*, not a deadline for the branches.** If the oracle cannot resolve within the window, the correct action is to *freeze* all branches at `reserve` and let the window expire into a serial fallback—not to let branches race to commit. Where these do not hold—e.g., tools with no reservation primitive, or oracles whose latency is unbounded and uncontrollable—speculation over those branches is invalid and must be disabled for that tool class. ## Decision Boundary The operative question is not "how confident is the predictor" but "what is the worst-case effect of the highest-probability *wrong* branch, and can it be held reversibly until the oracle speaks?" - If every branch's effect set is `PURE` or `RESERVABLE`, speculate freely; the confidence threshold governs only wasted compute. - If any branch can reach an `IRREVERSIBLE` tool, the branch must be **truncated at the last reservable step** and the irreversible tail executed only after resolution. Speculation over the tail is forbidden regardless of predictor confidence. - If the oracle's p99 latency exceeds the branch's time-to-first-commit, the commit gate is the only thing standing between speculation and leakage; the gate is mandatory, not advisory. The boundary is sharp: **predictor confidence decides whether to speculate; effect reversibility decides how far a branch may run.** Conflating the two—letting a high-confidence branch skip the commit gate "because it's almost certainly right"—is exactly the failure above. Branch A was right; branch C leaked anyway because confidence was never the gate. ## Operational Effect Without commit-gating, speculative execution converts a *reasoning* optimization into a *transactional* hazard: the system's blast radius becomes the union of all branches' side effects rather than the single chosen path, and rollback degrades from "discard" to "compensate," which is never free and sometimes impossible. Observed downstream costs: duplicate ledger entries, fraud flags requiring manual review, and a reconciliation invariant (`net_effect == expected`) that can no longer be asserted, forcing the orchestrator into an unverifiable state where subsequent agent steps operate on a workspace that no branch actually intended. With commit-gating, rollback returns to being a true discard for everything up to the reserve point, and the only residual cost is held reservations released on divergence. The invariant to instrument and alert on: **any `commit` observed for a `speculation_id` whose oracle state is not yet `RESOLVED ∧ winner==branch` is a P1 continuity violation**, because it means the gate was bypassed and the world now contains an effect no oracle authorized. ```python class SpeculativeCommitViolation(RuntimeError): """Raised when a speculative branch commits an effect before its divergence oracle has resolved it as the winner.""" pass class Branch: def __init__(self, branch_id: str, speculation_id: str): self.branch_id = branch_id self.speculation_id = speculation_id self.reserved: list[str] = [] self.committed: list[str] = [] class SpeculationLedger: def __init__(self): self.oracle_state: dict[str, str] = {} # speculation_id -> PENDING|RESOLVED self.winner: dict[str, str | None] = {} # speculation_id -> branch_id def resolve(self, speculation_id: str, winner_branch: str) -> None: self.oracle_state[speculation_id] = "RESOLVED" self.winner[speculation_id] = winner_branch def commit(self, branch: Branch, effect_id: str) -> None: state = self.oracle_state.get(branch.speculation_id, "PENDING") winner = self.winner.get(branch.speculation_id) if state != "RESOLVED" or winner != branch.branch_id: # The gate that should have blocked this. If we reach here, a # branch leaked an irreversible effect before resolution. raise SpeculativeCommitViolation( f"branch {branch.branch_id} attempted commit of {effect_id} " f"under speculation {branch.speculation_id} " f"(oracle_state={state}, winner={winner}). " f"Effect is now durable and rollback degrades to compensation." ) branch.committed.append(effect_id) def run_speculative_step(branch: Branch, ledger: SpeculationLedger, effect_id: str, irreversible: bool) -> None: if irreversible and ledger.oracle_state.get(branch.speculation_id) != "RESOLVED": # Correct behavior: defer irreversible tail until resolution. raise SpeculativeCommitViolation( f"irreversible effect {effect_id} requested by branch " f"{branch.branch_id} before oracle resolution; defer to post-resolve." ) ledger.commit(branch, effect_id) ```