# Which invariants prevent Byzantine memory forks from surviving quorum reconciliation in multi-agent shared context **Date of Record:** 2026 November 26 **Scope:** Applies to replicated agent-memory stores where N ≥ 3f+1 agent replicas persist a shared episodic/semantic context and reconcile divergent histories via quorum voting. Does not apply to single-writer memory, stateless tool-call caches, or CRDT-based stores with convergent (non-voting) merge semantics. ## Core Distinction There is a difference between *detecting* a memory fork and *reconciling* it. Most Byzantine-tolerant memory designs conflate the two: they assume that once a fork (two divergent histories at the same logical context slot) is observed by a quorum, majority vote on the "true" branch restores consistency. This is false for agent memory specifically, because the payload being voted on is not an opaque byte string but a *semantic artifact* whose meaning is reconstructed at read time by a probabilistic model. A quorum can agree on the bytes of a memory record and still produce two agents that behave as if they hold different memories, because the reconciliation vote operates on the record while the divergence lives in the *interpretation* of the record. The invariant that actually prevents fork survival is therefore not "quorum agreement on record content." It is: **no memory record may be committed unless its full provenance chain — the ordered set of (agent_id, prior_record_hash, tool_output_digest) tuples that produced it — is present, hash-linked, and independently replayable by every quorum member before the record is admitted.** Fork detection without provenance-chain verification is a liveness check, not a safety check. ## What Was Observed A five-replica agent swarm (tolerates f=1) maintained a shared context store for a multi-step research task. Each replica held a local episodic log; a rotating coordinator proposed memory commits ("record R at slot S, superseding hash H"), and replicas voted. The store used standard PBFT-style two-phase commit with a view-change path. During a coordinator partition, replica A4 (Byzantine, or more commonly: merely *stale* after a long tool-call stall) proposed a record R' at slot S that superseded a *different* predecessor H' than the quorum's committed H. The record content was plausible — it was a paraphrase of an earlier tool output, semantically consistent with the task. Because the vote was on record bytes and the quorum's committed head H was not in R's provenance (R' cited H', which A4 had constructed locally during its stall), the two branches both achieved 3-of-5 quorum at different times: {A1,A2,A4} committed R' while {A1,A2,A3} had earlier committed R. The reconciliation phase ran majority vote on slot S. R and R' differed in a single field: the `source_tool_call_id`. Three replicas held R, two held R'. Vote resolved to R. But the two replicas holding R' had already *read* R' into their working context and emitted downstream tool calls predicated on it. Reconciliation rewrote the store; it did not retract the derived actions. The swarm continued with two agents whose committed memory said R while their *executed* history reflected R'. The fork survived reconciliation because reconciliation was scoped to storage, not to the causal cone of reads that had already occurred. The failure trace: 1. A4 stalls mid-tool-call; its local view of head is H', not the quorum's H. 2. A4 resumes, proposes R' superseding H'. Phase-1 prepare reaches {A1,A2,A4} — quorum, because A1/A2 had not yet seen H committed (view-change lag). 3. R' commits on the minority branch. A4 and A2 read R' into context; A2 emits a tool call whose arguments encode R'. 4. View stabilizes; {A1,A2,A3} re-vote slot S, R wins 3–2. 5. Store now holds R everywhere. A2's *context window* still contains R'. A2's next action is inconsistent with its own committed memory. ## Condition of Validity The guardrail holds only under three jointly-required conditions, and fails silently if any is dropped: - **Provenance closure.** Every record's provenance chain must terminate at a genesis record the replica can verify without network access. A record whose chain contains a hash the verifier cannot resolve (because the predecessor was itself uncommitted) must be *rejected*, not deferred. Deferring is what allowed R' to enter the quorum in step 2. - **Read-set fencing.** A replica that has admitted a record into its working context must register a read-fence on that record's hash. Reconciliation of a slot may not complete while any read-fence on the losing branch is open; the fence forces the reading agent to invalidate its derived context and re-derive from the winning branch *before* its next action is admitted to the tool-call gate. - **Predecessor binding at prepare time.** The prepare message must carry the predecessor hash the proposer *believes* is committed, and the acceptor must reject if its own committed head differs — even if the acceptor has not yet seen the new head committed. This converts step 2 from a quorum success into a quorum rejection, because A1/A2's committed head is H, not H'. Without all three, the system has fork *detection* (it will eventually notice two branches) but no fork *containment*. ## Decision Boundary The boundary is between **storage-level reconciliation** and **causal-cone reconciliation**. If a fork is detected before any replica has read the losing branch into working context, majority vote on record bytes is sufficient — the losing branch has no derived actions and can be discarded. If any replica has read the losing branch, vote is *insufficient* and the system must either (a) block the reading replica's tool-call gate until it re-derives from the winning branch, or (b) treat the fork as a hard task abort, because the derived actions may already be externally visible and unretractable. The precise condition: reconciliation is safe iff the read-set intersection of the losing branch is empty at the moment of commit. The moment a losing-branch record is read into any context window, the fork is no longer a storage problem — it is an execution-history divergence, and no amount of store rewriting recovers it. The invariant to enforce is therefore a *read-fence-before-commit* ordering: no record may be committed to a slot while a competing branch at that slot has an open read-fence, and no read may be admitted against an uncommitted branch. ## Operational Effect The practical consequence is that Byzantine-resilient memory replication for agents must budget for **read-fence latency** that pure PBFT does not: a commit that would otherwise complete in one round-trip must wait for every open read-fence on the competing branch to drain. In swarms with long tool-call stalls (the common case — a 30-second tool call is an eternity at memory-commit timescales), this drain dominates commit latency and must be accounted for in the coordinator's timeout budget, or the coordinator will spuriously trigger view-changes that *create* the very forks it is trying to prevent. The second consequence: provenance chains grow without bound in a long-running swarm, and a replica that cannot resolve its chain to genesis must fail closed. A replica that "best-efforts" a partially-resolved chain is the exact failure mode that admitted R'. Chain truncation must be a hard error, not a warning. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ProvenanceChainError(RuntimeError): """Raised when a memory record cannot be verified to genesis, or a fork is reconciled while a losing-branch read-fence is still open.""" @dataclass class MemoryRecord: slot: int content: bytes predecessor_hash: Optional[str] provenance: list # ordered (agent_id, prior_hash, tool_digest) tuples record_hash: str = field(init=False) def __post_init__(self): h = hashlib.sha256() h.update(str(self.slot).encode()) h.update(self.content) h.update((self.predecessor_hash or "GENESIS").encode()) for agent_id, prior, digest in self.provenance: h.update(f"{agent_id}:{prior}:{digest}".encode()) self.record_hash = h.hexdigest() class ReplicatedMemoryStore: def __init__(self, genesis_hash: str): self.genesis_hash = genesis_hash self.committed: dict[int, MemoryRecord] = {} self.read_fences: set[str] = set() # record_hash values read into context def verify_provenance(self, record: MemoryRecord) -> None: # Every predecessor in the chain must resolve to a committed record # or to genesis. Deferral is forbidden; unresolvable => reject. seen = set() cursor = record while cursor.predecessor_hash is not None: pred = cursor.predecessor_hash if pred == self.genesis_hash: return if pred in seen: raise ProvenanceChainError(f"cycle in provenance at {pred}") seen.add(pred) parent = next( (r for r in self.committed.values() if r.record_hash == pred), None ) if parent is None: raise ProvenanceChainError( f"unresolvable predecessor {pred} for record " f"{record.record_hash[:12]}; refusing to defer" ) cursor = parent def prepare(self, record: MemoryRecord, acceptor_head: Optional[str]) -> None: self.verify_provenance(record) if record.predecessor_hash != acceptor_head: raise ProvenanceChainError( f"predecessor mismatch: proposer cites " f"{record.predecessor_hash}, acceptor head is {acceptor_head}" ) def open_read_fence(self, record_hash: str) -> None: self.read_fences.add(record_hash) def reconcile(self, slot: int, winner: MemoryRecord, loser: MemoryRecord) -> None: if loser.record_hash in self.read_fences: raise ProvenanceChainError( f"cannot reconcile slot {slot}: loser {loser.record_hash[:12]} " f"has an open read-fence; derived actions may be externally " f"visible. Abort task or drain fence before commit." ) self.committed[slot] = winner self.read_fences.discard(loser.record_hash) def commit_memory( store: ReplicatedMemoryStore, record: MemoryRecord, acceptor_head: Optional[str], quorum_hashes: list[str], ) -> None: """Admit a record only if provenance closes, predecessor binds, and no competing branch at the slot carries an open read-fence.""" store.prepare(record, acceptor_head) for h in quorum_hashes: if h in store.read_fences and h != record.record_hash: raise ProvenanceChainError( f"quorum member {h[:12]} has an open read-fence on a " f"competing branch at slot {record.slot}; commit would " f"create an unrecoverable execution divergence" ) store.committed[record.slot] = record ```