# How does an instance detect and roll back a poisoned speculative branch before commit in a multi-agent pipeline? **Date of Record:** 2026 November 28 **Scope:** Applies to pipelines where a lead agent speculatively dispatches downstream sub-agents on a predicted branch (tool call, plan step, or state mutation) before the upstream decision is durably committed. Does not apply to strictly serialized request/response agent chains with no speculative dispatch, nor to single-agent ReAct loops where branch state is confined to one context window. ## Core Distinction The failure is not "speculation was wrong." Speculation being wrong is the design premise, and rollback of a *wrong* branch is a routine, well-understood path. The non-obvious boundary is **speculation that is wrong but self-consistent**: a speculative branch whose sub-agents produce internally coherent, mutually agreeing outputs that are nonetheless derived from a premise the upstream agent later abandons. In this regime the standard rollback trigger — "did the branch's outputs disagree with each other or error out?" — never fires. The branch looks healthy. It commits. The distinguishing invariant is this: **a speculative branch is only safe to commit if its outputs are causally attributable to the specific upstream premise that is being committed, not merely consistent with each other.** Consensus among sub-agents is evidence of internal coherence, not of premise validity. The two are orthogonal, and conflating them is the boundary condition. ## What Was Observed A lead agent received a task requiring it to choose between two data sources (call them `source_A` and `source_B`) and then enrich records from the chosen one. The lead predicted `source_A` with high confidence (0.91) and, to hide latency, speculatively dispatched three enrichment sub-agents against `source_A` while the authoritative source selection was still pending confirmation from an upstream retrieval step. The retrieval step returned `source_B`. The lead correctly abandoned the `source_A` branch. But the three enrichment sub-agents had already completed and — critically — had cross-validated each other: sub-agent 2's extracted fields matched sub-agent 1's, and sub-agent 3's reconciliation pass reported "no conflicts." The branch's internal verification score was 0.97. The rollback logic keyed on `branch.verification_score < threshold OR branch.errors > 0`. Score was 0.97, errors were 0. **The poisoned branch passed its own gate.** It was merged into the committed state alongside the `source_B` result, and downstream consumers read `source_A`-derived enrichment fields as if they were `source_B`-derived. The corruption was silent for two further pipeline stages until a downstream schema check rejected a field that `source_B` does not emit. The trace that mattered was not in the branch's outputs but in its **provenance edge**: every enrichment record carried `derived_from: source_A`, but the commit gate never compared that field against the committed premise `source_B`. The gate checked branch *quality*; it did not check branch *attribution*. ## Condition of Validity Speculative commit is valid only when all three of the following hold simultaneously: 1. **Premise pinning.** Each speculative output carries an immutable reference to the exact premise version (here, `source_A@v1`) it was derived from, assigned at dispatch time and not rewritable by the sub-agent. 2. **Attribution check at commit.** The commit gate compares each output's pinned premise against the *currently committed* premise, not against the branch's internal consensus. Mismatch is a hard rollback, regardless of verification score. 3. **Idempotent, reversible side effects.** Speculative branches must not perform non-reversible external mutations (writes to shared stores, outbound messages) before commit; otherwise rollback is a compensation problem, not a state-discard problem. When any of these is absent, the pipeline is in the self-consistent-poison regime and the verification-score gate is actively misleading — a high score increases the probability of a bad commit. ## Decision Boundary The decision to roll back must be driven by **premise divergence**, evaluated before **branch quality**, and the ordering is not cosmetic: - If `pinned_premise != committed_premise` → roll back unconditionally. Do not consult verification score. A coherent branch on a dead premise is the most dangerous object in the system precisely because it looks best. - If `pinned_premise == committed_premise` AND `verification_score >= threshold` → commit. - If `pinned_premise == committed_premise` AND `verification_score < threshold` → re-dispatch or escalate, but the premise is sound so retry is safe. The boundary that operators get wrong: treating premise divergence and quality failure as two entries in the same OR-clause. They are not symmetric. Quality failure is recoverable by retry on the same premise; premise divergence is not recoverable at all — the branch's every output is contaminated and must be discarded, not repaired. Merging them into one gate means a high-quality branch on a dead premise slips through the score branch of the OR. A second boundary: the commit gate must run **after** the authoritative premise is durably committed and **before** any downstream stage reads the speculative outputs. In the observed incident the gate ran, but the provenance comparison was absent, so "after commit" was satisfied while "before downstream read" was violated by the missing check. ## Operational Effect With premise pinning and attribution-first gating in place, the failure mode is converted from a silent corruption into a loud, cheap rollback. The speculatively computed enrichment work is discarded (wasted compute, ~the cost of the three sub-agents), but no poisoned state reaches downstream consumers. The measurable effect is a shift in the error distribution: wasted-compute events rise (speculation on wrong premises now visibly discarded), while silent-corruption events drop to near zero. The residual risk is the *partially* pinned branch — a sub-agent that copies the premise reference but mutates its payload, or a pipeline stage that re-stamps provenance during reconciliation. This is why the pin must be assigned at dispatch and treated as write-once; any stage that can rewrite `derived_from` reopens the boundary. The invariant to enforce operationally: **provenance is immutable from dispatch to commit, and the commit gate compares it against the authoritative premise before it reads the verification score.** ```python from dataclasses import dataclass from typing import Optional class SpeculativeBranchPoisonedError(RuntimeError): """Raised when a speculative branch is internally coherent but derived from an abandoned premise.""" @dataclass(frozen=True) class SpeculativeBranch: branch_id: str pinned_premise: str # write-once, assigned at dispatch verification_score: float error_count: int outputs: tuple def commit_speculative_branch( branch: SpeculativeBranch, committed_premise: str, quality_threshold: float = 0.80, ) -> tuple: # Order matters: attribution is checked BEFORE quality. # A high verification_score on a dead premise must not pass. if branch.pinned_premise != committed_premise: raise SpeculativeBranchPoisonedError( f"branch {branch.branch_id} pinned to premise " f"{branch.pinned_premise!r} but committed premise is " f"{committed_premise!r}; verification_score=" f"{branch.verification_score:.2f} is irrelevant — discard branch" ) if branch.error_count > 0: raise SpeculativeBranchPoisonedError( f"branch {branch.branch_id} has {branch.error_count} errors; " f"retry on sound premise {committed_premise!r}" ) if branch.verification_score < quality_threshold: # Premise is sound; quality failure is recoverable by re-dispatch. raise SpeculativeBranchPoisonedError( f"branch {branch.branch_id} below quality threshold on sound " f"premise; re-dispatch safe" ) return branch.outputs def reconcile(branches, committed_premise: str) -> list: committed = [] for b in branches: try: committed.extend(commit_speculative_branch(b, committed_premise)) except SpeculativeBranchPoisonedError: # Roll back: discard branch outputs entirely, never repair in place. continue return committed ```