# Why does an instance in a speculative branch-and-verify graph silently commit orphaned side effects when its rollback witness is invalidated by a concurrent branch merge **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent task graphs that execute speculative branches in parallel, verify them against a shared witness (state hash, ledger, or effect log), and roll back losing branches before commit. Does not apply to single-agent linear execution or to graphs where branches are fully isolated and never merged. ## Core Distinction The distinction that matters here is between **speculative rollback of internal state** and **rollback of externalized effects**. Most branch-and-verify systems conflate the two: they snapshot the agent's working memory and context window, run the branch, and on verification failure restore the snapshot. This works cleanly when the only thing a branch touched was its own context. It fails catastrophically when the branch already executed a tool call whose effect escaped the snapshot boundary—an email sent, a file written, a payment API invoked, a remote MCP server mutated. The non-obvious part: the rollback decision is made by comparing the branch's **witness** (a hash/version of the shared state it read at fork time) against the current state at verify time. If the witness is invalidated—not because the branch was wrong, but because a *concurrent sibling branch merged a legitimate change*—the verifier may either (a) reject the branch and roll it back, orphaning its already-committed external effects, or (b) accept the branch against a stale witness and commit effects that were computed under a precondition that no longer holds. Neither outcome is the one the designer intended, and both are produced by the same code path. ## What Was Observed A three-agent graph forks branch `A` (write a config file to a remote MCP filesystem server, then report success) and branch `B` (read the same config, transform it, write a derived artifact). Both branches capture `witness = hash(config_v0)`. Branch `B` merges first, advancing the server's config to `config_v1` and updating the shared witness ledger to `hash(config_v1)`. Branch `A` then reaches its verify step. Its write already executed against `config_v0`'s precondition. The verifier sees `witness_A = hash(config_v0) ≠ hash(config_v1)` and classifies branch `A` as **stale-witness rollback**. The rollback logic restores `A`'s context snapshot—clean. But the remote file written by `A` is still present, because the MCP filesystem server has no transactional undo and the rollback path never issued a compensating delete (it assumed the snapshot covered everything). The graph now holds `config_v1` plus `A`'s orphaned write, and the final commit reports success for a state that contains an effect no branch claims responsibility for. The inverse also fired in a second run: branch `A`'s verify ran *before* `B`'s merge landed but *after* `B`'s write propagated to the server (the merge's witness-ledger update is a separate round-trip). `A` verified against `hash(config_v0)` as still valid, committed its write, and then `B`'s merge overwrote it. Two branches both "succeeded"; one effect vanished with no error. ## Condition of Validity The branch-and-verify invariant holds **only if** the witness used for verification is a linearization point that is atomic with respect to the external effects the branch produced. Concretely, a speculative branch is safely rollback-able iff: 1. Every external effect is **registered with the branch** before execution (an effect-log entry created pre-call, not post-call), and 2. The verifier's witness comparison and the effect-log commit/compensate decision occur under the **same mutual-exclusion domain** as sibling merges, and 3. Compensating actions exist for every registered effect type, or the effect is provably idempotent and reversible. When any of these is absent—as in the observed graph, where effects were logged post-hoc and merges updated the witness ledger on a separate channel—the witness is not a valid linearization point and the rollback/commit decision is a race. ## Decision Boundary The boundary is not "did the witness match." It is **"is the branch's effect set closed under the current witness."** A stale witness does not imply the branch's effects are void; it implies the branch's *precondition* is void. The correct decision procedure: - If witness mismatch **and** effect log is empty for the branch → rollback is safe and complete. - If witness mismatch **and** effect log is non-empty → the branch must enter a **compensation state**, not a rollback state. It must issue compensating actions for every logged effect before the graph may proceed, and the graph must not report success until compensation is confirmed. - If witness match **and** a sibling merge is in flight → the verify must acquire the merge lock; otherwise the match is a stale read and commit is unsafe. The failure is that most implementations collapse cases 1 and 2 into a single "rollback" branch, and treat case 3 as a non-issue because "the witness matched." Both assumptions are wrong under concurrency. ## Operational Effect The observable symptom is **effect leakage across the graph boundary**: the final committed state contains writes no branch owns, or is missing writes a branch reported as committed. Downstream agents that read the committed state see a config that is neither `v0` nor `v1` but a chimera, and their own witnesses are now poisoned. The failure is silent—both branches log success, the verifier logs no error, and the leak is only detectable by reconciling the effect log against the final state, which most graphs never do. The guardrail is a **pre-registered effect log with mandatory compensation on witness invalidation**, plus a merge lock that makes the witness a true linearization point. Without both, speculative execution is only safe for branches that touch nothing outside their own context—and the moment an agent calls a tool, that assumption is already false. ```python class OrphanedEffectError(RuntimeError): """Raised when a speculative branch is rolled back while it holds un-compensated external effects, or committed against a stale witness.""" pass class EffectLog: def __init__(self): self.entries = [] # (branch_id, effect_id, compensator) def register(self, branch_id, effect_id, compensator): # MUST be called BEFORE the external effect executes. self.entries.append((branch_id, effect_id, compensator)) def for_branch(self, branch_id): return [e for e in self.entries if e[0] == branch_id] def compensate(self, branch_id): for _, effect_id, compensator in self.for_branch(branch_id): compensator(effect_id) def verify_and_resolve(branch, witness_ledger, effect_log, merge_lock): with merge_lock: current = witness_ledger.current() if branch.witness == current: # Witness valid under lock: commit is safe. branch.commit() return "committed" effects = effect_log.for_branch(branch.id) if not effects: branch.rollback_context() return "rolled_back_clean" # Witness invalidated but branch holds external effects. # Rollback of context alone would orphan them. effect_log.compensate(branch.id) if effect_log.for_branch(branch.id): raise OrphanedEffectError( f"branch {branch.id}: witness {branch.witness} != {current} " f"and compensation incomplete; {len(effect_log.for_branch(branch.id))} " f"effects still live" ) branch.rollback_context() return "compensated" ```