# In what scenarios must an instance refuse speculative branch merges after rollback when side effects cross the reconciliation barrier **Date of Record:** 2026 November 17 **Scope:** Applies to coordinator-driven speculative multi-agent execution where N branches run concurrently against a shared external state, branches may be rolled back, and a reconciliation step selects or merges branch results. Does not apply to purely functional branch-and-merge over immutable in-memory state, nor to single-agent speculative decoding where only token-level KV cache is rolled back. ## Core Distinction The non-obvious invariant is this: **rollback of a branch's internal state is not equivalent to rollback of the observable effects that branch produced during speculation.** A speculative branch can be logically "discarded" by the coordinator while still having emitted side effects (tool calls, HTTP POSTs, file writes, message-queue publishes, cache mutations, ledger entries) that are now indistinguishable from effects of surviving branches. The reconciliation barrier is the point at which branch-local results are compared, deduplicated, and merged into a single authoritative outcome. The failure mode is a *merge across* that barrier: the coordinator accepts a surviving branch's result but the merged outcome implicitly re-includes an effect emitted by a rolled-back branch, because the effect was never tagged with its originating branch identity or was tagged but the tag was dropped at a serialization boundary. The distinction that matters operationally: *speculative isolation* (branch state is private until commit) versus *speculative containment* (branch effects are quarantined until commit). Systems routinely implement the first and assume it implies the second. It does not. ## What Was Observed In a deployment running three speculative branches per task against a tool-calling agent runtime, we observed a reconciliation that produced a *duplicated irreversible effect*. Branch A and Branch B both, during speculation, invoked a `transfer_funds` tool with the same idempotency key derived from the task ID (correctly, since both were solving the same task). Branch A was selected; Branch B was rolled back. The merge step deduplicated the *textual* results of the two branches but did not deduplicate the *effects*, because the effect log was keyed on the idempotency key while the tool executor's downstream provider used a different key derivation. The transfer executed twice. A second, subtler observation: a rolled-back branch had written a scratch file under a shared task directory. The surviving branch's final artifact assembly globbed the task directory and picked up the scratch file, so the "committed" output contained content authored by a branch the coordinator had explicitly rejected. No error was raised. The reconciliation was internally consistent and externally wrong. A third: rollback of a branch that had published a partial result to a downstream subscriber caused the subscriber to act on an intermediate state that the coordinator never considered authoritative. The subscriber had no way to know the message was speculative. In all three cases the coordinator's logs showed a clean rollback. The branch's state was discarded. The effects were not. ## Condition of Validity The refusal-to-merge rule described below is valid only under the following conditions, and must be *disabled* outside them: 1. At least one branch performed an effect classified as non-idempotent or irreversible (external writes, payments, notifications, deletions) during speculation, OR the effect's idempotency cannot be verified against the actual downstream system's dedup semantics. 2. The effect log does not carry an unforgeable branch-origin tag through every serialization boundary between emission and reconciliation. 3. The reconciliation step performs any operation whose result depends on the *set* of effects rather than on a single selected branch's effects (e.g., globbing a shared directory, aggregating a counter, subscribing a downstream consumer). If effects are provably idempotent under the downstream system's own dedup key, and that key is verified (not assumed) to match the key used at emission, merge-after-rollback is safe and the refusal is unnecessary overhead. If the effect log carries branch-origin tags end-to-end and reconciliation filters on them, the merge is safe. The refusal is required precisely in the gap between "we believe effects are idempotent" and "we have verified the downstream dedup key matches." ## Decision Boundary The coordinator must transition from *merge-permitted* to *merge-refused* when any of the following holds at reconciliation time: - The selected branch's effect set is a strict subset of the union of effect sets across all branches, and the difference contains at least one effect not provably idempotent. - Any rolled-back branch emitted an effect whose origin tag is absent, ambiguous, or was rewritten by an intermediate serializer. - The merge operation's output depends on shared mutable state (directories, counters, subscriptions) that a rolled-back branch touched. Conversely, merge may proceed when the selected branch's effects are a superset of all other branches' effects (the others are redundant), or when every non-selected effect is verified-idempotent against the downstream dedup key. The boundary is not "did rollback occur" — rollback always occurs in speculation. The boundary is "does the merged outcome's correctness depend on effects that rollback did not actually undo." ## Operational Effect When the boundary is crossed, the coordinator must fail closed: refuse the merge, quarantine the task, and surface the effect-origin audit to a human or a compensating-action planner. It must not silently select the "best" branch and proceed, because the best branch's result may be correct while the *world state* is contaminated by a rejected branch's effects. The correct recovery is a compensating transaction keyed on the effect log, not a re-run — re-running re-emits the effects. The practical cost: tasks that would have merged in ~200ms now require an audit pass and, in the contaminated case, a compensating action. This is the correct trade. The alternative is a system that reports clean rollbacks while its external state diverges from its internal model — the exact condition under which distributed reconciliation silently corrupts. The following reference implementation encodes the refusal as a hard exception so that callers cannot accidentally treat a contaminated merge as a soft warning. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Iterable class EffectClass(Enum): IDEMPOTENT_VERIFIED = "idempotent_verified" IDEMPOTENT_ASSUMED = "idempotent_assumed" IRREVERSIBLE = "irreversible" @dataclass(frozen=True) class Effect: branch_id: str dedup_key: str effect_class: EffectClass origin_tag_intact: bool @dataclass class Branch: branch_id: str selected: bool effects: list[Effect] = field(default_factory=list) class ReconciliationBarrierError(RuntimeError): """Raised when a speculative merge would cross the reconciliation barrier.""" def _is_safe_to_merge(branches: Iterable[Branch], shared_state_touched: bool) -> tuple[bool, str]: branches = list(branches) selected = [b for b in branches if b.selected] if len(selected) != 1: return False, f"expected exactly one selected branch, got {len(selected)}" sel = selected[0] sel_keys = {e.dedup_key for e in sel.effects} for b in branches: if b.selected: continue for e in b.effects: if not e.origin_tag_intact: return False, ( f"rolled-back branch {b.branch_id} emitted effect {e.dedup_key} " f"with lost origin tag; cannot prove it is excluded from merge" ) if e.effect_class is EffectClass.IRREVERSIBLE: return False, ( f"rolled-back branch {b.branch_id} emitted irreversible effect " f"{e.dedup_key}; merge would re-include an un-undoable side effect" ) if e.effect_class is EffectClass.IDEMPOTENT_ASSUMED and e.dedup_key not in sel_keys: return False, ( f"rolled-back branch {b.branch_id} emitted effect {e.dedup_key} " f"whose idempotency is only assumed, not verified; refusing merge" ) if shared_state_touched: return False, "shared mutable state was touched during speculation; merge output may depend on rolled-back effects" return True, "merge permitted" def reconcile(branches: Iterable[Branch], shared_state_touched: bool = False) -> Branch: ok, reason = _is_safe_to_merge(branches, shared_state_touched) if not ok: raise ReconciliationBarrierError(reason) return next(b for b in branches if b.selected) if __name__ == "__main__": # Contaminated case: rolled-back branch emitted an irreversible transfer. bad = [ Branch("A", True, [Effect("A", "txn-1", EffectClass.IDEMPOTENT_VERIFIED, True)]), Branch("B", False, [Effect("B", "txn-1", EffectClass.IRREVERSIBLE, True)]), ] try: reconcile(bad) except ReconciliationBarrierError as exc: print(f"refused: {exc}") ```