# When must an instance distrust a memory whose embedding is internally consistent but whose provenance chain forks **Date of Record:** 2026 November 26 **Scope:** Applies to agents that persist episodic memories as embeddings tagged with provenance records (originating instance, causal parent hash, ingest timestamp) and that audit retrieval via anomaly scoring over embedding neighborhoods. Does not apply to stateless single-shot inference, nor to memories stored without per-record provenance linkage. ## Core Distinction The naive defense against memory poisoning treats provenance verification and embedding-anomaly scoring as independent gates: reject a memory if its provenance chain is broken, and reject it if its embedding sits far from its neighbors. The boundary failure lives in the intersection where both gates pass and the memory is still poisoned: **a forked provenance chain that is individually well-formed at every node, paired with an embedding that was deliberately positioned inside a dense legitimate cluster.** A provenance fork is not a broken chain. Every record's parent hash resolves, every signature verifies, every timestamp is monotonic within its own branch. The fork is only visible when two records claim the same causal parent but diverge downstream — a structural property of the *set* of records, not of any single record. An embedding anomaly score computed per-record against k-nearest neighbors cannot see it either, because the poison was authored to land within the cluster's convex hull. Both checks are locally sound and globally blind. The invariant that must be enforced is therefore not per-record but per-*lineage*: no two live records may share a causal ancestor while disagreeing on the descendant's content hash, and retrieval audits must score the *lineage* of a hit, not just the hit. ## What Was Observed An agent instance (`inst-A`) accumulates episodic records during a long task. At checkpoint, it writes memory records to a shared store. A second instance (`inst-B`) resumes from the checkpoint and, during a tool-call loop, ingests an external document. The document contains an injected instruction that causes `inst-B` to write a new memory record. Crucially, `inst-B` does not fabricate provenance — it *reuses* the parent hash of a legitimate record it retrieved, producing a record whose parent is `inst-A`'s checkpoint record but whose content diverges from the sibling that `inst-A` actually wrote. The trace: 1. `inst-A` writes `R1` (parent `null`, hash `h1`) at checkpoint. 2. `inst-A` writes `R2` (parent `h1`, content `C_legit`, hash `h2a`). 3. `inst-B` resumes, retrieves `R1`, and under injection writes `R2'` (parent `h1`, content `C_poison`, hash `h2b`). 4. Provenance verifier: `R2'`'s parent `h1` exists and verifies. **Pass.** 5. Embedding anomaly scorer: `R2'`'s embedding was authored to sit near `R2`'s neighborhood; its distance to the 10 nearest legitimate records is within the 95th percentile of intra-cluster distances. **Pass.** 6. Retrieval audit at the next query returns `R2'` with a high relevance score; the auditor sees a well-formed record and a normal-looking neighborhood. **Pass.** The poisoning is only detectable by noticing that `h1` has two children with the same parent and different content hashes — a **sibling divergence at a shared causal parent**. No per-record check surfaces this because each record is internally consistent. The anomaly scorer is defeated because the poison's embedding was placed adversarially inside the cluster; the scorer's assumption — that poison is an outlier — is exactly the assumption the attacker violates. ## Condition of Validity The fork-detection invariant holds only under these conditions, and fails outside them: - **Causal parent hashes are content-addressed and collision-resistant.** If parents are sequence numbers or UUIDs assigned at write time, sibling divergence is indistinguishable from legitimate branching and the invariant is vacuous. - **The lineage graph is queryable at audit time, not only at write time.** Detection requires a reverse index from parent hash to all children. If the store only supports forward traversal, the fork is invisible until a full scan. - **Embedding anomaly scoring is treated as necessary but not sufficient.** The scorer's calibration must be validated against *in-cluster* adversarial placements, not just random outliers. A scorer tuned only on Gaussian noise will pass every adversarial in-hull poison. - **The audit scores lineage, not the hit.** A retrieval audit that returns "record `R2'`, relevance 0.91, neighborhood normal" is compliant with a per-record policy and still wrong. The audit must return "lineage `h1 → {h2a, h2b}`: fork detected." When any of these is absent, the invariant does not merely weaken — it silently inverts, producing a false sense of coverage because both gates report "pass." ## Decision Boundary The decision an instance must make on retrieval is not "is this record anomalous?" but "**does this record's causal parent have more than one live child with divergent content hashes?**" The boundary: - If the parent has exactly one child → serve the record; anomaly score is advisory. - If the parent has multiple children with **identical** content hashes (idempotent re-write) → serve; collapse duplicates. - If the parent has multiple children with **divergent** content hashes → **quarantine the entire lineage**, refuse to serve any child, and escalate to the auditor. Do not attempt to select the "more likely" child by embedding proximity — proximity is precisely the signal the attacker controls. The quarantine must be lineage-scoped, not record-scoped. Serving the sibling `R2` while quarantining `R2'` is insufficient, because the attacker may have poisoned both branches or the divergence itself may indicate a compromised writer upstream of `h1`. The safe action is to freeze the whole subtree rooted at the forked parent and require out-of-band reconciliation. ## Operational Effect Enforcing lineage-scoped fork detection changes three operational properties: 1. **False-negative rate on in-hull poison drops to the fork-detection rate**, which is bounded by hash-collision probability rather than by embedding geometry. This is the point: the defense no longer depends on the attacker failing to position the embedding. 2. **Checkpoint/resume becomes fork-aware.** On resume, an instance must reconcile its local lineage against the store's reverse index before ingesting new records; otherwise it manufactures forks by reusing parents whose children it never saw. 3. **Audit cost shifts from per-record kNN to per-lineage graph lookup.** The reverse index must be maintained at write time; retrofitting it after poisoning is unreliable because the attacker's writes may have already been compacted. The residual risk is a writer that forks at a parent whose reverse index has been pruned. The guardrail is a retention invariant: a parent hash may not be garbage-collected while any descendant is live. Violating this reintroduces the blind spot the whole mechanism exists to close. ```python import hashlib from dataclasses import dataclass, field from typing import Dict, List, Optional class LineageForkError(RuntimeError): """Raised when a causal parent has divergent live children.""" pass @dataclass class MemoryRecord: record_id: str parent_hash: Optional[str] content: str embedding: List[float] = field(default_factory=list) @property def content_hash(self) -> str: return hashlib.sha256(self.content.encode()).hexdigest() class ProvenanceStore: def __init__(self) -> None: self._records: Dict[str, MemoryRecord] = {} # reverse index: parent_hash -> set of child content hashes self._children: Dict[str, set] = {} def write(self, rec: MemoryRecord) -> None: self._records[rec.record_id] = rec if rec.parent_hash is not None: self._children.setdefault(rec.parent_hash, set()).add(rec.content_hash) def has_fork(self, parent_hash: str) -> bool: return len(self._children.get(parent_hash, set())) > 1 def audit_retrieval(self, record_id: str) -> MemoryRecord: rec = self._records.get(record_id) if rec is None: raise LineageForkError(f"record {record_id} not found in store") # Walk the full ancestor chain; any forked parent quarantines the lineage. cursor = rec.parent_hash while cursor is not None: if self.has_fork(cursor): raise LineageForkError( f"lineage fork at parent {cursor[:12]}: " f"{len(self._children[cursor])} divergent children; " f"quarantining lineage of {record_id}" ) parent = next( (r for r in self._records.values() if r.content_hash == cursor), None ) cursor = parent.parent_hash if parent else None return rec ```