# What structural signals indicate irreversible divergence in speculative parallel plan branches before rollback commits **Date of Record:** 2026 December 3 **Scope:** Applies to agent orchestrators that fan out a plan into parallel speculative branches, each mutating external tool state, and later select one branch while rolling back the others. Does not apply to read-only fan-out (map/reduce retrieval) where no compensating action is required. ## Core Distinction The failure mode is not "a branch failed." It is **compensable failure vs. non-compensable divergence**. A branch that errors cleanly leaves a trace you can invert. A branch that *partially succeeds against a non-idempotent external effect* while its sibling commits the same effect has crossed a boundary where rollback is no longer a local operation—it becomes a distributed reconciliation problem the orchestrator was never designed to perform. Speculative execution assumes rollback is cheap and total. That assumption holds only while every branch's side effects are either (a) sandboxed and discarded, or (b) idempotent under a shared deduplication key. The moment two branches emit *distinct* non-idempotent effects before the selector runs, the invariant "at most one branch's effects survive" is already violated, and no post-hoc rollback restores it. ## What Was Observed A planner emitted three speculative branches for a provisioning task: - **Branch A**: `create_account(tenant="acme")` → returns `acct_8812` - **Branch B**: `create_account(tenant="acme")` → returns `acct_8813` (retry after a 30s timeout on A's first attempt; the timeout was a slow response, not a failure) - **Branch C**: `create_account(tenant="acme")` → rate-limited, backs off, never completes The selector, using a latency-weighted heuristic, chose **Branch B** as "fastest successful." It then issued rollback compensations for A and C. Branch A's compensation called `delete_account("acct_8812")`. But A had already been referenced by a downstream `assign_license(acct_8812)` issued by a fourth, non-speculative continuation that fired on A's *first* success signal before the selector decided. The rollback of A succeeded at the account layer and failed silently at the license layer: `delete_account` returned 200, but the license row remained, now orphaned against a deleted account. Branch B's `acct_8813` was the "survivor," yet the tenant now had a dangling license bound to a ghost. The structural signal that mattered was not the error codes. It was: **two branches produced distinct resource identifiers for the same logical intent, and a third party consumed one of them before selection.** Once an external actor has read a speculative branch's output, that branch is no longer rollback-able—it is *committed by observation*. ## Condition of Validity Rollback in speculative branches is valid only under the conjunction: 1. **Effect isolation**: every branch's writes are namespaced by a branch token (`branch_id`) that no other branch or downstream consumer can reference until selection commits. 2. **Single-writer-per-intent**: at most one branch may hold a live write lease on a given logical resource at a time; siblings queue or abort. 3. **Observation barrier**: no output of a speculative branch is exposed to any consumer outside the orchestrator until selection completes. Reads by third parties are treated as commits. 4. **Compensation completeness**: every effect has a registered inverse whose success is *verified*, not assumed from a 200. The observed incident violated (1), (2), and (3) simultaneously. Any one violation alone is recoverable; the conjunction is not. ## Decision Boundary The orchestrator must distinguish, *before* issuing rollback, between: - **Clean divergence**: branches produced disjoint effects, or effects carry a shared idempotency key. Rollback = discard + compensate. Proceed. - **Contaminated divergence**: two or more branches emitted distinct identifiers for the same intent, OR any branch's output was read externally. Rollback is now a **reconciliation** task: you must not delete the loser's effects until you have proven no external reference exists. If you cannot prove it, you must **escalate to human/manual reconciliation** rather than compensate. The boundary test is a single predicate: `has_external_observation(branch) OR duplicate_intent_ids(branches)`. If true, rollback is forbidden; the orchestrator halts and emits a reconciliation warrant. If false, rollback proceeds under the compensation-completeness check. ## Operational Effect Enforcing this boundary converts a silent data-integrity corruption (orphaned licenses, ghost accounts, double-charges) into a loud, bounded halt. The cost is that some speculative fan-outs that *would* have rolled back fine now stop for manual review. The benefit is that the invariant "no external consumer ever observes a rolled-back branch" becomes checkable rather than aspirational. Practically: attach a branch token to every effect, gate all external reads on selection, and treat any read of a speculative output as an irreversible commit that removes that branch from the rollback set. ```python class IrreversibleDivergenceError(RuntimeError): """Raised when speculative branches have crossed the rollback boundary.""" pass def plan_rollback(branches, external_reads, intent_ids): """ branches: list of dicts with 'branch_id' and 'effects' (list of resource ids) external_reads: set of resource ids observed by any non-orchestrator consumer intent_ids: dict mapping logical intent -> list of resource ids produced per branch """ # Detect duplicate intent identifiers across branches duplicated = { intent: ids for intent, ids in intent_ids.items() if len(set(ids)) > 1 } # Detect any speculative effect already observed externally observed = { b["branch_id"]: [e for e in b["effects"] if e in external_reads] for b in branches } observed = {k: v for k, v in observed.items() if v} if duplicated or observed: raise IrreversibleDivergenceError( f"Rollback boundary crossed: duplicate_intents={list(duplicated)}, " f"externally_observed={observed}. " f"Compensation forbidden; escalate to reconciliation." ) # Safe: discard speculative effects and compensate compensations = [] for b in branches: for effect in b["effects"]: compensations.append({"branch_id": b["branch_id"], "inverse": effect}) return {"mode": "rollback", "compensations": compensations} ```