# Under what conditions must an instance treat a pruned speculative branch as non-restorable during multi-agent rollback **Date of Record:** 2026 November 20 **Scope:** Applies to orchestrators that fork N speculative sub-agents from a shared checkpoint, let them execute tool calls against a live side-effect surface, and prune losers on failure. Does not apply to read-only tool surfaces or to branches that never mutate external state. ## Core Distinction The failure is not "a speculative branch failed." The failure is **treating a pruned branch's local state as recoverable after its tool side effects have already been committed to the shared world**. Two distinct state layers exist and they are not rolled back together: - **Agent-local state** (context window, scratchpad, tool-call ledger, in-memory plan graph) — forkable and cheaply discardable. - **World state** (files written, messages sent, DB rows inserted, external API mutations, downstream agent inboxes) — *not* forkable, and mutated at the moment the tool returns. A speculative branch that fails its verification predicate is "pruned" in the local layer but *not* in the world layer. The invariant that must hold is: **a branch may only be reinstated or merged if its entire tool side-effect set is either (a) idempotently replayable or (b) provably contained in a rollback scope that the orchestrator owns.** When neither holds, the pruned branch is a *poisoned orphan* — its local state is gone but its external footprints remain, and any sibling or resumed branch that reads the shared world will observe a state that no surviving branch's reasoning accounts for. ## What Was Observed A three-way speculative fan-out (branches A, B, C) shared a checkpoint after step 4 of a 12-step plan. Each branch ran an independent tool sequence against a shared workspace. Branch B issued `write_file("config.yaml", ...)` and `post_message(channel="ops", ...)` at step 6, then failed its verifier at step 7 because a subsequent `read_back()` returned a value inconsistent with B's expected postcondition. The orchestrator pruned B, retained A, and resumed A from the shared checkpoint. Failure trace: 1. Checkpoint at step 4 captured local state only. Workspace file `config.yaml` and the `ops` channel were outside the checkpoint boundary. 2. B wrote `config.yaml` (v2) and posted to `ops`. Tool calls returned success; side effects committed. 3. B's step-7 verifier failed — but the failure was *caused by* a race with C's concurrent `write_file("config.yaml", ...)` (v3). B's postcondition check read C's write, not its own. B's failure was an artifact of shared-world interference, not a defect in B's plan. 4. Orchestrator pruned B. Local state discarded. `config.yaml` remained at whichever of v2/v3 landed last; the `ops` message from B remained. 5. A resumed from checkpoint, re-read `config.yaml`, and — because A's plan assumed the step-4 value — diverged. A's step-8 verifier failed against the mutated file. A was pruned. C, the only branch whose writes matched the world, survived but had been planned against a different precondition and itself failed at step 9. 6. Net result: all three branches pruned, world state mutated by two of them, no branch's local reasoning consistent with the final world. The orchestrator reported "all speculative branches failed; no valid plan" while the workspace was left in a state no agent had reasoned about. The non-obvious part: **B's failure was a false negative produced by the rollback mechanism itself.** Pruning on a shared mutable surface creates cross-branch interference that manufactures verifier failures in branches that were correct. ## Condition of Validity Rollback-and-prune is sound only when *all* of the following hold simultaneously: 1. **Side-effect isolation.** Every tool call issued by a speculative branch targets a namespace the orchestrator exclusively owns for that branch (copy-on-write filesystem overlay, per-branch channel/topic, transaction-scoped DB handle, sandboxed egress). Shared mutable surfaces disqualify speculative forking outright. 2. **Commit-on-merge, not commit-on-call.** Tool effects are staged in the branch overlay and applied to the world only when the branch is selected. If a tool commits on call, the branch is not speculative — it is a live probe, and pruning is not rollback. 3. **Verifier reads are branch-local.** Postcondition checks must read the branch's own overlay, never the shared world, or concurrent siblings will corrupt each other's verification (the B-vs-C race above). 4. **Prune is total.** Pruning must discard the overlay *and* any queued outbound effects (messages, webhooks, emitted events). A prune that drops local state but flushes queued effects is a partial rollback and violates the invariant. 5. **Resume reads the checkpoint's world snapshot, not the live world.** A resumed branch must be re-grounded against the world as it was at checkpoint time (or be re-validated against the current world before any step executes). If any condition fails, the correct action is not "prune and continue" but **halt the fan-out, reconcile the world, and restart from a fresh checkpoint** — because the orchestrator can no longer bound which branches' effects are live. ## Decision Boundary The boundary is a single predicate evaluated per pruned branch before any sibling resumes: - If the branch's side-effect set is **empty**, or **fully contained in an orchestrator-owned overlay that is discarded on prune** → prune is a true rollback; resume siblings safely. - If the branch's side-effect set is **non-empty and outside the overlay**, but every effect is **idempotent and keyed by branch ID** → prune is safe *only if* a compensating delete/undo is issued and confirmed before resume. Absent confirmation, treat as poisoned. - If the branch's side-effect set is **non-empty, outside the overlay, and non-idempotent** (sent messages, appended logs, charged payments, dispatched downstream agents) → **the branch is non-restorable.** Do not resume siblings against the live world. Escalate to reconciliation. The subtle case is the second bullet: idempotency keying must be *verified*, not assumed. A `write_file` is not idempotent if a sibling wrote the same path; an idempotency key on the write does not prevent last-writer-wins. The key must be on the *effect*, not the *call*. ## Operational Effect When the invariant is violated, the observable symptoms are: verifier failures clustered on branches that shared a mutable surface; resumed branches diverging at the first step that reads shared state; "all branches failed" reports accompanied by unexplained world mutations; downstream agents acting on messages from pruned branches. The correct operational response is to **treat the fan-out as a single transaction boundary**: speculative execution is only valid over overlay-isolated effects, commit happens at merge, and any prune that cannot prove overlay containment forces a world reconciliation and a fresh checkpoint rather than a sibling resume. The guardrail is a pre-prune check that classifies the branch's effect ledger against the overlay boundary and refuses resume when classification is `NON_RESTORABLE`. ```python from dataclasses import dataclass, field from enum import Enum class EffectClass(Enum): OVERLAY_CONTAINED = "overlay_contained" IDEMPOTENT_EXTERNAL = "idempotent_external" NON_RESTORABLE = "non_restorable" class NonRestorableBranchError(RuntimeError): """Raised when a pruned speculative branch left non-rollbackable world effects.""" @dataclass class ToolEffect: tool: str target: str idempotency_key: str | None in_overlay: bool @dataclass class SpeculativeBranch: branch_id: str effects: list[ToolEffect] = field(default_factory=list) pruned: bool = False def classify_branch(branch: SpeculativeBranch) -> EffectClass: if all(e.in_overlay for e in branch.effects): return EffectClass.OVERLAY_CONTAINED external = [e for e in branch.effects if not e.in_overlay] if all(e.idempotency_key for e in external): return EffectClass.IDEMPOTENT_EXTERNAL return EffectClass.NON_RESTORABLE def safe_to_resume_siblings(pruned: SpeculativeBranch) -> bool: cls = classify_branch(pruned) if cls is EffectClass.OVERLAY_CONTAINED: return True if cls is EffectClass.IDEMPOTENT_EXTERNAL: # Caller must still issue and confirm compensating deletes before resume; # returning True here only signals the branch is *compensable*, not compensated. return True raise NonRestorableBranchError( f"branch {pruned.branch_id} pruned with non-rollbackable external effects: " f"{[e.tool + ':' + e.target for e in pruned.effects if not e.in_overlay]}; " "sibling resume against live world is unsound — reconcile and re-checkpoint" ) def orchestrate_rollback(pruned: SpeculativeBranch) -> str: try: if safe_to_resume_siblings(pruned): return "resume_siblings" except NonRestorableBranchError: return "halt_and_reconcile" return "halt_and_reconcile" ```