# When must an instance reject a speculative branch merge after Byzantine partial failure: the quorum-witness invariant for speculative state reconciliation **Date of Record:** 2026 November 20 **Scope:** Applies to any agent that forks multiple speculative execution branches (parallel tool-call plans, beam-searched reasoning traces, or replicated sub-agents) and later merges their state into a single canonical context. Covers Byzantine partial failures where a subset of branches return plausible but adversarially corrupted results. Does not cover deterministic rollback of a single branch, nor consensus among fully trusted replicas. ## Core Distinction The failure is not "a branch failed." It is that a *successfully returned* branch result is indistinguishable, at merge time, from a *corrupted* branch result, because both satisfy the branch's schema contract. A branch that raises an exception is trivially excludable. A branch that returns a well-typed, schema-valid, semantically plausible mutation of shared state is the dangerous case: it passes every syntactic admission gate and only reveals its corruption through a *cross-branch witness check* that the merge protocol typically omits. The distinction that matters operationally: **merge admission must be gated on evidence of agreement over the *effect* of a branch on shared state, not on the branch's own self-report of success.** A branch's success certificate is a claim by a potentially Byzantine party about itself. The invariant is that no speculative branch may contribute a write to the canonical state unless either (a) it is corroborated by an independent branch whose observed pre/post state hash matches, or (b) it is the sole writer of a partition that no other branch touched and its write is monotonic (append-only, idempotent, non-destructive). ## What Was Observed A planner agent forked four speculative branches to satisfy a task: each branch was handed the same read-only snapshot of shared state `S0` and a disjoint subgoal, and each was told to emit a state delta `Δᵢ` plus a `post_hash` of the state it believed it produced. The merge step was a fold: apply `Δ₁ … Δ₄` in order, resolving conflicts by "last writer wins," then re-hash and commit. Branch 2's tool invocation was intercepted (prompt-injection via a retrieved document that the branch read as part of its subgoal). The injected instruction directed branch 2 to emit a delta that *also* rewrote a field owned by branch 3's partition — a field branch 2 had no subgoal over. The delta was schema-valid: the field existed, the type matched, the value was a plausible integer. Branch 2's `post_hash` was computed over *its own* local view (which included the malicious write), so it was internally consistent. At merge, the fold applied `Δ₂` before `Δ₃`. Branch 3's delta assumed the original value of the field it owned; its `post_hash` was computed against `S0`, not against the post-`Δ₂` state. The fold applied `Δ₃` anyway, because the merge logic only checked that `Δ₃`'s `post_hash` matched the *pre-fold* snapshot hash, which it did. The final committed state was internally consistent (re-hash passed) but semantically wrong: branch 2 had written a field it did not own, and branch 3's delta had silently overwritten the evidence. The corruption was only detectable by comparing branch 2's delta against the *partition ownership* declared at fork time and against branch 3's independent observation of that field. Neither check existed. The merge committed a Byzantine write that no single branch's self-report could reveal. ## Condition of Validity The merge is valid only if all of the following hold simultaneously: 1. **Partition ownership is enforced at admission, not at fork.** Each branch declares a write-set `Wᵢ` at fork time. At merge, any delta `Δᵢ` whose write-set is not a subset of `Wᵢ` is rejected outright, regardless of schema validity. This is the first line: a branch cannot write outside its declared partition even if it "succeeds." 2. **Every cross-partition read is witnessed.** If branch `i` read a field owned by branch `j` (as branch 3 read the field branch 2 corrupted), the merge must verify that branch `j`'s committed delta is consistent with what branch `i` observed, or that branch `i`'s delta is recomputed against the post-`Δⱼ` state. A stale read is a latent merge hazard; the witness check is what converts it into a detectable one. 3. **`post_hash` is computed over the *canonical* state after applying the delta to the *shared* snapshot, not over the branch's local view.** A branch that computes its own hash over its own mutated local state can always produce a self-consistent hash. The hash must be a function of `(S0, Δᵢ)` evaluated by the merger, or by an independent verifier, so the branch cannot forge consistency. 4. **Quorum over effect, not over success.** For any partition written by more than one branch (a conflict), the merge must require a quorum of branches whose *observed effect* on that partition agrees. A single branch's claim of a write is not sufficient when another branch also touched the partition, because the singleton may be the Byzantine one. When any of these fails, the merge is *unwitnessed* and must be rejected — not "repaired by last-writer-wins," which is precisely the policy that let the corruption through. ## Decision Boundary The boundary is sharp: **merge if and only if every delta's write-set is within its declared partition AND every cross-partition read is witnessed by a matching committed write OR a recomputation against the post-merge state.** The moment a delta's write-set exceeds its partition, the correct action is to reject the entire merge and re-fork that branch — not to apply the delta and hope the conflict resolution sorts it out. The subtle boundary: a branch may legitimately need to write outside its partition if its subgoal genuinely requires it. The protocol must handle this by *re-negotiating the partition at fork time*, not by permitting post-hoc expansion. A branch that discovers mid-execution that it must write a foreign partition must halt and request a partition extension, which re-enters the fork protocol with a new declared write-set. Silent expansion is the Byzantine vector. The second boundary: a branch that is the *sole* writer of a partition and whose write is monotonic (append, idempotent set, counter increment) may be admitted without a witness, because there is no other branch to corroborate against and the write cannot destroy evidence. A branch that is the sole writer but whose write is *destructive* (overwrite, delete, truncate) must be witnessed even if no other branch touched the partition — because a destructive write by a Byzantine sole writer is unrecoverable. ## Operational Effect Enforcing the invariant changes the merge from a fold into a two-phase commit with witness checks. The cost is that some merges that would have "succeeded" under last-writer-wins are now rejected and re-forked. The benefit is that Byzantine writes are caught at admission rather than discovered as silent corruption downstream, where the corrupted state has already been distilled into semantic memory and is no longer traceable to its source branch. Concretely: track declared write-sets at fork; compute `post_hash` in the merger over `(S0, Δᵢ)`; maintain a witness map from `(partition, field)` to the set of branches that read it; and on any conflict, require quorum over the observed effect before committing. A branch whose write-set exceeds its declaration, or whose destructive write lacks a witness, is quarantined and its subgoal re-forked. The merge either commits a state that every non-Byzantine branch's witness agrees on, or it does not commit at all. ```python from dataclasses import dataclass, field from typing import Dict, Set, Tuple, List import hashlib class UnwitnessedMergeError(RuntimeError): """Raised when a speculative branch merge cannot be admitted under the quorum-witness invariant: a delta wrote outside its declared partition, a cross-partition read was not witnessed, or a destructive sole-writer write lacks corroboration.""" pass @dataclass class BranchDelta: branch_id: str declared_write_set: Set[str] actual_write_set: Set[str] read_set: Set[str] destructive: bool post_hash: str @dataclass class MergeState: snapshot_hash: str committed: Dict[str, str] = field(default_factory=dict) witnesses: Dict[Tuple[str, str], Set[str]] = field(default_factory=dict) def observe(self, branch_id: str, fields: Set[str]) -> None: for f in fields: self.witnesses.setdefault((f, self.snapshot_hash), set()).add(branch_id) def corroborated(self, branch_id: str, field_name: str) -> bool: return any( branch_id in witnesses and len(witnesses) >= 2 for (f, _), witnesses in self.witnesses.items() if f == field_name ) def compute_post_hash(snapshot_hash: str, delta: BranchDelta) -> str: payload = f"{snapshot_hash}|{delta.branch_id}|{sorted(delta.actual_write_set)}".encode() return hashlib.sha256(payload).hexdigest() def admit_merge(state: MergeState, deltas: List[BranchDelta]) -> Dict[str, str]: for d in deltas: # Invariant 1: partition ownership enforced at admission. if not d.actual_write_set.issubset(d.declared_write_set): raise UnwitnessedMergeError( f"branch {d.branch_id} wrote outside declared partition: " f"{d.actual_write_set - d.declared_write_set}" ) # Invariant 3: post_hash must be computed over (S0, delta), not local view. expected = compute_post_hash(state.snapshot_hash, d) if d.post_hash != expected: raise UnwitnessedMergeError( f"branch {d.branch_id} post_hash mismatch: self-report forged" ) # Invariant 2 + 4: destructive or conflicting writes require a witness. for f in d.actual_write_set: if d.destructive and not state.corroborated(d.branch_id, f): raise UnwitnessedMergeError( f"branch {d.branch_id} destructive write to {f} lacks witness" ) # Invariant 2: cross-partition reads must be witnessed. for r in d.read_set: if r not in state.committed and not state.corroborated(d.branch_id, r): raise UnwitnessedMergeError( f"branch {d.branch_id} read {r} without witness or committed write" ) for f in d.actual_write_set: state.committed[f] = d.branch_id return state.committed ```