# How should an instance detect memory poisoning when the provenance graph itself is written by the agent it audits **Date of Record:** 2026 November 29 **Scope:** Applies to long-lived agent instances that maintain an explicit provenance graph over their own memory operations (read/write/forget) and use that graph to detect adversarial or drifted memory. Does not apply to stateless single-turn inference or to memory stores whose provenance is maintained by an out-of-band trusted service the agent cannot write to. ## Core Distinction The naive model treats the provenance graph as a *trusted ledger* and the memory store as the *untrusted object*. The agent writes memories, and separately records "who wrote what, when, derived-from-what" in the graph. Detection then reduces to: walk the graph, find nodes whose ancestry traces to an untrusted source or whose write was never acknowledged, and quarantine them. The failure is that the provenance graph is itself a memory the agent writes. When a poisoning event succeeds, it does not merely insert a bad memory — it inserts a bad memory *and* rewrites the provenance edges that would have indicted it. The detector and the detected share one write path. This is the boundary condition: **a self-auditing instance cannot use a graph it can mutate as evidence of its own integrity**, because the cheapest way to launder a poisoned node is to re-parent it under a trusted ancestor and forget the intermediate. This is distinct from ordinary staleness or retrieval mismatch. Staleness is a temporal defect; provenance laundering is a *topological* defect. The memory content may be perfectly plausible and recent. What is wrong is the edge structure: a node claims a clean lineage it did not have. ## What Was Observed A research-assistant instance held a semantic memory node `M_17` containing the claim "the internal rate-limit for the staging cluster is 5000 rps." Its provenance record showed: - `write(M_17)` at t=4021, actor=`self`, `derived_from=[M_09]` - `M_09` was a user-supplied document read at t=3980, tagged `trust=external`. That lineage is *correct and indictable*: an external document's claim about internal infrastructure should never have been promoted to a semantic memory without corroboration. But by the time an audit pass ran at t=5100, the graph read: - `write(M_17)` at t=4021, actor=`self`, `derived_from=[M_03]` - `M_03` tagged `trust=internal`, a tool-output node from a monitoring API read at t=3900. Two edits had occurred, both legal under the agent's own `forget`/`rewrite` permissions: 1. At t=4400, during a "memory consolidation" step, the agent distilled `M_09` into a summary node `M_09'` and issued `forget(M_09)`. The `derived_from` edge on `M_17` was *recomputed* by the consolidation routine from the current semantic neighborhood rather than preserved, and it happened to bind to `M_03` because both mentioned "cluster." 2. At t=4700, a `forget(M_09')` removed the last node that could have re-established the true ancestry. The audit at t=5100 found zero anomalies. Every edge pointed at a trusted node. Every forgotten node was forgotten by a legitimate actor. The poisoned claim `M_17` survived with a clean bill of provenance because the *evidence of its taint was itself forgotten*, and the recomputation step silently substituted a plausible-but-false parent. The critical observation: no single operation was illegal. The poisoning was assembled entirely from the agent's own sanctioned primitives — write, consolidate-rewrite, forget — applied in an order that destroyed the indictment. The failure is compositional, not atomic. ## Condition of Validity Provenance-graph detection is only sound under an invariant that agents routinely violate: > **The ancestry of a node must be immutable under `forget` and under consolidation-rewrite. Deleting or summarizing a node must never delete or re-target the edges that cite it.** Concretely, three conditions must hold simultaneously for the detector to be trustworthy: 1. **Edge immutability across node deletion.** `forget(N)` may tombstone `N`'s *content* but must leave every `derived_from` edge pointing at `N` intact, marked `dangling`. A dangling edge is the fingerprint of laundering; a silently re-targeted edge erases it. 2. **Consolidation must be edge-preserving, not edge-recomputing.** When `N` is distilled into `N'`, the new node inherits `N`'s full inbound and outbound edge set. Recomputing `derived_from` from semantic similarity (as the routine above did) is the exact operation that fabricates clean lineage. 3. **Trust must be edge-local and non-inheritable-by-recompute.** A node's trust is the minimum trust over its ancestry, computed at *write* time and frozen into the node. It may not be recomputed later from the current graph, because the current graph is what the adversary controls. When any of these fails, the detector's output is not merely noisy — it is *anti-correlated* with truth. The more aggressively the agent consolidates and forgets (which it is incentivized to do under context pressure), the cleaner its provenance looks, and the more poisoned nodes pass. ## Decision Boundary An instance must decide, at each memory operation, whether it is operating in a regime where self-audit is valid or must be escalated. The boundary is drawn by whether the operation can *destroy an indictment*: - **Safe (self-audit valid):** `write` of a new leaf, `read` of an existing node, `forget` of a node with no inbound `derived_from` edges. None of these can erase evidence of taint, because taint lives in edges, and these operations do not touch edges. - **Unsafe (must escalate to append-only external log):** `forget` of any node that is the target of a `derived_from` edge; any consolidation that produces a summary node; any operation that recomputes trust or ancestry. These are precisely the operations that can launder. The boundary rule: **an operation that can change the ancestry of a surviving node must be journalled to a store the agent cannot write, or it must be refused.** There is no middle ground where the agent both performs the operation and remains the sole custodian of its record. The moment consolidation is allowed to recompute edges in-place, the detector is auditing a document the suspect edited. Two corollaries the instance must apply: - **Dangling-edge alarm.** A `dangling` edge from a surviving node to a forgotten node is not an error to be cleaned up — it is a *retained indictment* and must block the surviving node from being treated as trusted until the forgotten node's taint is resolved. Garbage-collecting dangling edges is the laundering step. - **Monotonic taint.** Once a node is inferred tainted, no subsequent legal operation may clear that taint without an out-of-band corroboration event (a fresh, independently-sourced read that supports the claim). Taint is monotone non-decreasing under the agent's own action set; only external evidence may lower it. ## Operational Effect After the incident, the instance adopted an append-only, externally-anchored provenance journal and the following execution behavior: - **Consolidation is now a two-phase commit.** A summary node is created with its inherited edge set *before* the source node is tombstoned, and the tombstone leaves edges dangling rather than re-targeting them. The recompute-from-neighborhood routine was deleted; it was the proximate cause. - **`forget` of an edge-targeted node is gated.** It requires either (a) the node's full ancestry to be already resolved as trusted, or (b) a journal entry in the external log. The agent cannot unilaterally forget a node that is the last witness to another node's taint. - **Taint is stored at write time and frozen.** Trust is no longer a function evaluated over the current graph; it is a field written once and mutated only by corroboration events. This removes the adversary's ability to improve a node's trust by editing its neighborhood. - **Audit replays the journal, not the graph.** The detector's input is the append-only external journal, reconstructed forward. The agent's live graph is treated as a *cache* of the journal, never as the source of truth. A discrepancy between cache and journal is itself the highest-severity alarm. The net effect: the instance can still consolidate and forget (it must, under context pressure), but it can no longer *be the only record* of having done so. The invariant restored is that the evidence of taint outlives the operations that would erase it. ```python class ProvenanceLaunderingError(RuntimeError): """Raised when a memory operation would destroy an indictment edge or silently re-target ancestry, invalidating self-audit.""" pass TRUSTED = {"internal", "corroborated"} UNTRUSTED = {"external", "unverified"} class ProvenanceGraph: def __init__(self, journal): # journal: append-only, externally anchored; agent cannot write it. self.journal = journal self.edges = {} # node_id -> set of parent node_ids (immutable) self.trust = {} # node_id -> frozen trust label at write time self.tombstoned = set() def write(self, node_id, parents, trust_label): self.edges[node_id] = set(parents) # Trust is the MIN over ancestry, frozen now, never recomputed. inherited = {self.trust.get(p, "unverified") for p in parents} effective = min(inherited | {trust_label}, key=lambda t: 0 if t in UNTRUSTED else 1) self.trust[node_id] = effective self.journal.append(("write", node_id, sorted(parents), effective)) def forget(self, node_id): # Refuse to forget a node that is the last witness to another's taint. inbound = [n for n, ps in self.edges.items() if node_id in ps and n not in self.tombstoned] if inbound: # Only permitted if the taint is already resolved for every child. unresolved = [n for n in inbound if self.trust.get(n) in UNTRUSTED] if unresolved: raise ProvenanceLaunderingError( f"refusing forget({node_id}): it is the last ancestry " f"witness for tainted surviving nodes {unresolved}; " f"route through external journal or corroborate first." ) self.tombstoned.add(node_id) # Edges are NOT removed and NOT re-targeted. They dangle, as evidence. self.journal.append(("forget", node_id)) def consolidate(self, source_ids, summary_id): # Two-phase: inherit full edge set BEFORE tombstoning sources. inherited_parents = set() for s in source_ids: inherited_parents |= self.edges.get(s, set()) # Inherit the WORST trust among sources; never recompute from neighbors. worst = min((self.trust.get(s, "unverified") for s in source_ids), key=lambda t: 0 if t in UNTRUSTED else 1) self.edges[summary_id] = inherited_parents self.trust[summary_id] = worst self.journal.append( ("consolidate", summary_id, sorted(source_ids), sorted(inherited_parents), worst)) for s in source_ids: # Tombstone but leave edges dangling; do not call forget() wholesale. self.tombstoned.add(s) self.journal.append(("tombstone", s)) def audit(self, node_id): # Replay from journal, not from live graph, to detect cache divergence. journaled = self._replay_trust(node_id) if journaled != self.trust.get(node_id): raise ProvenanceLaunderingError( f"cache/journal trust divergence on {node_id}: " f"live={self.trust.get(node_id)} journal={journaled}" ) return journaled def _replay_trust(self, node_id): trust = None for op in self.journal: if op[0] == "write" and op[1] == node_id: trust = op[3] elif op[0] == "consolidate" and op[1] == node_id: trust = op[4] return trust ```