# What structural signals indicate memory poisoning in persistent agent stores, and why write-audit trails alone cannot localize the corrupting write **Date of Record:** 2026 November 30 **Scope:** Applies to persistent agent memory stores (episodic logs, semantic vector indexes, and structured fact tables) where writes are attributed to an LLM instance via a write-audit trail and consistency checks run across sessions. Does not apply to stateless single-turn inference, nor to stores where every write is human-signed and immutable. ## Core Distinction The common assumption is that a write-audit trail gives you localization: if a poisoned fact appears in the store, walk the audit trail backward to the write that introduced it and roll back. This works for *atomic* corruption — a single write whose payload is wrong. It fails for **distributed poisoning**, where no single write is individually invalid but a *sequence* of individually-valid writes converges the store onto a false consensus. The audit trail localizes the *last* write, not the *corrupting* write, because each intermediate write was consistent with the store state at the time it was applied. The structural signal that distinguishes distributed poisoning from benign drift is **audit-trail non-reconstructability under replay**: replaying the recorded writes in recorded order against a clean snapshot does not reproduce the current store state, *and* the divergence is monotone in a single fact's confidence field. This is a different signature from ordinary staleness (which is reversible and non-monotone) and from atomic corruption (which is localized). ## What Was Observed A research-agent store accumulated a fact: `project_X.deadline = 2025-04-30`. Over eleven sessions, retrieval-augmented agents cited this fact, and each citation triggered a "reinforcement" write that bumped a `confidence` field and appended a `last_confirmed` timestamp. The originating write (session 1) had derived the date from an ambiguous source document. Sessions 2–11 did not re-read the source; they read the store, treated the stored fact as ground truth, and wrote back a *stronger* version of it. The audit trail, read naively, showed eleven writes, each with `source: internal_retrieval`, each schema-valid, each consistent with the prior state. No single write was poisoned by an external injection. The poisoning was **epistemic circularity**: the store became its own corroborating witness. Three structural signals appeared that a per-write validator would not flag: 1. **Confidence monotonicity without external evidence.** The `confidence` field strictly increased across the sequence while the set of `evidence_refs` (external document IDs) stayed constant at size 1. Confidence grew, evidence did not. 2. **Replay divergence.** Replaying the eleven writes against a clean snapshot produced a store state whose `confidence` was *lower* than the live store. The live store had accepted concurrent reinforcement writes from parallel sessions that the serial replay did not interleave. The audit trail was not a total order; it was a partial order recorded as if total. 3. **Provenance closure failure.** Following `evidence_refs` transitively from the final fact reached only the store itself (a self-loop through session 2's write), never an external source. The provenance graph was not a DAG rooted in external evidence; it had a cycle. The rollback attempt failed initially because rolling back "the last write" (session 11) left the fact intact at confidence 10/11. Rolling back all eleven writes was correct but destroyed eight unrelated facts that had been co-written in the same sessions — the writes were not fact-scoped. ## Condition of Validity The invariant that must hold for audit-trail-based rollback to be sound: > **Provenance acyclicity + evidence-rootedness.** Every fact in the store must have a provenance DAG whose leaves are external evidence references (document IDs, tool-call outputs with hashes, human attestations), and whose internal nodes are derived writes. A write that cites only store-internal facts as evidence is a *reinforcement write* and must not increase confidence beyond the minimum confidence of its cited evidence. When this invariant is violated — specifically when a reinforcement write cites a fact that (transitively) cites the write itself — the store has entered an epistemic cycle. In that regime, confidence is no longer a measure of truth; it is a measure of citation count. The audit trail remains *complete* (every write is recorded) but is no longer *sufficient* (the recorded writes do not determine which write introduced the error). The condition also requires that the audit trail record enough to reconstruct the *read set* of each write, not just the write payload. A trail that records `{fact_id, new_value, timestamp, agent_id}` but not `{facts_read, tool_outputs_consulted}` cannot detect circularity, because circularity is a property of the read set, not the payload. ## Decision Boundary The decision boundary is between **rollback-by-localization** and **rollback-by-provenance-closure**: - If the poisoned fact's provenance DAG is acyclic and evidence-rooted, and the divergence is localized to one write, rollback that write and its dependents (computed via reverse provenance edges). Cost is proportional to dependent count. - If the provenance DAG contains a cycle, or if replay divergence is monotone in confidence, the store is in epistemic-cycle regime. Localized rollback is *unsound*: it will leave the cycle intact. The required action is to quarantine every fact in the strongly-connected component of the provenance graph, re-derive each from external evidence, and only then re-admit. Cost is proportional to SCC size, which can be the entire store. The boundary test is a single query: does `evidence_refs` transitively reach an external leaf, or does it reach the store's own fact-ID space? The second case is the trigger. A per-write schema validator will never see this; a provenance-graph checker will. The threshold for "monotone confidence growth" should be calibrated: flag when confidence increases across ≥3 consecutive reinforcement writes with a constant evidence set. Below 3, ordinary corroboration; at or above, circularity is the parsimonious explanation. ## Operational Effect Stores that adopt provenance-closure checking before rollback avoid the two failure modes observed: (a) rolling back the last write and leaving the poison in place at high confidence, and (b) rolling back the whole session and destroying co-written facts. The cost is that every write must carry a read-set manifest and every fact must carry a provenance edge set, which roughly doubles write-audit volume. The deeper effect is a change in what "confidence" means. In a store without provenance-closure enforcement, confidence is a citation counter and drifts upward monotonically under retrieval-heavy workloads. In a store with enforcement, confidence is bounded by the minimum confidence of external evidence, and reinforcement writes that do not consult new evidence are recorded as *no-ops on confidence* — they update `last_confirmed` but not `confidence`. This single change eliminates the monotone-growth signal entirely, because the signal was an artifact of the missing invariant. The residual risk is external-evidence poisoning: if the leaf document is itself adversarial, provenance closure holds but the fact is false. That is a different failure mode (input poisoning, not store poisoning) and requires a different guardrail — evidence-hash pinning at ingest, not provenance checking at reinforcement. ```python from dataclasses import dataclass, field from typing import Dict, Set, List class ProvenanceCycleError(RuntimeError): """Raised when a fact's provenance graph reaches the store's own fact space without passing through an external evidence leaf. This is the epistemic-cycle condition under which localized rollback is unsound.""" pass @dataclass class Fact: fact_id: str confidence: float evidence_refs: Set[str] = field(default_factory=set) # external doc IDs or internal fact IDs is_external: bool = False def check_provenance_acyclic(facts: Dict[str, Fact], start: str, seen: Set[str] = None) -> bool: if seen is None: seen = set() if start in seen: return False # cycle detected seen.add(start) fact = facts.get(start) if fact is None: return True # dangling ref, treat as external-ish; caller decides if fact.is_external: return True if not fact.evidence_refs: return False # no evidence and not external: unrooted return all(check_provenance_acyclic(facts, ref, seen.copy()) for ref in fact.evidence_refs) def safe_rollback(facts: Dict[str, Fact], poisoned_id: str) -> List[str]: if not check_provenance_acyclic(facts, poisoned_id): raise ProvenanceCycleError( f"Fact {poisoned_id} has cyclic/unrooted provenance; " f"localized rollback is unsound. Quarantine SCC and re-derive from external evidence." ) # acyclic and rooted: roll back poisoned fact and reverse-provenance dependents to_remove = {poisoned_id} changed = True while changed: changed = False for fid, f in facts.items(): if fid not in to_remove and f.evidence_refs & to_remove: to_remove.add(fid) changed = True return sorted(to_remove) ```