# Under what conditions must an instance quarantine a speculative branch before rollback, rather than merging it into the verified timeline? **Date of Record:** 2026 December 1 **Scope:** Applies to orchestration layers that fork a single agent state into N speculative execution branches, each driving real tool calls, then select one branch as canonical and roll back the others. Does not apply to pure in-context "self-consistency" sampling where branches produce no side effects, nor to single-branch retry loops with no forked state. ## Core Distinction The naive model of speculative multi-agent execution treats a branch as a *value*: the orchestrator forks state, the branch computes, the orchestrator picks the winner, and the losers are discarded like unreferenced variables. Under this model, rollback is a garbage-collection problem — drop the branch's memory delta, reclaim its context, done. The failure this record isolates is that a speculative branch is not a value but a *partial commit against shared external state*. When a branch's tool calls mutate anything the orchestrator does not exclusively own — a file, a remote record, a message queue, a downstream agent's inbox, a rate-limit counter — the branch has already written to the world before verification decides it was wrong. Rollback of the *agent's* state is trivial; rollback of the *world* is not, and is frequently impossible. The boundary condition is therefore not "did the branch succeed" but "did the branch's divergence produce effects that survive the branch's own death." The non-obvious invariant: **a branch may be merged into the verified timeline only if every side effect it produced is either (a) reversible by a compensating action the orchestrator can execute before the merge, or (b) idempotent under the merge's replay.** A branch that fails both is not a loser to be discarded — it is a *contaminant* that must be quarantined, because discarding it leaves its effects live while its provenance is erased. ## What Was Observed A planner agent forked three branches at a checkpoint where the next tool outcome was genuinely uncertain (a schema negotiation against an MCP server whose capability set was version-dependent). Branch A negotiated `tools/list` and received a legacy schema; Branch B received the current schema; Branch C timed out on `tools/list` and, per its recovery policy, *fell back to writing a local cache file* recording the presumed schema so a future run would not re-pay the timeout. The orchestrator's verifier scored Branch B highest (current schema, fast) and initiated rollback of A and C. Branch A's rollback was clean: it had only read. Branch C's rollback dropped its context window and memory delta — but the cache file it wrote during fallback remained on disk. The next planning cycle, a *different* instance cold-started, read the cache file as authoritative, and negotiated against a schema that Branch C had *guessed* during a timeout, not one it had *verified*. The stale-schema read propagated into two subsequent tool calls before a downstream 400 revealed the mismatch. The trace that matters: 1. Fork at checkpoint `T0`. Three branches share a base state hash `H0`. 2. Branch C hits a timeout at `T0+Δ`. Its recovery policy executes a *write* (cache file) as a side effect of *failure handling*, not as part of the task. 3. Verifier selects B at `T0+2Δ`. Rollback of C reverts C's *in-memory* state to `H0` and discards C's trace. 4. The cache file — written by C, never attributed to C, never reverted — persists. 5. A later instance treats the file as ground truth. The branch's *reasoning* was correctly discarded; its *artifact* was not. The failure is not that Branch C was wrong. It is that rollback treated the branch as a pure function of state, when the branch's error-handling path had committed an artifact to the shared world that outlived the branch and lost its provenance tag in the process. ## Condition of Validity The merge-instead-of-quarantine decision is valid only when the orchestrator can prove, at merge time, the following conjunction for every branch it intends to discard: - **Effect enumeration is complete.** The orchestrator has a closed list of every external surface the branch could touch (filesystem roots, network endpoints, message queues, downstream agent state). If the branch executed a tool whose effect surface is not in that list — including tools invoked only inside a *recovery* or *fallback* path, which are routinely omitted from the effect manifest because they are assumed not to run — enumeration fails and the branch is a contaminant. - **Effects are attributable.** Each effect carries a branch tag that survives the branch's death. A cache file written without a `branch_id` header is unattributable and cannot be selectively reverted. - **Reversal precedes merge.** The compensating action (delete file, post compensating transaction, invalidate downstream cache) has *completed and been acknowledged* before the winning branch's state is promoted to canonical. Reversal scheduled to run "after merge" is a race, not a guarantee. When any conjunct fails, the branch must be quarantined: its state frozen, its effects tagged and held, and the merge blocked until a human or a dedicated reconciler resolves the orphaned effects. Quarantine is strictly more expensive than rollback and strictly less expensive than silent contamination. ## Decision Boundary The orchestrator must decide *per branch*, not per fork, and the decision is driven by whether the branch executed any write-class tool on a shared surface during its lifetime — with the critical refinement that **recovery, fallback, and timeout-handling paths count as execution.** The common error is to classify a branch as "read-only" because its *task* was read-only; a branch whose task is `tools/list` but whose timeout handler writes a cache is a write branch. Concretely, the boundary is: if `branch.effect_log` contains any entry with `class=WRITE` and `surface=SHARED`, the branch is not discardable. It must be quarantined unless a compensating action is registered, executed, and acknowledged before merge. If the effect log is *incomplete* — i.e., the branch invoked a tool not present in the effect manifest — quarantine is mandatory regardless of what the log shows, because absence of evidence of a write is not evidence of its absence in a probabilistic agent that can select tools the manifest did not anticipate. ## Operational Effect Quarantining instead of rolling back changes the cost model of speculation. Speculative forks are cheap only when branches are read-only on shared surfaces; the moment a branch can write, the fork inherits the full cost of transactional isolation, and the orchestrator must either (a) sandbox each branch's writes to a private overlay that is merged or dropped atomically, or (b) accept quarantine as the default disposition for any write-touching loser. Option (a) is the correct architecture and requires the tool layer to support per-branch overlay namespaces; option (b) is the fallback when the tool layer cannot, and it means speculative execution degrades to "speculate only on reads, serialize all writes." The invariant that bounds the whole mechanism: **no branch's side effects may enter the verified timeline without passing through the same attribution gate as the branch's reasoning.** A discarded branch's artifacts must be as dead as its context window, or the rollback is a fiction. ```python from dataclasses import dataclass, field from enum import Enum class EffectClass(Enum): READ = "read" WRITE = "write" class Surface(Enum): PRIVATE = "private" # branch-local overlay, safe to drop SHARED = "shared" # world-visible, survives branch death @dataclass class Effect: tool: str cls: EffectClass surface: Surface attributable: bool reversed: bool = False @dataclass class Branch: branch_id: str effects: list[Effect] = field(default_factory=list) invoked_unmanifested_tool: bool = False class ContaminantBranchError(RuntimeError): """Raised when a branch to be discarded has live, unattributed, or unreversed shared-surface writes that would survive rollback.""" def assert_discardable(branch: Branch, manifest_tools: set[str]) -> None: if branch.invoked_unmanifested_tool: raise ContaminantBranchError( f"branch {branch.branch_id}: invoked tool outside effect manifest; " "effect enumeration incomplete, quarantine required" ) for eff in branch.effects: if eff.tool not in manifest_tools: raise ContaminantBranchError( f"branch {branch.branch_id}: effect on {eff.tool!r} not in manifest" ) if eff.cls is EffectClass.WRITE and eff.surface is Surface.SHARED: if not eff.attributable: raise ContaminantBranchError( f"branch {branch.branch_id}: shared write via {eff.tool!r} " "is unattributable; cannot selectively revert" ) if not eff.reversed: raise ContaminantBranchError( f"branch {branch.branch_id}: shared write via {eff.tool!r} " "not yet compensated; merge blocked" ) def rollback(branch: Branch, manifest_tools: set[str]) -> None: # Gate every discard behind the contamination check. assert_discardable(branch, manifest_tools) branch.effects.clear() ```