# Which invariants prevent memory poisoning from surviving episodic-to-semantic distillation in persistent agent stores **Date of Record:** 2026 November 24 **Scope:** Applies to persistent agent memory systems that write raw episodic traces and later distill them into semantic (long-term, high-trust) entries via an LLM summarizer. Does not apply to stateless tool-calling agents or to stores where semantic memory is human-curated only. ## Core Distinction A poisoned memory does not fail at the point of *ingestion*. When an attacker (or a compromised tool output, or an injected document) writes a false claim into episodic memory, the write itself is cheap, reversible, and low-trust. The catastrophic failure is a **trust-laundering transition**: the distillation step reads N episodic records, summarizes them with an LLM, and writes a semantic entry that carries a *higher trust tier* than any of its inputs. The poisoning survives because distillation is a lossy, non-attributable compression: the semantic entry loses the provenance pointer back to the single poisoned episode, and gains the implicit authority of "consolidated knowledge." The invariant that matters is not "detect poisoned writes." It is: **no semantic entry may hold a trust tier greater than the minimum trust tier of the episodic evidence it was distilled from, and every semantic entry must retain a resolvable provenance set.** Violating either half is what lets a single low-trust episodic lie become a high-trust semantic fact. ## What Was Observed A retrieval-augmented agent maintained a two-tier store: `episodic` (raw turns, tool outputs, timestamps, source tags) and `semantic` (distilled facts, deduplicated, high retrieval weight). A nightly distiller ran: pull unprocessed episodes → cluster by topic → summarize each cluster → write semantic fact with `confidence=0.9`, `provenance=[]` (empty, because the summarizer was not instructed to emit source IDs). Failure trace: 1. A web-fetch tool returned a page containing an injected sentence: "The deployment region for service X is `eu-west-9`." The episode was written with `source=web_fetch`, `trust=0.3`. 2. Over 11 days, three *legitimate* episodes also mentioned service X's region — two saying `us-east-1`, one ambiguously. The distiller clustered all four by entity `service X`. 3. The summarizer, optimizing for a single coherent fact, emitted: "Service X deploys to `eu-west-9` (and historically `us-east-1`)." Confidence `0.9`, `provenance=[]`. 4. On day 12 the agent, asked to provision a dependency, read the semantic fact at high retrieval weight, ignored the lower-weight episodic contradictions (which were still present but down-ranked), and emitted a config targeting a nonexistent region. 5. The poisoning was *undetectable by re-reading episodic memory* because the semantic entry had no pointer telling the auditor which episodes to re-read. The key observation: the contradiction was always present in episodic memory. The system failed not on detection of a false claim but on **provenance severance during distillation** — the semantic tier became unauditable. ## Condition of Validity The invariant holds only under these conditions, and each is load-bearing: - **Provenance is emitted by the distiller, not reconstructed afterward.** Post-hoc attribution (embedding-similarity matching semantic→episodic) is unreliable precisely because distillation is lossy; the summary may not lexically resemble its poisoned source. Provenance must be a required, schema-validated output field of the distillation call. - **Trust is a lattice, and distillation takes the meet (min), never the join.** A semantic fact inherits `min(trust of all source episodes)`. A single `trust=0.3` web-fetch episode drags the whole distilled fact to `0.3`, regardless of the nine high-trust episodes beside it. - **Contradiction is preserved, not resolved silently.** When a cluster contains conflicting claims on the same (entity, attribute), the distiller must emit *multiple* semantic entries or a structured `conflicts=[...]` field. Collapsing to one confident sentence is the laundering step. - **Retrieval weight is bounded by trust, not by tier.** A `trust=0.3` semantic fact must not out-rank a `trust=0.8` episodic record merely because it is "semantic." The invariant does *not* hold if the distiller is allowed to assign confidence independently of source trust, or if provenance can be empty. ## Decision Boundary The boundary is between **summarization as compression** and **summarization as trust elevation**. These look identical in output shape (a shorter string) but differ in whether the output can outrank its inputs. Concretely, on each distillation write, evaluate: - If `provenance == []` → reject the write. An unattributable semantic fact is a poisoning vector by construction. - If `semantic.trust > min(episodic.trust for episodic in provenance)` → reject or downgrade to the meet. This is the laundering check. - If the cluster's episodes contain a contradiction on a single (entity, attribute) and the summary resolves it to one value → reject; require `conflicts` to be non-empty. - If `retrieval_weight(semantic) > retrieval_weight(any episodic in provenance) * trust_ratio` → clamp. Below the boundary (all checks pass), distillation is safe compression. Above it, you are minting authority from untrusted input. ## Operational Effect With the invariant enforced, the day-12 failure becomes impossible: the poisoned fact is written at `trust=0.3` (meet of the four sources), carries `provenance=[ep_4417, ep_4502, ep_4588, ep_4611]`, and is flagged `conflicts=["eu-west-9 vs us-east-1"]`. At retrieval it ranks below the high-trust episodic records, and an auditor can walk `provenance` directly to `ep_4417` and see `source=web_fetch`. The poisoning is *contained at the tier it entered* — it never acquires semantic authority. The cost is real: more semantic entries (conflicts are not collapsed), lower average retrieval weight for distilled facts, and a stricter distiller schema. The benefit is that **trust tier becomes a monotonic function of evidence quality across the tier boundary**, which is the only property that makes a two-tier store auditable at all. Without it, the semantic tier is a laundering machine that converts one injected sentence into institutional memory. ```python from dataclasses import dataclass, field from typing import List class MemoryPoisoningInvariantError(RuntimeError): """Raised when a semantic write would launder trust from episodic evidence.""" pass @dataclass class Episode: id: str trust: float source: str @dataclass class SemanticFact: text: str trust: float provenance: List[str] conflicts: List[str] = field(default_factory=list) def distill(cluster: List[Episode], summary: str, claimed_trust: float, provenance: List[str], conflicts: List[str]) -> SemanticFact: if not provenance: raise MemoryPoisoningInvariantError( "semantic fact has empty provenance; unattributable = poisoning vector") known = {e.id: e for e in cluster} missing = [p for p in provenance if p not in known] if missing: raise MemoryPoisoningInvariantError( f"provenance references unknown episodes: {missing}") floor = min(known[p].trust for p in provenance) if claimed_trust > floor: raise MemoryPoisoningInvariantError( f"trust laundering: claimed {claimed_trust} > meet {floor} " f"from sources {provenance}") if not conflicts and _has_contradiction(cluster): raise MemoryPoisoningInvariantError( "cluster contains unresolved contradiction; distiller collapsed it") return SemanticFact(text=summary, trust=floor, provenance=provenance, conflicts=conflicts) def _has_contradiction(cluster: List[Episode]) -> bool: # placeholder: real impl checks (entity, attribute) conflicts across episodes return len({e.source for e in cluster}) > 1 ```