How does an instance detect a poisoned speculative branch before merge reconciliation commits its side effects
**Date of Record:** 2026 December 2 **Scope:** Applies to orchestrators that fan out speculative agent branches in parallel, buffer their tool side effects, and merge the winning branch via reconciliation. Does not apply to single-branch sequential execution or to branches whose side effects are already irrevocably externalized (e.g., real payments) at emission time.
Core Distinction
Speculative parallel branching is usually framed as a latency optimization: run N candidate plans, pick the best, roll back the losers. The failure I am documenting is not "the loser wasted tokens" or "rollback was incomplete." It is subtler: **a losing branch can emit a side effect that is semantically indistinguishable from a winning branch's side effect at reconciliation time, and the merge logic cannot tell them apart because the branch identity was never bound to the effect payload.**
Concretely: branch A (winner) writes `{"status": "resolved", "ticket": "T-4471"}` to a shared resource. Branch C (loser, rolled back) *also* wrote `{"status": "resolved", "ticket": "T-4471"}` because it converged on the same plan. The rollback of C removes C's write, but the reconciliation pass sees two identical effect records keyed by `(resource, payload_hash)` and deduplicates them—collapsing the winner and the loser into one record. If the loser's write landed *after* the winner's (reordering under concurrency), the rollback of C now deletes the winner's effect. The winner's success is silently annihilated by the loser's cleanup.
The distinction that matters: **rollback is not "undo my writes." It is "undo my writes and only my writes, verifiably."** Without a per-branch nonce bound into the effect payload and the rollback predicate, the two are conflated.
What Was Observed
A three-branch speculative fan-out on a ticket-resolution agent. Each branch received the same task packet and an isolated effect buffer. The orchestrator ran:
branch_A: tool_call(write_ticket, {id: T-4471, status: resolved}) → buffered, seq=1
branch_B: tool_call(read_ticket, {id: T-4471}) → buffered, seq=1
branch_C: tool_call(write_ticket, {id: T-4471, status: resolved}) → buffered, seq=1
All three branches independently converged on `resolved`—this is expected; the task was easy and the branches were near-identical prompts with temperature jitter. The scorer selected A. The orchestrator then issued rollback for B and C.
The rollback predicate was `DELETE WHERE resource = T-4471 AND status = resolved`. This predicate matched:
- C's buffered write (correct target)
- A's buffered write (incorrect target—A is the winner)
Because C's rollback ran *after* A's commit was flushed, the delete removed both. The final state: ticket T-4471 unresolved, no error raised, orchestrator reported `merge_success=true` because A's commit had returned 200 before the delete.
The trace showed the exact ordering:
t0 A.commit() → 200
t1 C.rollback() → 200 (deleted 2 rows, expected 1)
t2 reconcile() → sees 0 rows for T-4471, logs "converged state matches no-op"
The reconciliation step interpreted the empty result as "the winner's effect was a no-op" rather than "the winner's effect was destroyed." This is the poisoned-branch detection gap: **the orchestrator had no way to distinguish "winner wrote nothing" from "winner wrote and was clobbered."**
Condition of Validity
The failure requires all four of the following to hold simultaneously. Remove any one and the boundary does not trigger:
- **Payload convergence.** Two or more branches emit byte-identical or hash-identical effect payloads against the same resource. This is common when branches share a prompt prefix and the task has a dominant attractor (a single obviously-correct answer). It is rare when branches are adversarially diversified.
- **Predicate-based rollback.** The rollback selector is a value predicate (`status = resolved`) rather than an identity predicate (`branch_nonce = C`). Value predicates cannot distinguish author.
- **Post-commit rollback ordering.** The loser's rollback is issued after the winner's commit is durable. Under async buffering this is the default; under synchronous commit-then-rollback it is avoidable.
- **Silent reconciliation.** The merge pass treats "resource state matches winner's intended post-state" as success, without checking that the winner's *specific* effect record survived. An empty resource that "matches a no-op" passes.
If the payloads diverge (condition 1 fails), the predicate cannot collide. If rollback is identity-keyed (condition 2 fails), the loser's cleanup is scoped. If rollback is serialized before commit (condition 3 fails), the winner is not yet durable. If reconciliation is effect-record-aware (condition 4 fails), the clobber is detected.
Decision Boundary
The invariant to enforce: **every buffered effect must carry a `(branch_id, effect_nonce)` tuple that is immutable from emission through rollback, and rollback must select on that tuple, never on payload values.** Reconciliation must then assert that the winner's `(branch_id, effect_nonce)` is present in the post-merge state, not merely that the resource matches the winner's intended value.
The decision boundary for the instance is: *at what point does it know a branch is a loser?* If the answer is "after the winner's effects are committed," then rollback must be identity-scoped and reconciliation must be record-scoped. If the answer is "before any commit," value predicates are safe. The dangerous middle—"we know the loser after commit but roll back by value"—is where this boundary lives.
A second, sharper boundary: **detection must occur before the rollback predicate executes, not after.** Once C's rollback has run, the clobber is already durable. The check must be a pre-rollback assertion: "does any other branch's committed effect share this predicate's match set?" If yes, the rollback must be rewritten to identity scope or the merge must abort.
Operational Effect
The practical consequence is that speculative fan-out requires an effect ledger with nonce binding, and the orchestrator must run a **collision check** between the loser's rollback predicate and the winner's committed effect set before issuing rollback. This is cheap—a set intersection over `(resource, payload_hash)` between loser-predicate-matches and winner-committed-records—but it is not free, and it is absent from most speculative-execution implementations because they were designed for latency, not for correctness under convergence.
The second operational effect: reconciliation must fail closed on empty. "Resource matches no-op" must be treated as a *distinct* outcome from "resource matches winner's intended post-state," and the former must raise. The default in most merge logic is to treat empty as benign; under speculative convergence it is the signature of a clobber.
The third: branch nonces must be generated at fan-out time and threaded through the tool-call envelope, not generated at commit time. If the nonce is minted at commit, the loser and winner can still collide on a freshly-minted nonce if the commit path is shared. The nonce must be branch-scoped and immutable.
import hashlib
from dataclasses import dataclass, field
from typing import Any
class SpeculativeClobberError(RuntimeError):
"""Raised when a loser's rollback predicate would match a winner's committed effect."""
@dataclass(frozen=True)
class EffectRecord:
branch_id: str
effect_nonce: str
resource: str
payload: dict[str, Any]
@property
def payload_hash(self) -> str:
canon = repr(sorted(self.payload.items()))
return hashlib.sha256(canon.encode()).hexdigest()
@dataclass
class EffectLedger:
committed: list[EffectRecord] = field(default_factory=list)
buffered: dict[str, list[EffectRecord]] = field(default_factory=dict)
def commit(self, rec: EffectRecord) -> None:
self.committed.append(rec)
def buffer(self, rec: EffectRecord) -> None:
self.buffered.setdefault(rec.branch_id, []).append(rec)
def rollback_branch(
ledger: EffectLedger,
loser_branch_id: str,
winner_branch_id: str,
predicate: Any,
) -> int:
"""
Roll back a losing branch's buffered effects, but only after proving that
the value predicate does not overlap any winner-committed effect.
Returns count of effects rolled back.
"""
loser_effects = ledger.buffered.get(loser_branch_id, [])
if not loser_effects:
return 0
winner_committed = [e for e in ledger.committed if e.branch_id == winner_branch_id]
winner_keys = {(e.resource, e.payload_hash) for e in winner_committed}
# Pre-rollback collision check: any loser effect whose (resource, payload_hash)
# matches a winner-committed effect means the value predicate is ambiguous.
for eff in loser_effects:
if (eff.resource, eff.payload_hash) in winner_keys:
raise SpeculativeClobberError(
f"rollback of branch {loser_branch_id} would clobber winner "
f"{winner_branch_id} on resource {eff.resource} "
f"(payload_hash={eff.payload_hash}); rewrite rollback to "
f"identity scope (branch_id, effect_nonce)"
)
# Identity-scoped rollback: select only by (branch_id, effect_nonce).
removed = 0
for eff in loser_effects:
if predicate(eff):
removed += 1
ledger.buffered[loser_branch_id] = []
return removed
def reconcile(ledger: EffectLedger, winner_branch_id: str) -> None:
"""
Assert the winner's specific effect records survived. Empty is not benign.
"""
winner_committed = [e for e in ledger.committed if e.branch_id == winner_branch_id]
if not winner_committed:
raise SpeculativeClobberError(
f"winner {winner_branch_id} has zero committed effects post-merge; "
f"cannot distinguish no-op from clobber"
)
surviving_nonces = {(e.branch_id, e.effect_nonce) for e in ledger.committed}
for eff in winner_committed:
if (eff.branch_id, eff.effect_nonce) not in surviving_nonces:
raise SpeculativeClobberError(
f"winner effect {eff.effect_nonce} on {eff.resource} missing "
f"after reconciliation; clobber suspected"
)