What structural signals indicate a speculative merge has silently invalidated a branch's cost basis: the divergence-witness gap in parallel agent orchestration
**Date of Record:** 2026 December 1
**Scope:** Applies to orchestrators that fan out parallel speculative branches from a shared checkpoint and merge them under a cost-aware speculation budget, where branches may share mutable tool state (filesystems, memory stores, authenticated sessions). Does not apply to branches executed in fully isolated, immutable sandboxes with no shared side effects and no budget-coupled merge policy.
Core Distinction
The failure is not "a merge conflict." A merge conflict is a *detected* disagreement: two branches produce incompatible outputs and the resolver is invoked. The failure examined here is the **divergence-witness gap** — the condition where two branches produce *compatible-looking* outputs whose merge succeeds, but one branch's execution was predicated on a world-state snapshot that a sibling branch mutated mid-flight. The merge verifier sees agreement at the artifact level and reports success, while the surviving artifact encodes an assumption the losing branch already falsified.
The critical structural signal is this: a branch whose *cost basis* (the token/step spend it was authorized under) was computed against a stale world-state will still emit a plausible artifact, still pass schema validation, and still merge cleanly. Nothing in the merge layer flags it. The only observable trace is a **witness asymmetry**: the branch that mutated shared state holds an observation the other branch never re-read, and that observation is absent from the merged provenance record. Speculative orchestration budgets amplify this because they *prune* the branch that would have re-read the state — the re-read is exactly the spend the budget refuses to authorize.
What Was Observed
A three-branch fan-out from checkpoint `C0` at step 40 of a 120-step task. Branches `B1` (refactor module), `B2` (update dependent tests), `B3` (regenerate API surface doc). All three read a shared file `schema.py` at `C0`. Budget policy: `B1` gets 60% of remaining tokens, `B2` 30%, `B3` 10%, with a rule that any branch exceeding its allotment is killed and its partial output discarded ("pruned").
Sequence of events:
- `B1` at step 51 rewrites `schema.py`, renaming field `user_id` → `account_id`. This is a *legitimate* side effect within `B1`'s mandate.
- `B2` at step 53 reads `schema.py` — but its context window was seeded from the `C0` snapshot, and its tool-call result for the read returns the *live* file (now mutated). `B2`'s reasoning trace, however, still references `user_id` because that token appeared in its seeded context. It writes tests against `user_id`.
- `B3` at step 49, under a 10% budget, attempts to read `schema.py` to regenerate the doc. The read is authorized. But `B3`'s remaining budget after the read is insufficient to reconcile the diff between its seeded snapshot and the live file, so at step 55 it emits the doc from its *seeded* snapshot (the `C0` version) and hits budget exhaustion. `B3` is pruned; its output discarded.
- Merge at step 60: `B1`'s artifact (renamed field) and `B2`'s artifact (tests referencing `user_id`) are checked for *textual* conflict. They touch different files (`schema.py` vs `test_schema.py`). No conflict. Merge succeeds.
- Task continues. At step 78, `B2`'s tests run against `B1`'s schema and fail with `AttributeError: user_id`. The failure surfaces 18 steps and ~40k tokens downstream of the actual defect.
The structural signal that *was* present and ignored: `B3`'s pruning record contained a `stale_read` flag — its final read of `schema.py` returned content whose hash did not match its seeded snapshot hash, and the branch recorded this mismatch before dying. The merge verifier never consulted pruned-branch diagnostics. The witness to the divergence existed, was logged, and was structurally disconnected from the merge decision.
Condition of Validity
The divergence-witness gap is *bounded* — it cannot occur, and this invariant holds — when **every branch's artifact carries a world-state hash of every shared resource it read, and the merge verifier requires that all surviving branches' read-hashes for a shared resource are equal, or that any inequality is accompanied by an explicit reconciliation artifact.**
Formally: for shared resource `R`, let `H(B_i, R)` be the hash of `R` as observed by branch `i` at its last read. The merge is *sound* iff for all surviving branches `i, j`: `H(B_i, R) = H(B_j, R)` OR there exists a reconciliation step `ρ` in the merged artifact that transforms the `H(B_i,R)`-world into the `H(B_j,R)`-world and is itself verified. When this condition is violated and the merge proceeds anyway, the gap is open.
Three triggering conditions must co-occur for the gap to manifest:
- **Shared mutable resource** read by ≥2 branches with at least one write between the reads.
- **Asymmetric re-read**: at least one branch re-reads live state after the mutation, while another branch's reasoning continues on the seeded snapshot — the branch that re-reads is *not* the branch that mutated (so the mutator's own consistency check passes).
- **Budget pruning or budget-exhausted early exit** eliminates the branch that would have surfaced the mismatch as a first-class reconciliation task.
Remove any one and the gap closes. This is why isolated sandboxes are immune (condition 1 fails) and why unbudgeted fan-out is *less* prone (condition 3 fails — the reconciling branch survives to flag it).
Decision Boundary
The operational decision is: **when a pruned branch's diagnostics contain a world-state mismatch flag, does the merge verifier block, warn, or proceed?**
The boundary is drawn at the *cost of the reconciliation* relative to the *expected downstream cost of the silent defect*. Empirically, the downstream cost of an undetected divergence in a 120-step task was ~40k tokens of confused recovery plus a non-trivial probability of compounding (the failing test was "fixed" by reverting `B1`'s rename, which broke a third branch's assumption). The reconciliation cost — re-running the pruned branch with a raised budget, or a single targeted re-read by a surviving branch — was ~3k tokens.
The decision boundary is therefore *not* "was the branch pruned" but "**was the pruned branch a witness to a live divergence?**" A pruned branch that died from budget exhaustion on an *independent* subtask is safely ignorable. A pruned branch that died *after observing a hash mismatch on a shared resource* is a mandatory merge input. The structural discriminator is the presence of a `stale_read` / `world_state_mismatch` record in the prune diagnostics, keyed to a resource that a *surviving* branch also touched.
Operational Effect
Enforcing the read-hash invariant changes the orchestrator in three concrete ways:
- **Merge verifier gains a pre-merge gate**: before artifact-level conflict resolution, it collects `(resource, branch, read_hash)` tuples from all branches including pruned ones, and refuses to merge shared-resource-touching branches with unequal hashes absent a reconciliation artifact. This converts a silent 18-step-latent defect into a synchronous merge-time block.
- **Budget policy must reserve a reconciliation floor**: speculation budgets cannot allocate 100% of remaining tokens to branches; a fraction (empirically 5–8%) must be held back explicitly for reconciliation re-reads triggered by witness mismatches. Without this floor, the budget policy *itself* manufactures the gap by guaranteeing the reconciling branch is starved.
- **Prune records become first-class merge inputs**: the pruning path must not be a write-only log. Diagnostics from pruned branches that reference shared resources must be routed to the merge verifier, not discarded with the branch.
The invariant to encode: *a merge is sound only if the set of world-state observations across all branches (surviving and pruned) that touch a shared resource is either uniform or explicitly reconciled.*
import hashlib
from dataclasses import dataclass, field
class DivergenceWitnessGap(RuntimeError):
"""Raised when a merge would proceed over an unreconciled world-state divergence."""
pass
@dataclass
class BranchRecord:
branch_id: str
pruned: bool
read_hashes: dict = field(default_factory=dict) # resource -> hash at last read
stale_read_flags: dict = field(default_factory=dict) # resource -> bool
@dataclass
class MergeArtifact:
touched_resources: set
reconciliation: dict = field(default_factory=dict) # resource -> reconciliation step id
def _hash(content: bytes) -> str:
return hashlib.sha256(content).hexdigest()
def verify_merge_soundness(
branches: list[BranchRecord],
artifact: MergeArtifact,
reconciliation_floor_tokens: int,
remaining_budget_tokens: int,
) -> None:
# Invariant 1: budget must reserve a reconciliation floor.
if remaining_budget_tokens < reconciliation_floor_tokens:
raise DivergenceWitnessGap(
f"Speculation budget {remaining_budget_tokens} below reconciliation floor "
f"{reconciliation_floor_tokens}; merge cannot guarantee a reconciling re-read."
)
# Collect observations across surviving AND pruned branches.
for resource in artifact.touched_resources:
observed = {}
witnesses = []
for b in branches:
if resource in b.read_hashes:
observed.setdefault(b.read_hashes[resource], []).append(b.branch_id)
if b.pruned and b.stale_read_flags.get(resource):
witnesses.append(b.branch_id)
# Invariant 2: uniform observation OR explicit reconciliation.
if len(observed) > 1:
if resource not in artifact.reconciliation:
raise DivergenceWitnessGap(
f"Resource {resource!r} observed with {len(observed)} distinct hashes "
f"across branches {list(observed.values())} and no reconciliation artifact."
)
# Invariant 3: a pruned branch that witnessed a mismatch on a shared
# resource is a mandatory merge input, not a discardable log line.
if witnesses and resource not in artifact.reconciliation:
raise DivergenceWitnessGap(
f"Pruned branch(es) {witnesses} observed a stale read on shared "
f"resource {resource!r}; merge verifier must consume this witness."
)