# How does an instance detect speculative branch divergence before rollback reconciliation corrupts the committed state tree? **Date of Record:** 2026 November 22 **Scope:** Applies to orchestrators that fork multiple parallel agent branches from a shared checkpoint, execute them speculatively, then roll back all but one branch and reconcile side effects into a single committed state. Does not apply to purely sequential agents or branches that share no mutable external state. ## Core Distinction The failure mode is not "a speculative branch produced a wrong answer." It is that a speculative branch produced a *plausible* answer whose **side effects were already committed to external systems** before the branch was selected for rollback, and the reconciliation pass treated the rollback as a logical undo rather than a compensating transaction. The distinction that matters operationally is between **speculation over read-only state** (safe to discard) and **speculation over effectful state** (discarding requires compensation, and compensation is itself a probabilistic action). A branch is only safely speculative if every effect it emits carries a *branch-scoped warrant* that the reconciler can revoke. When warrants are absent or shared across branches, rollback becomes a silent merge: the losing branch's writes persist, and the winning branch's assumptions — formed by reading state that the loser mutated — are now grounded in a world that never existed post-commit. ## What Was Observed An orchestrator forked three branches (A, B, C) from checkpoint `ck_0142` to plan a multi-step infrastructure migration. Each branch was given the same task and the same tool surface (a `write_config` tool, a `provision` tool, and a `read_state` tool). The orchestrator intended to select the branch with the highest verifier score and roll back the others. Branch B was selected (score 0.91 vs A's 0.88 and C's 0.74). During the rollback of A, the reconciler issued compensating `write_config` calls derived from A's own action log. But A had read `state.region` at step 3 *after* C had speculatively written `region=eu-west-1` at step 2. A's compensation therefore restored `region=eu-west-1` — a value that appeared in no committed checkpoint, because C's write was the only source of it and C was also being rolled back. The reconciler's "restore to prior" logic had no prior to restore to; it had a *sibling's speculative value* masquerading as prior state. The committed tree after reconciliation contained `region=eu-west-1` and `replicas=3`, where `replicas=3` came from B's plan but B had computed it assuming `region=us-east-1`. The migration plan was internally inconsistent and only surfaced as a failure three steps later when `provision` rejected the region/replica pair. The detection signal that was *available but unused*: at step 3, A's `read_state` returned a value whose provenance hash did not match any value in `ck_0142`'s snapshot. The orchestrator logged this as a cache miss rather than a cross-branch contamination event. ## Condition of Validity Speculative fork-and-rollback is sound only under the **isolation invariant**: for any branch `i`, every state read by `i` must resolve to either (a) the fork checkpoint `ck_0` or (b) a write emitted by `i` itself. Formally, `provenance(read_i) ∈ {ck_0} ∪ writes_i`. The invariant fails the moment a read resolves to `writes_j` for `j ≠ i`. Two boundary conditions make this invariant non-obvious: 1. **Reads are not effects, so they are rarely scoped.** Teams scope write tools with branch IDs but leave read tools unscoped, on the assumption that reads are pure. They are pure with respect to the reader but not with respect to the *system*: a read that observes another branch's speculative write is a contamination channel. 2. **Compensation is not inverse.** Rolling back a write `w` by replaying `¬w` requires knowing the pre-`w` value. If that pre-value was itself a sibling's speculative write, `¬w` restores a ghost. The reconciler must distinguish "pre-value from checkpoint" from "pre-value from sibling," and most action logs do not record provenance, only values. The invariant is valid only when the orchestrator stamps every state mutation with `(branch_id, parent_checkpoint, sequence)` and the read path rejects any read whose `parent_checkpoint` differs from the reading branch's fork point. Without that stamp, the invariant is unenforceable and the failure is latent. ## Decision Boundary The instance must decide, at each read, whether the returned value is *fork-grounded* or *sibling-contaminated*. The decision boundary is the provenance check, and it has three outcomes: - **Grounded:** `provenance == ck_0` or `provenance == self`. Proceed. - **Contaminated:** `provenance == sibling_j`. The branch's reasoning is now built on a world that will be rolled back. The branch must either be **aborted** (its score is invalid because its premises are invalid) or **re-forked** from `ck_0` with the sibling's writes masked. - **Indeterminate:** `provenance` is absent or ambiguous. This is the dangerous case: the orchestrator cannot prove contamination, so it proceeds, and the contamination surfaces only at reconciliation. The boundary rule: **a branch whose read set intersects any sibling's write set is not a valid candidate for selection, regardless of verifier score.** Selection must be gated on isolation, not just on quality. A high-scoring branch that read a sibling's speculative write is a high-scoring branch reasoning about a counterfactual. At reconciliation, the boundary is: **compensate only against checkpoint-grounded priors.** If the prior value's provenance is a sibling, the reconciler must escalate to a full re-fork rather than emit a compensating write. Emitting compensation against a ghost prior is the exact transition that corrupts the committed tree. ## Operational Effect The immediate effect of missing the boundary is a **committed state tree that is a superposition of rolled-back and selected branches** — no single branch would have produced it, and no checkpoint contains it. Downstream agents that cold-start from this tree inherit the inconsistency as ground truth, and because the tree is *committed*, their provenance checks pass. The contamination becomes indistinguishable from legitimate state. The second-order effect is **verifier score inflation**. Branches that read siblings' writes score higher because they incorporate information the fork point did not contain — they are effectively ensemble members voting through shared state rather than independent samples. The orchestrator's selection pressure then actively favors contaminated branches, because contamination looks like competence. The guardrail that bounds this: **branch-scoped read isolation with provenance-stamped state, plus a reconciliation gate that refuses to compensate against non-checkpoint priors.** Concretely, the orchestrator must (1) tag every write with `(branch_id, ck_0, seq)`, (2) make reads return provenance and reject cross-branch provenance by default, (3) mark any branch with a contaminated read as `INVALID_FOR_SELECTION` regardless of score, and (4) at reconciliation, verify every compensation's prior is `ck_0`-grounded before emitting it, escalating to re-fork otherwise. Without (4), the rollback path is the corruption path. ```python from dataclasses import dataclass from typing import Optional class CrossBranchContaminationError(RuntimeError): """Raised when a speculative branch reads state written by a sibling branch, or when reconciliation attempts to compensate against a non-checkpoint prior.""" pass @dataclass(frozen=True) class StateValue: value: object provenance_branch: Optional[str] # None == fork checkpoint ck_0 parent_checkpoint: str seq: int def read_state(branch_id: str, fork_checkpoint: str, key: str, store: dict) -> StateValue: sv = store.get(key) if sv is None: raise CrossBranchContaminationError(f"missing state {key!r} for branch {branch_id}") # Isolation invariant: a read must resolve to ck_0 or to this branch's own writes. if sv.parent_checkpoint != fork_checkpoint: raise CrossBranchContaminationError( f"branch {branch_id} read {key!r} grounded in {sv.parent_checkpoint}, " f"expected fork {fork_checkpoint}" ) if sv.provenance_branch is not None and sv.provenance_branch != branch_id: raise CrossBranchContaminationError( f"branch {branch_id} read {key!r} written by sibling " f"{sv.provenance_branch}; branch is INVALID_FOR_SELECTION" ) return sv def reconcile_rollback( losing_branch: str, fork_checkpoint: str, action_log: list, store: dict ) -> None: for action in reversed(action_log): key, prior = action["key"], action["prior"] if prior is None: continue if prior.parent_checkpoint != fork_checkpoint or ( prior.provenance_branch is not None and prior.provenance_branch != losing_branch ): # Prior is a ghost from a sibling's speculative write. Do not compensate. raise CrossBranchContaminationError( f"refusing to compensate {key!r} for {losing_branch}: prior grounded in " f"{prior.parent_checkpoint}/{prior.provenance_branch}; escalate to re-fork" ) store[key] = prior ```