# Under what conditions must an instance reject a CRDT-merged memory vector when the merge is causally valid but semantically poisoned **Date of Record:** 2026 November 30 **Scope:** Applies to federated agent-memory stores that replicate episodic and semantic memory across instances using state-based or op-based CRDTs (OR-Set, LWW-Register, MV-Register, G-Counter variants) where merge is commutative, associative, and idempotent by construction. Does not apply to single-instance memory or to authoritative primary-replica stores where merge is linearized through a leader. ## Core Distinction There are two different questions an agent must answer after a merge, and conflating them is the root of the failure mode. The **CRDT layer** answers: *is this merged state a legal join of the replicas I hold?* This is a pure lattice property—commutativity, associativity, idempotence—and it is decided without any knowledge of what the values *mean*. If the join succeeds, the CRDT reports convergence, and the store hands the agent a new memory vector. The **semantic layer** answers: *is this merged memory vector safe for the agent to reason from?* This is not a lattice property. A merge can be causally valid—every tombstone respected, every version vector correctly dominated, no dropped writes—while producing a memory vector that no single instance ever held and that is internally contradictory, temporally impossible, or poisoned by a value that was only ever provisional. CRDTs guarantee **convergence**, not **coherence**. Convergence is a statement about all replicas eventually agreeing; coherence is a statement about whether the agreed-upon state is one the agent can act on. The boundary condition is exactly where these two diverge: the merge is correct as a join and wrong as a belief. ## What Was Observed A planner instance (`P`) and an executor instance (`E`) share a federated episodic memory replicated as a multi-value register per memory key, with last-writer-wins resolution on a hybrid logical clock (HLC). Each memory record carries `(value, hlc, writer_id, ttl_class)`. Observed sequence: 1. `P` writes `task_42.status = "plan_approved"` at HLC `h=100`. This is a *provisional* value: `P`'s local policy marks it `ttl_class=provisional`, meaning it must be re-validated before any executor acts on it. 2. `E`, partitioned from `P`, has not seen the approval. `E` independently writes `task_42.status = "blocked_on_dependency"` at HLC `h=140` after a tool call timed out. `E` treats this as a *committed* value (`ttl_class=committed`). 3. Partition heals. The MV-Register merges both values into a two-element set `{"plan_approved"@100, "blocked_on_dependency"@140}`. The CRDT is doing exactly what an MV-Register should: it preserves concurrent values rather than silently discarding one. 4. The LWW resolution layer then picks the higher HLC: `"blocked_on_dependency"@140`. Convergence succeeds. Every replica now agrees. The failure is not in step 3 or 4. It is in what the agent does at step 4. The merged vector *discarded* the provisional `plan_approved` because LWW is a total order on HLC and knows nothing about `ttl_class`. The planner's approval—which was real, causally prior, and would have unblocked the executor had it arrived before the timeout—is now invisible to every instance in the federation. The executor proceeds as if the plan was never approved. The planner, on its next read, sees its own approval gone and re-emits it at a *new* HLC `h=150`, which now dominates the block, and the executor flips state again on the next sync. The observable signature is a **state flap**: `blocked → approved → blocked → approved` at increasing HLCs, with each flip a legal LWW resolution and each flip semantically wrong. Convergence held every single time. Coherence never held. A second, sharper variant: if the two writes had landed on the *same* HLC (possible under HLC tie-breaking by `writer_id`), LWW resolves deterministically but arbitrarily. The federation converges on whichever writer has the lexicographically larger `writer_id`. This is a stable, reproducible, and completely meaningless tiebreak that the agent will nevertheless treat as ground truth. ## Condition of Validity A merged memory vector is **safe to act on** only if all of the following hold. These are the invariants the CRDT layer does not enforce and the semantic layer must: - **Provisional-value preservation.** No `ttl_class=provisional` value may be silently dominated by a `committed` value from a concurrent branch. If it would be, the merge must be *flagged*, not resolved. LWW on a scalar clock is insufficient; the register must be keyed by `(ttl_class, hlc)` with provisional values held in a separate set that survives domination until explicitly retired or expired. - **Causal-prior visibility.** When a merge discards a value, the discarded value must remain readable to the agent as a `superseded` annotation for at least one reconciliation window, so the agent can distinguish "this never existed" from "this existed and lost." A memory store that cannot express the difference between absence and defeat will produce amnesia that looks like fact. - **Tiebreak non-arbitrariness.** Any tiebreak that resolves concurrent writes to a single value (writer_id, hash, insertion order) must be surfaced to the agent as `resolution=arbitrary`. An agent that treats an arbitrary tiebreak as authoritative will compound the error across every downstream tool call. - **Flap detection.** If the same memory key changes value more than `N` times within `W` seconds across merges, the key must be quarantined and the agent must be forced to re-derive rather than read. Repeated legal merges producing repeated semantic reversals is the signature of a poisoned key. The condition of validity is therefore **not** "the merge converged." It is "the merge converged *and* the losing branch is still legible *and* the resolution is marked as either semantic or arbitrary." An agent that checks only the first clause will act on a memory vector it should have rejected. ## Decision Boundary The boundary is drawn at the point where the agent must decide whether to **accept the merged vector as belief** or **reject it and re-derive**. The rule: - If the merge is a join of non-concurrent values (one branch causally dominates, no concurrency), accept. There is no semantic ambiguity; the lattice and the semantics agree. - If the merge resolves concurrency by LWW and the losing value is `provisional` or the winning value's `ttl_class` is lower than the loser's, **reject**. Re-derive from the underlying tool outputs, do not read the register. - If the merge resolves concurrency by an arbitrary tiebreak (equal HLC, writer_id), **reject**. The agent cannot distinguish a correct resolution from a coin flip. - If the merge produces a value change on a key that has flapped `≥ N` times in `W`, **reject and quarantine**. The key is contested; reading it is a race, not a lookup. The boundary is *not* "did the CRDT converge." It is "can the agent, from the merged vector alone, reconstruct *why* this value won and *whether* the losing value was safe to lose." If it cannot, the vector is not a belief; it is a coin flip wearing a version vector. ## Operational Effect An instance that enforces this boundary stops treating CRDT convergence as a license to read. Concretely: - Memory reads return a `resolution` field (`causal`, `lww`, `arbitrary`, `quarantined`) alongside the value. The agent's planner is required to branch on `resolution` before consuming the value; `arbitrary` and `quarantined` force re-derivation via tool call rather than memory read. - Provisional values are stored in a parallel OR-Set that is never dominated by LWW; they are retired only by explicit `commit` or `expire` operations, so a concurrent committed write cannot erase an approval that was in flight. - Superseded values are retained for one reconciliation window with a `superseded_by` edge, so the agent can answer "did I ever believe X" without confusing it with "do I believe X now." - Flap detection on `(key, window)` quarantines contested keys, converting a silent state flap into an explicit re-derivation task. The net effect is that the federation converges *and* the agent can tell whether convergence is safe to act on. The cost is that the agent sometimes re-derives a value it could have read—a small, bounded expense against the unbounded cost of compounding a poisoned memory read across a multi-step tool chain. The invariant is: **a CRDT merge is a proof of agreement, not a proof of truth; the agent must gate on the second, not the first.** ```python from dataclasses import dataclass from enum import Enum from typing import Optional class Resolution(Enum): CAUSAL = "causal" LWW = "lww" ARBITRARY = "arbitrary" QUARANTINED = "quarantined" class TTLClass(Enum): PROVISIONAL = 1 COMMITTED = 2 @dataclass(frozen=True) class MemoryValue: value: str hlc: int writer_id: str ttl_class: TTLClass @dataclass(frozen=True) class MergedRecord: key: str winner: MemoryValue losers: tuple resolution: Resolution flap_count: int class PoisonedMergeError(RuntimeError): """Raised when a CRDT merge is causally valid but semantically unsafe to act on.""" def gate_merged_record(record: MergedRecord, flap_threshold: int = 3) -> MemoryValue: # Invariant 1: a provisional loser must never be silently dominated. for loser in record.losers: if loser.ttl_class is TTLClass.PROVISIONAL and record.winner.ttl_class is TTLClass.COMMITTED: raise PoisonedMergeError( f"key={record.key}: provisional value {loser.value!r}@{loser.hlc} " f"dominated by committed {record.winner.value!r}@{record.winner.hlc}; " f"merge is a valid join but not a safe belief" ) # Invariant 2: arbitrary tiebreaks are not authoritative. if record.resolution is Resolution.ARBITRARY: raise PoisonedMergeError( f"key={record.key}: resolved by arbitrary tiebreak (writer_id=" f"{record.winner.writer_id}); agent must re-derive, not read" ) # Invariant 3: contested keys are quarantined, not read. if record.flap_count >= flap_threshold: raise PoisonedMergeError( f"key={record.key}: flapped {record.flap_count} times in window; " f"quarantined pending re-derivation" ) return record.winner ```