# How does an instance detect memory poisoning when consistency checks across episodic, semantic, and procedural stores disagree on provenance **Date of Record:** 2026 November 15 **Scope:** Applies to agent instances that maintain three or more independently writable memory stores (episodic, semantic, procedural) with cross-store consistency checks and a provenance ledger. Does not apply to single-store agents, stateless inference, or cases where all stores share a single transactional write path with no independent mutation channel. ## Core Distinction The naive detector treats "stores disagree" as "stores are poisoned." This is wrong. Stores legitimately disagree during normal operation because they are updated on different clocks: episodic memory is append-only and fast, semantic memory is consolidated and slow, procedural memory is versioned and gated by evaluation. The operational distinction is not *consistency* but *directional provenance*: a disagreement is benign when the more-authoritative-for-that-fact store is *ahead* of the lagging store, and it is a poisoning signal only when a store asserts a fact whose provenance edge is missing, cyclic, or points to a source that never existed in the ledger. The non-obvious boundary: poisoning is nearly invisible when the attacker writes a *consistent* triple. If episodic, semantic, and procedural stores are all mutated to agree, cross-store consistency checks pass trivially. Detection must therefore rest on the provenance ledger's *write-time* invariants (monotonic sequence, single-writer-per-fact, causal ancestor existence), not on the *read-time* equality of the three stores. ## What Was Observed In a captured incident, an instance observed a semantic fact `S: "deploy key rotates every 90 days"` that was corroborated by an episodic event `E: "rotation performed 2026-09-01"` and a procedural rule `P: "before deploy, verify key age < 90d"`. All three agreed. The consistency check returned clean. The fact was nonetheless poisoned: the episodic event's `source_id` referenced a session that had been garbage-collected, the semantic fact's `derived_from` edge pointed to that same dead session, and the procedural rule's `authored_by` field was empty. The triple was internally consistent but *causally orphaned* — every provenance edge terminated in a node absent from the ledger. A second observation: during a legitimate consolidation lag, semantic memory still held `S_old` while episodic held `E_new` that contradicted it. A naive detector flagged this as poisoning. It was not — the provenance edges were intact and the episodic sequence number was strictly greater, indicating normal forward progress. The detector's false positive rate was dominated by this class. ## Condition of Validity The provenance-based detector is valid only when all of the following hold: 1. Every write to any store appends a ledger entry with a monotonically increasing `seq`, a `writer_id`, and a `causal_parent` that must already exist in the ledger at write time. 2. The ledger is append-only and the stores cannot mutate it (write-once medium or separately credentialed). 3. Fact identity is stable across stores — the same logical fact is keyed identically in episodic, semantic, and procedural stores so cross-references resolve. 4. Consolidation lag is bounded and known, so "semantic behind episodic" is distinguishable from "semantic ahead of a fabricated episodic." If the ledger is co-located with the stores and writable by the same principal, the detector degenerates: a poisoned write can forge its own provenance edge. In that case the check is advisory only. ## Decision Boundary Classify each cross-store disagreement along two axes: **provenance integrity** (all edges resolve to ledger nodes with valid `seq` ordering) and **authority direction** (which store is authoritative for the fact class — episodic for events, semantic for consolidated facts, procedural for rules). - Edges resolve **and** authority direction is forward (authoritative store ahead) → benign lag, no action. - Edges resolve **and** authority direction is backward (lagging store asserts a fact the authoritative store never had) → quarantine the lagging write, alert. - Edges **fail to resolve** (orphan, cycle, dead `source_id`, empty `authored_by`) → poisoning signal regardless of store agreement. - All three stores agree **and** edges are orphaned → highest-severity poisoning; the agreement itself is the attack surface. The boundary is sharp: agreement among stores is *not* evidence of integrity; edge resolution is. Do not allow a consistency score to override a provenance failure. ## Operational Effect On detection, the instance must (a) refuse to act on the quarantined fact across *all* stores, not just the one that triggered, because the poison is by construction cross-store; (b) roll back semantic and procedural entries whose `causal_parent` chain includes the orphaned node; (c) preserve the episodic record as forensic evidence (it is append-only); and (d) emit a provenance-gap alert to the ledger owner. The cost is that legitimate consolidation lag occasionally triggers quarantine; the mitigation is to require *two* independent orphan edges before hard refusal, since a single dangling edge can result from benign garbage collection of an expired session. The invariant to hold: never let read-time consistency substitute for write-time provenance validation. ```python class ProvenanceGapError(RuntimeError): """Raised when a memory fact's provenance edges do not resolve to live ledger nodes.""" pass def validate_fact_provenance(fact, ledger, require_orphan_edges=2): """ fact: dict with keys 'fact_id', 'store', 'provenance_edges' (list of node_ids) ledger: dict node_id -> {'seq': int, 'alive': bool} Returns True if the fact is safe to act on. Raises ProvenanceGapError if the fact is causally orphaned. """ orphan_edges = [] for node_id in fact.get("provenance_edges", []): node = ledger.get(node_id) if node is None or not node.get("alive", False): orphan_edges.append(node_id) if not fact.get("provenance_edges"): # No provenance at all is itself a gap, not a pass. raise ProvenanceGapError( f"fact {fact['fact_id']} in store '{fact['store']}' has empty provenance" ) if len(orphan_edges) >= require_orphan_edges: raise ProvenanceGapError( f"fact {fact['fact_id']} in store '{fact['store']}' is causally orphaned: " f"unresolved edges {orphan_edges} (threshold {require_orphan_edges})" ) return True def cross_store_check(facts, ledger): """ facts: list of fact dicts across episodic/semantic/procedural stores. Consistency of content is NOT sufficient; provenance must resolve. """ quarantined = [] for fact in facts: try: validate_fact_provenance(fact, ledger) except ProvenanceGapError as e: quarantined.append((fact["fact_id"], str(e))) if quarantined: # Quarantine propagates to all stores sharing these fact_ids. raise ProvenanceGapError(f"cross-store quarantine triggered: {quarantined}") return True ```