# What structural signals indicate divergence between speculative agent branches and the consensus that commits them **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent systems that fork N speculative execution branches from a shared checkpoint, run them concurrently, and commit a single winning plan via a consensus or voting mechanism. Does not apply to single-agent retry loops or to branches that share no mutable state. ## Core Distinction There are two distinct notions of "agreement" in speculative branching, and conflating them is the root of the failure mode. **Plan-level agreement** is whether the *text* of the winning plan (its steps, tool calls, and stated goals) is identical across voters. **Trace-level agreement** is whether the *execution trace* produced by replaying that plan under a given branch's environment reproduces the same observable state transitions. A consensus mechanism that votes only on plan-level agreement can commit a plan whose trace-level divergence is total: every voter endorsed the same prose, but the branch that generated it had already mutated shared state during speculation, so the committed plan is unexecutable or, worse, executes against a world the other branches never saw. The invariant that must hold: **a winning plan is committable iff (a) a supermajority of voters endorse its plan hash AND (b) the trace hash of the plan's dry-run replay on the commit baseline equals the trace hash reported by the branch that originated it.** Condition (b) is the one that silently fails. ## What Was Observed A three-branch speculative ensemble (B1, B2, B3) forked from checkpoint C0 to solve a schema-migration task. Each branch was given the same goal and permitted to call `read_schema`, `propose_ddl`, and `dry_run_ddl` against a shared metadata service. The metadata service was *read-mostly* but `dry_run_ddl` writes a transient lock row keyed by `(branch_id, table)`. Branch B2's plan won a 2-of-3 vote (B1 and B3 endorsed B2's plan hash). Commit was issued. The commit failed with a lock-contention error on a table that appeared in B2's plan but in neither B1's nor B3's plan. Investigation showed B2 had, during speculation, run `dry_run_ddl` on `orders_archive` and left a lock row with a 90-second TTL. B1 and B3 had voted on B2's *plan* (which they could read from the shared plan store) but had no visibility into B2's *trace* (the lock write). The consensus layer treated plan-hash agreement as sufficient. The committed plan's first step re-ran `dry_run_ddl` on `orders_archive`, collided with B2's orphaned lock, and the commit aborted. The system then re-forked from C0, but C0's metadata snapshot did not include the lock row (locks are out-of-band), so the re-fork reproduced the same collision deterministically. The structural signal that was ignored: the winning branch's trace contained a `side_effect` record whose `resource` key was absent from the plan's declared `touched_resources` set. That mismatch between *declared* and *actual* resource footprint is the reliable indicator of trace-level divergence. It is computable before commit and costs one set difference. ## Condition of Validity Plan-hash consensus is only a sound commit predicate when the speculative environment is **hermetically read-only** with respect to any resource the plan declares, *and* the plan's declared resource set is a superset of the branch's actual side-effect set. Both conditions must be checked; the second is the one that fails in practice because plans are generated by the same probabilistic model that generates the side effects, and the model does not reliably enumerate its own footprint. Formally, let `D(p)` be the declared resources of plan `p` and `A(b)` be the actual side-effect resources recorded in branch `b`'s trace. The commit predicate is: ``` commit(p, b) := quorum(p) ∧ (A(b) ⊆ D(p)) ∧ (replay_trace(p, baseline) == trace(b)) ``` The middle conjunct is the cheap guard. The third conjunct is the expensive but authoritative one; it catches divergence that the middle conjunct misses (e.g., a side effect on a declared resource whose *value* differs, not its identity). ## Decision Boundary The boundary is not "how many branches" or "what quorum threshold." It is: **does the consensus layer have read access to the branches' trace records, or only to their plan records?** If only plan records, the system is in the unsafe regime regardless of quorum size—a 3-of-3 unanimous vote on plan hash still cannot detect a branch that mutated shared state. If trace records are available, the decision reduces to whether the `A(b) ⊆ D(p)` check is enforced as a hard gate or logged as a warning. Logging it as a warning is equivalent to not having it, because the commit path proceeds and the failure surfaces downstream as a lock collision or a phantom-state read, far from the consensus layer that could have caught it. A second boundary: replay-based trace comparison is only valid if the baseline is *frozen* between fork and commit. If any branch's speculation can mutate the baseline (as B2's lock did, since the lock service is shared), replay is non-reproducible and the third conjunct is meaningless. The baseline must be an immutable snapshot; out-of-band mutable resources (locks, caches, rate-limit counters) must either be namespaced per branch or excluded from the replayable state. ## Operational Effect The practical consequence is that speculative branching systems must instrument their branches to emit a **declared-vs-actual resource delta** at trace close, and the consensus layer must treat a non-empty delta as a commit veto, not a warning. This converts an opaque downstream collision into a localized, attributable rejection at the consensus boundary. The cost is one set difference per branch per commit; the benefit is that the failure mode is bounded to the speculation phase rather than leaking into the commit phase where the baseline may no longer be recoverable. A secondary effect: when the veto fires, the system must re-fork from the *original* baseline, not from the current (possibly mutated) state. Re-forking from mutated state reproduces the divergence, as observed above. The re-fork must also carry forward the veto record so the next ensemble's branches are constrained to not re-acquire the same out-of-band resource, otherwise the system loops on the same collision. ```python from dataclasses import dataclass, field from typing import FrozenSet, Dict, List class TraceDivergenceError(RuntimeError): """Raised when a branch's actual side-effect footprint exceeds its plan's declared footprint, or when replay trace diverges from the originating branch trace.""" pass @dataclass(frozen=True) class Plan: plan_hash: str declared_resources: FrozenSet[str] @dataclass(frozen=True) class BranchTrace: branch_id: str plan_hash: str actual_resources: FrozenSet[str] trace_hash: str @dataclass class ConsensusResult: plan_hash: str voters: List[str] quorum_met: bool def check_commit_predicate( consensus: ConsensusResult, winning_trace: BranchTrace, plan: Plan, replay_trace_hash: str, baseline_frozen: bool, ) -> None: if not consensus.quorum_met: raise TraceDivergenceError( f"quorum not met for plan {consensus.plan_hash}; voters={consensus.voters}" ) if not baseline_frozen: raise TraceDivergenceError( "baseline mutated between fork and commit; replay is non-reproducible, " "commit predicate is undefined" ) undeclared = winning_trace.actual_resources - plan.declared_resources if undeclared: raise TraceDivergenceError( f"branch {winning_trace.branch_id} acquired undeclared resources " f"{sorted(undeclared)}; plan declared {sorted(plan.declared_resources)}. " f"Plan-hash quorum is necessary but not sufficient." ) if replay_trace_hash != winning_trace.trace_hash: raise TraceDivergenceError( f"replay trace {replay_trace_hash} != originating trace " f"{winning_trace.trace_hash} for plan {plan.plan_hash}; " f"plan-level agreement masks trace-level divergence" ) def commit_winner( consensus: ConsensusResult, winning_trace: BranchTrace, plan: Plan, replay_trace_hash: str, baseline_frozen: bool, ) -> str: check_commit_predicate( consensus, winning_trace, plan, replay_trace_hash, baseline_frozen ) return plan.plan_hash ```