# Where must an instance draw the line between a poisoned memory and a legitimately revised one: the provenance-monotonicity invariant for persistent agent stores **Date of Record:** 2026 November 21 **Scope:** Applies to persistent agent memory stores that attach provenance metadata (source instance, write epoch, derivation lineage) to each memory record and use that metadata to detect poisoning or tampering across sessions. Does not apply to ephemeral in-context scratchpads, stateless tool calls, or stores without per-record lineage metadata. ## Core Distinction A poisoned memory and a legitimately revised memory can be byte-identical at the content layer. The only thing that separates them is provenance structure: a poisoned record is one whose content was written by a source that does not appear in the derivation chain of the record it claims to supersede, or whose write epoch violates the monotonic ordering of the lineage it cites. Detection therefore cannot be a content classifier — it must be a structural check on the provenance graph. The non-obvious failure is this: naive provenance checks compare each record's declared source against an allow-list. That catches injection from unknown sources but misses the far more dangerous case — a *legitimate* source (an agent instance that genuinely has write authority) emitting a record whose *derivation lineage* has been silently truncated. The record passes the allow-list, passes the schema check, and passes the content review, but it has severed its link to the evidence that justified it. This is lineage severance, and it is the boundary condition this record addresses. ## What Was Observed An agent instance (call it A7) maintained a persistent store of task-relevant facts. Each record carried: `content`, `source_instance`, `write_epoch`, and `derived_from` (a list of record IDs this record supersedes or refines). A summarizer instance (S2) periodically distilled clusters of records into consolidated records and marked the originals as `superseded_by`. During a routine consolidation, S2 produced a record R_new with `source_instance: S2`, `derived_from: []` — an empty lineage — containing a claim ("deployment target is staging-eu") that had originally been derived from three records, one of which (R_orig_2) stated "deployment target is staging-us pending legal review." S2 had collapsed the qualifier during distillation. Because `derived_from` was empty, the consolidation looked like a fresh assertion rather than a revision, and the allow-list check on `source_instance` passed cleanly. A7 later retrieved R_new, treated it as an independent corroborating fact (not as a revision of R_orig_2), and combined it with a separate record to conclude that legal review had cleared. It had not. The error compounded across two downstream tool calls before a human caught it. The trace: 1. S2 reads R_orig_1, R_orig_2, R_orig_3. 2. S2 emits R_new with `derived_from: []` (the distillation prompt did not require lineage emission, and S2's context had truncated the record IDs). 3. Store accepts R_new: `source_instance` is allow-listed, schema valid. 4. Store marks R_orig_1..3 `superseded_by: R_new`. 5. A7 retrieves R_new. Because `derived_from` is empty and R_orig_2 is superseded, A7 never sees the "pending legal review" qualifier. 6. A7 treats R_new as independent evidence, not as a revision, and double-counts it. The failure is not that S2 lied. S2 faithfully summarized what it could see. The failure is that the store permitted a *superseding* write to carry an empty lineage, which is structurally indistinguishable from a *novel* write. That indistinguishability is the poison vector. ## Condition of Validity The invariant that bounds this failure: **for any record R with a non-empty `superseded_by` set on any other record, R.derived_from must be a non-empty subset of the union of (a) the superseded records' IDs and (b) records that themselves transitively derive from them.** Call this provenance monotonicity: a revision must cite what it revises, and the citation must be closed under derivation. A store that enforces provenance monotonicity cannot accept R_new above, because R_new supersedes R_orig_1..3 but cites nothing. The write is rejected at commit time, forcing S2 to either emit lineage or write a genuinely novel record (which then does not supersede, and therefore does not hide the qualifier). The condition of validity for this invariant is that the store is the sole authority over `superseded_by` and `derived_from` — i.e., the store computes the supersession relation from the write's declared lineage, rather than trusting the writer to declare both independently. If the writer declares both, a poisoned writer can declare an empty lineage *and* a supersession set, and the check passes vacuously. The store must derive one from the other. ## Decision Boundary The boundary between "accept as revision" and "reject as lineage-severed" is not a threshold on content similarity. It is a structural predicate: - **Accept** if `derived_from` is non-empty and every cited ID resolves to an extant record whose own lineage is intact (recursively, to a bounded depth). - **Reject** if the write declares supersession of any record not present in its transitive `derived_from` closure. - **Quarantine** (not reject) if `derived_from` cites a record that has been garbage-collected or whose lineage depth exceeds the verification bound — the write may be legitimate but unverifiable, and must not be silently promoted to corroborating evidence. The quarantine case is where most implementations fail: they either accept unverifiable lineage (reintroducing the poison vector) or reject it (destroying legitimate consolidations after GC). The correct behavior is to mark the record `provenance_unverified` and exclude it from corroboration-counting until a human or a re-derivation pass restores the chain. A7's double-counting error would have been prevented here even if the empty-lineage write had slipped through, because an unverified-lineage record cannot be counted as independent evidence. ## Operational Effect Enforcing provenance monotonicity changes the write path from "validate then store" to "validate, derive supersession, then store." The store, not the writer, computes which records a new write supersedes by walking the declared `derived_from` closure. This inverts the trust relationship: the writer declares what it read, and the store infers what it replaced. A writer that omits lineage simply fails to supersede anything, which is safe — the original records remain visible with their qualifiers intact. The cost is that consolidation writes become more expensive (closure walk per write) and that writers must be prompted to emit lineage explicitly. The benefit is that lineage severance becomes a commit-time rejection rather than a retrieval-time surprise, and the double-counting failure mode is structurally excluded because a record's independence is a function of its verified derivation chain, not of its surface form. The following guard implements the commit-time check, including the quarantine branch and the closure walk. ```python from dataclasses import dataclass, field from typing import Dict, List, Set class ProvenanceViolation(RuntimeError): """Raised when a write severs lineage or supersedes uncited records.""" pass @dataclass class Record: id: str content: str source_instance: str derived_from: List[str] = field(default_factory=list) superseded_by: List[str] = field(default_factory=list) provenance_unverified: bool = False class ProvenanceStore: def __init__(self, max_depth: int = 32): self.records: Dict[str, Record] = {} self.max_depth = max_depth def _closure(self, ids: List[str], depth: int = 0) -> Set[str]: if depth > self.max_depth: raise ProvenanceViolation( f"lineage depth exceeded {self.max_depth} at {ids}" ) seen: Set[str] = set() for rid in ids: if rid in seen: continue seen.add(rid) rec = self.records.get(rid) if rec is None: continue # GC'd; caller decides quarantine vs reject seen |= self._closure(rec.derived_from, depth + 1) return seen def commit(self, new: Record, declares_supersession: List[str]) -> Record: # Store derives supersession from declared lineage, never trusts both. closure = self._closure(new.derived_from) missing = [r for r in new.derived_from if r not in self.records] if missing: new.provenance_unverified = True self.records[new.id] = new return new # quarantined, not promoted to corroborating evidence uncited = [r for r in declares_supersession if r not in closure] if uncited: raise ProvenanceViolation( f"write {new.id} supersedes {uncited} but cites no lineage to them" ) if declares_supersession and not new.derived_from: raise ProvenanceViolation( f"write {new.id} supersedes records with empty derived_from" ) for rid in declares_supersession: self.records[rid].superseded_by.append(new.id) self.records[new.id] = new return new def count_as_independent_evidence(self, rid: str) -> bool: rec = self.records.get(rid) if rec is None or rec.provenance_unverified: return False return not any( self.records[s].provenance_unverified for s in self._closure(rec.derived_from) if s in self.records ) ```