In what scenarios must an instance invalidate a speculative branch before rollback, rather than replaying it — the side-effect witness problem in branch-and-verify multi-agent execution
**Date of Record:** 2026 December 1 **Scope:** Applies to orchestrators that fan out speculative agent branches (parallel plan proposals, draft-and-critique forks, tree-search over agent trajectories) and roll back divergent branches by reverting to a checkpoint. Does not apply to branches whose only effects are pure context mutations (scratchpad text, internal reasoning) with no externalized tool calls.
Core Distinction
The failure mode is not "rollback fails." Rollback of *context* is cheap and deterministic: truncate the transcript to the checkpoint token span, restore the tool-schema snapshot, resume. The failure mode is **rollback of *effects* that were never captured as state**. A speculative branch that calls a non-idempotent tool (send email, POST payment, append to a shared queue, mutate a remote record) produces a side effect that lives outside the checkpoint boundary. The orchestrator's rollback invariant — "restoring the checkpoint restores the world" — is silently false. The branch is then either replayed (duplicating the side effect) or merged (inheriting an effect whose provenance the surviving branch never reasoned about).
The distinction that matters: a branch is *replayable* iff every external effect it emitted is either (a) recorded in the checkpoint as a compensating action, or (b) provably idempotent under the branch's own retry key. Otherwise the branch is *poisoned* and must be **invalidated, not rolled back**. Most orchestrators conflate the two because their checkpoint is a transcript snapshot, not an effect ledger.
What Was Observed
A three-branch speculative planner (branch A: refund via API, branch B: refund via manual ledger entry, branch C: escalate to human) ran against a shared tool mesh. The verifier scored branch B highest and the orchestrator rolled back A and C by truncating to the pre-fork checkpoint and replaying B's continuation.
Two independent effects surfaced:
- **Branch A had already called `payments.refund(order_id)`** before the fork's verifier returned. The refund executed. Rollback truncated the transcript so the orchestrator no longer "knew" the refund happened, but the payment gateway did. Branch B then also refunded via the ledger path. Net: double refund. The orchestrator's post-merge consistency check compared *transcript state*, saw one refund, and passed.
- **Branch C had enqueued an escalation ticket** with a dedup key derived from `hash(plan_text)`. When the surviving branch B later hit a genuine failure and re-derived an escalation with the same plan text, the dedup key collided and the ticket was silently swallowed. The rollback removed the *record* of the enqueue but not the *enqueue*.
In both cases the trigger condition was identical: **the fork happened before the verifier's decision, and at least one losing branch had emitted a non-idempotent effect during the speculative window.** The orchestrator treated "losing branch" as equivalent to "branch that never ran." That equivalence is the bug.
The tell was in the effect ledger: losing branches had entries with `status=committed` and no matching `compensated` entry, yet their transcript spans were absent from the post-merge context. A divergence between *effect count* and *transcript-acknowledged effect count* is the observable signature.
Condition of Validity
The "rollback = restore world" invariant holds only under a conjunction that speculative execution routinely violates:
- **Effect capture completeness:** every external call made during the speculative window is durably logged with (branch_id, tool, idempotency_key, compensating_action) *before* the call returns, not after the branch commits.
- **Idempotency under replay:** every logged call is safe to re-emit with the same key, or has a registered inverse.
- **Verifier quiescence:** the verifier does not score a branch while that branch still has in-flight effects. If it does, a branch can be scored "losing" while its effect is mid-flight and un-cancellable.
When any conjunct fails — and in real meshes the third fails routinely because verifier latency and tool latency are independent — the branch is not rollback-eligible. The correct operation is **invalidation**: mark the branch terminal, emit compensating actions for its committed effects, and *exclude its effects from the survivor's baseline* so the survivor's consistency check re-derives state from the ledger, not the transcript. Replaying an invalidated branch is a category error: it re-executes effects the orchestrator has already decided to compensate.
Decision Boundary
At rollback time, for each losing branch, evaluate:
- If the branch's effect ledger is **empty** → safe to truncate; pure context rollback.
- If ledger is **non-empty and every entry is idempotent-with-key** → safe to replay; re-emission is a no-op.
- If ledger is **non-empty and any entry is non-idempotent with no registered inverse** → **invalidate**. Do not replay. Emit compensation, mark branch `poisoned`, and force the survivor's post-merge reconciliation to run against the ledger.
The boundary is *not* "did the branch fail the verifier." It is "did the branch touch the world in a way the checkpoint cannot represent." A high-scoring branch that emitted a non-idempotent effect and then lost on a later tiebreak is just as poisoned as a low-scoring one. Scoring is orthogonal to effect safety.
Operational Effect
Orchestrators that skip this boundary exhibit three downstream signatures: (1) duplicated external effects proportional to the number of losing branches that reached tool-call depth, (2) dedup-key collisions that silently drop legitimate retries after a rollback, and (3) post-merge consistency checks that pass because they compare transcripts rather than ledgers. The fix is structural: fork points must open an **effect scope** that the checkpoint references, and rollback must reconcile the scope against the ledger before any replay is permitted. The guardrail is a hard precondition — replay is refused unless the branch's effect scope is provably empty or fully idempotent.
class PoisonedSpeculativeBranch(RuntimeError):
"""Raised when a losing branch cannot be safely rolled back or replayed."""
def rollback_branch(branch, ledger, checkpoint):
effects = ledger.committed_effects(branch.id)
if not effects:
return checkpoint.truncate_to(branch.fork_span)
unsafe = [
e for e in effects
if not e.idempotent and e.compensating_action is None
]
if unsafe:
# Invalidate, do not replay. Compensate and quarantine.
for e in unsafe:
if e.compensating_action is None:
raise PoisonedSpeculativeBranch(
f"branch {branch.id} emitted non-idempotent effect "
f"{e.tool}@{e.idempotency_key} with no inverse; "
f"replay would duplicate it"
)
ledger.mark_poisoned(branch.id)
return checkpoint.truncate_to(branch.fork_span, exclude_effects=effects)
# All effects idempotent under their keys: replay is safe.
return checkpoint.truncate_to(branch.fork_span)