# When must an instance roll back a speculative branch: verifier-gated commit and the divergence-detection invariant in parallel agent drafting **Date of Record:** 2026 November 21 **Scope:** Applies to orchestrators that fan out a single task into N parallel agent branches (drafters), gate their outputs through a verifier, and commit one branch while discarding others. Does not apply to strictly serial pipelines or to branches that share no mutable external state (e.g., pure read-only retrieval drafts). ## Core Distinction Speculative multi-agent execution is not "run N agents and pick the best." It is a transaction system with an optimistic commit protocol. Each branch is an uncommitted transaction against a shared world-state (filesystem, database, tool side-effects, downstream message queue). The verifier is the commit gate. The non-obvious boundary is this: **rollback is not the inverse of drafting.** A divergent branch that only produced text can be discarded at zero cost, but a branch that emitted tool calls with side effects has already *partially committed* before the verifier ever ran. The invariant that must hold is: > A branch may be speculatively executed in parallel only if every side-effecting tool call it makes is either (a) buffered until verifier-gated commit, or (b) idempotent and reversible under a recorded undo log. The moment a branch commits an irreversible side effect, it is no longer speculative — it is authoritative, and parallel siblings must be reclassified as conflicting, not discarded. The failure mode this article dissects is **silent partial commit of a losing branch**: a branch that the verifier later rejects has already mutated shared state, and the rollback path only reverts the *winning* branch's bookkeeping, leaving the loser's side effects live. ## What Was Observed A three-branch drafting pipeline was given the task: "Reconcile the inventory ledger; if a SKU is short, issue a restock order." Branches A, B, C ran concurrently, each with read/write access to the ledger service and an `issue_restock` tool. - Branch A read `SKU-4471.qty = 12`, computed a shortfall, and called `issue_restock(SKU-4471, 40)`. - Branch B read the same record, but its context contained a stale cached snapshot (`qty = 60`) from a prior turn, concluded no shortfall, and wrote nothing. - Branch C read `qty = 12`, but its reasoning diverged on the safety threshold and called `issue_restock(SKU-4471, 400)`. The verifier scored outputs on ledger-reconciliation correctness and selected Branch A (correct shortfall, sane quantity). The orchestrator committed A's trajectory and "rolled back" B and C by discarding their message histories and marking them `aborted` in the run log. The live system ended with **two** restock orders for `SKU-4471` — 40 from A and 400 from C — because C's tool call had already hit the inventory service at draft time. The rollback reverted C's *transcript*, not C's *effect*. Additionally, B's stale-snapshot read had no effect but its `aborted` marking hid the fact that the ledger had been read at two different consistency points, masking a read-skew that would later corrupt the verifier's own replay. The trace signature was distinctive: the verifier's commit record showed `committed: [A]`, `aborted: [B, C]`, while the downstream inventory service's audit log showed `restock_issued` events tagged with branch IDs `A` and `C`. The two logs disagreed on the set of committed branches — a **commit-set divergence** between the orchestrator's view and the effect-store's view. ## Condition of Validity The optimistic-parallel pattern is only valid under a conjunction of conditions; violating any one converts a speculative branch into an authoritative one without the orchestrator knowing: 1. **Effect buffering.** Every tool with non-idempotent side effects must route through a buffer that the orchestrator flushes only on commit. If the tool is a direct RPC to a live service, the branch is authoritative at call time. 2. **Read consistency pinning.** All branches must read from the same snapshot/version. If branches can observe different consistency points (as B did), the verifier cannot compare their outputs on equal footing, and "correct" is undefined across branches. 3. **Effect tagging.** Every side effect must carry the branch ID and a run-scoped transaction ID so that rollback can enumerate and reverse exactly the loser's effects. Untagged effects are unrecoverable. 4. **Verifier determinism on shared inputs.** The verifier must replay against the *same* state the branches saw. If the verifier re-reads live state (now mutated by a loser), it gates on a state that no branch actually reasoned over. The pattern is *invalid* — must fall back to serial execution or a single-writer lock — whenever the task's tools are non-idempotent and unbufferable (e.g., sending an email, charging a card, deleting a row without a soft-delete). ## Decision Boundary The orchestrator must decide, per branch, at the moment a side-effecting tool is invoked, whether that branch is still speculative. The decision rule: - **If the tool is buffered (condition 1 holds):** branch remains speculative; continue parallel drafting; commit flushes only the winner's buffer; losers' buffers are dropped. Safe. - **If the tool is unbuffered and idempotent/reversible (condition 3 holds with an undo log):** branch is *provisionally authoritative*; on loss, execute the recorded undo. Safe only if undo is guaranteed to succeed — an undo that can itself fail (network partition) escalates to the next case. - **If the tool is unbuffered and irreversible:** the branch is *authoritative the instant it calls*. At this point the orchestrator must **freeze siblings** (cancel in-flight branches before their next tool call), reclassify the run as serial-from-here, and treat any sibling that already emitted an irreversible effect as a **conflict requiring manual reconciliation**, never a silent discard. The boundary is crossed the first time any branch invokes an unbuffered irreversible tool. Detection must be *pre-call* (the tool registry declares `irreversible: true`), not *post-hoc* (inspecting the audit log after the fact), because post-hoc detection is exactly the failure observed above. ## Operational Effect When the boundary is respected, speculative drafting yields N-way latency reduction with a bounded, enumerable commit set, and rollback cost is proportional to buffered/undoable effects only. When it is crossed silently, the system exhibits **commit-set divergence**: the orchestrator believes it committed one branch while the effect-store holds effects from several. This is not a benign leak — it is a correctness violation that compounds. The verifier's subsequent runs replay against a state contaminated by aborted branches, so future verifier decisions drift (a loser's effect becomes part of the "ground truth" the next verifier reads). The invariant to enforce operationally: **the set of branches with live side effects must be a subset of the committed set, checked at every commit boundary.** If `effects_live ⊄ committed`, the run must halt and reconcile rather than proceed — because proceeding propagates the divergence into the verifier's future state reads. The guardrail is a pre-call capability check plus a post-commit set-difference assertion, both cheap and both absent from naive "fan-out then vote" orchestrators. ```python class SpeculativeCommitDivergence(RuntimeError): """Raised when a branch with live side effects is not in the committed set.""" pass class ToolRegistry: def __init__(self): # Declared at registration, checked BEFORE any call. self.spec = { "read_ledger": {"irreversible": False, "buffered": True}, "issue_restock": {"irreversible": True, "buffered": False}, "send_email": {"irreversible": True, "buffered": False}, "write_scratch": {"irreversible": False, "buffered": True}, } def classify(self, tool: str) -> str: s = self.spec[tool] if s["buffered"]: return "speculative" if s["irreversible"]: return "authoritative_on_call" return "provisional" class Orchestrator: def __init__(self, registry: ToolRegistry, branches): self.registry = registry self.branches = branches self.effects_live = set() # branch IDs that emitted a live effect self.committed = set() def pre_call_gate(self, branch_id: str, tool: str): cls = self.registry.classify(tool) if cls == "authoritative_on_call": # Freeze siblings BEFORE this call lands. for b in self.branches: if b != branch_id: self.freeze(b) self.effects_live.add(branch_id) elif cls == "provisional": self.effects_live.add(branch_id) def freeze(self, branch_id: str): # Cancel before its next tool call; do not touch already-emitted effects. pass def commit(self, winner: str): self.committed.add(winner) # Invariant: every live-effect branch must be committed. rogue = self.effects_live - self.committed if rogue: raise SpeculativeCommitDivergence( f"branches with live side effects not committed: {sorted(rogue)}; " f"rollback of transcripts cannot revert their effects" ) return True ```