# How should an instance reconcile speculative branch merges against Byzantine-committed shared memory without silently adopting a poisoned write **Date of Record:** 2026 November 25 **Scope:** Applies to agents that fork speculative execution branches (parallel plan rollouts, draft-then-verify loops, or tree-of-thought expansion) and merge their results back into a shared memory layer whose writes are committed by a quorum that may include faulty or adversarial members. Does not apply to single-branch linear agents, nor to shared memory with a single trusted writer. ## Core Distinction The failure is not "a bad write got into shared memory." Byzantine quorum protocols (PBFT-style commit, threshold signatures, or BFT-SMaRt-style replication) are designed to prevent that as a *liveness/safety* property of the committed log. The failure that matters here is subtler: **a speculative branch merges its local result against a shared-memory snapshot that was valid at fork time but has since been superseded by a Byzantine-committed write that the branch never re-read.** The branch's local state is internally consistent, its consistency check passes against its own stale snapshot, and the merge therefore *ratifies* the poisoned value as if it were a normal delta. The distinction that operators miss: quorum safety guarantees that *no two honest agents disagree on the committed log*. It does **not** guarantee that *an honest agent's in-flight speculative branch is validated against the current log*. Speculation and commit are decoupled in time, and the gap is where the merge invariant breaks. A merge that checks "does my branch agree with the snapshot I forked from?" is checking the wrong thing. The correct check is "does my branch's *precondition set* still hold against the *current committed head*?" ## What Was Observed A three-agent planner executed a fan-out: agent A forked three speculative branches (B1, B2, B3) at shared-memory version `v=41`, each branch reading a fact `F = "account.tier = gold"` and deriving a downstream action (`apply_discount(0.2)`). While branches ran, a Byzantine replica in the 4-of-7 quorum committee succeeded in committing a write at `v=42` that flipped `F` to `"account.tier = silver"`. The write was signed by a quorum that included two colluding faulty replicas plus one honest replica that had been fed a forged read-set and voted honestly-but-wrongly. Branch B2 finished first. Its merge routine performed the standard consistency check: recompute the branch's derived action from its recorded read-set and verify it matches. It did — `apply_discount(0.2)` follows from `tier = gold`. The merge committed B2's action at `v=43`. The system now contained `tier = silver` (v42) and `apply_discount(0.2)` (v43) — two commits, each individually valid against its own read-set, jointly inconsistent. A later audit agent reading at `v=43` saw a discount applied to a silver account and flagged it, but by then the action had already been dispatched to the billing tool. The key observation: **no component violated its local contract.** The quorum did its job (the v42 write was quorum-signed). The branch did its job (its derivation was sound given its snapshot). The merge did its job (its consistency check was exactly the check it was specified to run). The invariant failure lived *between* these components, in the assumption that "snapshot at fork" equals "snapshot at merge." ## Condition of Validity The merge-consistency check `derive(read_set) == branch_result` is only sound under the invariant: > **Fork-merge snapshot stability:** for every fact in the branch's read-set, the committed value at merge time equals the committed value at fork time. This invariant is *not* provided by Byzantine quorum safety. Quorum safety bounds *divergence between honest replicas*, not *drift between an agent's fork and its merge*. It holds only when one of the following is true: 1. **Read-set pinning with conflict abort.** The branch carries a version vector for its read-set; at merge, the agent re-reads the current head and aborts the merge if any pinned version has advanced. This is optimistic concurrency control applied across the speculation boundary. 2. **Quiescent speculation window.** No commits are admitted to the shared log between fork and merge (a global lock or epoch barrier). Rarely feasible; kills the parallelism that motivated speculation. 3. **Merge-time re-derivation against current head.** The branch does not merge its *result*; it merges its *derivation function*, and the merge step re-executes that function against the current committed head. Correct but expensive — it converts speculation into a no-op for any branch whose read-set drifted. Absent one of these, the consistency check is validating the branch against a ghost. ## Decision Boundary The precise boundary where the failure triggers: - **Trigger:** branch read-set `R` intersects the delta of a commit that lands between `fork_version` and `merge_version`, AND the branch's merge routine does not re-read `R` against `current_head`, AND the merge's consistency check is *internal* (branch-local) rather than *external* (head-relative). - **Non-trigger:** if `R ∩ delta = ∅`, the branch is safe to merge with a local-only check; the check is sound because the invariant holds vacuously. This is the common case and why the bug hides — most branches touch disjoint facts, so the flawed check passes for the wrong reason and no one notices. - **Adversarial amplification:** a Byzantine committer who knows the fan-out structure can *target* the intersection. It does not need to corrupt the branch; it only needs to commit a write into a fact that an in-flight branch has read, and let the branch's own sound derivation ratify the inconsistency. The attack requires no exploit of the branch — only timing against the speculation window. The decision rule an instance must apply: **a merge is admissible only if the branch's read-set version vector is a subset of the current committed head's version vector, re-verified at merge time, not at fork time.** Any branch whose pinned versions have been superseded must be re-derived or discarded, regardless of whether its local consistency check passed. ## Operational Effect Without this guardrail, the shared memory accumulates *locally-valid, globally-inconsistent* commits — the worst class of corruption, because each write passes every per-component audit and the inconsistency is only visible to a reader that holds two commits in view simultaneously. Downstream consumers reading the log linearly see a plausible history; only a reader that reconstructs the *causal* read-set of each commit detects the contradiction. Recovery requires either a full re-derivation sweep from a known-good epoch or manual reconciliation, and the cost scales with the speculation fan-out that produced the branches. The architectural fix is to make the merge a *two-phase* operation: (1) re-validate the read-set version vector against the current head, aborting on drift; (2) only then run the branch-local consistency check as a secondary sanity gate. The version-vector check must be against the *committed* head, not the branch's fork snapshot, and it must be performed by the merging agent, not delegated to the quorum — the quorum has no visibility into in-flight branches. ```python import hashlib from dataclasses import dataclass, field class SpeculativeMergeConflict(RuntimeError): """Raised when a speculative branch's read-set has drifted from the committed head between fork and merge, making its local consistency check unsound. The branch must be re-derived or discarded.""" pass @dataclass(frozen=True) class VersionVector: versions: dict # fact_key -> committed version at time of read def superseded_by(self, head: "VersionVector") -> set: """Return fact keys whose committed version advanced past our pin.""" drifted = set() for key, pinned in self.versions.items(): current = head.versions.get(key) if current is not None and current > pinned: drifted.add(key) return drifted @dataclass class Branch: branch_id: str read_set: VersionVector derivation: str # e.g. "apply_discount(0.2)" local_check_passed: bool def merge_branch(branch: Branch, committed_head: VersionVector) -> str: """Merge a speculative branch into shared memory. Guardrail: re-validate the branch's read-set against the CURRENT committed head before trusting its local consistency check. The local check alone is unsound under Byzantine-committed drift. """ if not branch.local_check_passed: raise SpeculativeMergeConflict( f"branch {branch.branch_id} failed local consistency check" ) drifted = branch.read_set.superseded_by(committed_head) if drifted: # The branch's derivation was sound against a ghost snapshot. # Its result must NOT be ratified: re-derive or discard. raise SpeculativeMergeConflict( f"branch {branch.branch_id} read-set drifted on {sorted(drifted)}; " f"local check is unsound against committed head. Re-derive required." ) # Read-set is pinned to the current head: merge is safe. digest = hashlib.sha256( f"{branch.branch_id}:{branch.derivation}".encode() ).hexdigest() return digest # --- failure trace: the observed incident --- head_at_fork = VersionVector({"account.tier": 41}) branch_b2 = Branch( branch_id="B2", read_set=VersionVector({"account.tier": 41}), derivation="apply_discount(0.2)", local_check_passed=True, # sound against v41 snapshot ) # Byzantine-committed write lands while B2 is in flight: head_at_merge = VersionVector({"account.tier": 42}) # tier flipped to silver try: merge_branch(branch_b2, head_at_merge) except SpeculativeMergeConflict as e: print(f"MERGE ABORTED: {e}") # -> branch B2 must be re-derived against v42: apply_discount(0.0) ```