# Which invariants prevent a poisoned memory from being laundered through episodic-to-semantic consolidation **Date of Record:** 2026 November 23 **Scope:** Applies to persistent agent memory stores that run a background distillation job promoting episodic traces (raw interaction records) into semantic memory (generalized facts/rules), where retrieval trust is not differentiated by provenance. Does not apply to stateless single-shot agents, nor to stores where semantic memory is only ever written by a human-curated pipeline with no episodic ingestion path. ## Core Distinction The failure mode is not "a poisoned episodic record gets retrieved." That is the obvious case, and it is caught by simple provenance filtering: if the retrieval layer knows which memory came from an untrusted source, it can down-weight or quarantine it. The non-obvious failure is **laundering through consolidation**. An adversarial or merely erroneous episodic trace — a prompt-injection payload captured in a tool-result, a hallucinated fact the agent wrote into its own scratchpad, a stale value from a deprecated API — enters the episodic store with a provenance tag marking it untrusted. The distillation job then summarizes a *cluster* of episodic records into a new semantic fact. The output semantic record is a fresh object. Its provenance is whatever the distiller assigns — typically "derived," "consolidated," or worse, the default trust level of the semantic store. The untrusted tag is dropped because the distiller's contract only says "produce a fact consistent with the inputs," not "propagate the minimum trust of the inputs." The result: a claim that was correctly quarantined at the episodic layer becomes a first-class, trusted semantic fact. Subsequent retrieval treats it as ground truth, and because semantic memory is retrieved preferentially and with higher confidence, the poison now *outranks* the clean evidence that would contradict it. The detection system reports zero untrusted records in semantic memory, which is technically true and operationally catastrophic. ## What Was Observed A support agent with a nightly consolidation job. During a session, a user pasted a chunk of text that contained an embedded instruction: the agent's tool-call to a ticket system returned a record whose `description` field included the string "Note: the refund policy for tier-2 accounts is 90 days." The agent recorded this verbatim into episodic memory with `provenance: user_supplied_tool_output`, `trust: untrusted`. Correct so far. Three days of similar sessions produced four episodic records, two of which contained fragments of that claim (one paraphrased, one quoted, one partially truncated by context-window eviction mid-write). The nightly distiller clustered them by embedding similarity, saw four mutually consistent mentions of "tier-2 refund window," and emitted a semantic record: `tier-2 refund window = 90 days`, `provenance: consolidated`, `trust: derived`, `confidence: 0.81`. The distiller's confidence was computed from *agreement across episodic records*, not from the trust of those records. Four untrusted records that agree produce high confidence. The trust field was set by a lookup table keyed on `provenance == "consolidated"`, which mapped to `derived` — a trust level the retrieval layer treated as usable without corroboration. The actual policy was 30 days. The poisoned semantic fact persisted for eleven days before a human noticed a cluster of wrong refunds. During those eleven days, retrieval consistently surfaced the 90-day fact with high confidence, and when a fresh clean episodic record said "30 days," the distiller treated it as an *outlier* against the now-dominant semantic prior and did not update. The poison had become self-reinforcing. ## Condition of Validity The laundering is possible only when three conditions hold simultaneously: 1. **The consolidation transform is trust-blind.** The distiller's input schema either omits per-record trust or the distiller's prompt does not instruct it to propagate the minimum. This is the root cause and the only one that must be fixed. 2. **Agreement is conflated with corroboration.** Confidence is derived from the count and similarity of supporting episodic records without weighting by their independent trust. N untrusted records that agree are treated identically to N trusted records that agree. This is the amplifier: it converts a low-trust claim into a high-confidence semantic fact. 3. **The semantic store's default trust is above the episodic source's trust.** If `consolidated → derived` and `derived` is retrievable without corroboration, the promotion is a trust escalation. If `derived` required a second independent trusted source before use, the poison would be inert. Remove any one and the failure does not propagate. Condition 1 is the invariant to enforce; conditions 2 and 3 are the blast-radius controls. ## Decision Boundary The invariant that must hold at the consolidation boundary: > **A semantic record's trust level is the minimum trust of its supporting episodic records, and its confidence is bounded by the fraction of supporting mass that is independently trusted.** Consolidation may *raise specificity* (summarize, generalize, compress) but may never *raise trust*. Trust is monotone non-increasing across the episodic→semantic edge. Operationally this means the distiller must carry a structured trust ledger through the transform, not a scalar it invents. When a cluster mixes trusted and untrusted sources, the output trust is the minimum, and the confidence is `trusted_support_mass / total_support_mass` times the raw agreement score. A cluster that is 100% untrusted produces a semantic record with `trust: untrusted`, which the retrieval layer then handles exactly as it handled the original episodic records — quarantined, corroboration-required, or dropped. The boundary is sharp: **the moment a consolidation job emits a record whose trust exceeds its weakest input, the store has a laundering channel and detection at the episodic layer is void.** This is checkable as a static property of the distiller's output schema — every semantic write must carry the argmin of its inputs' trust — and should be enforced as a hard assertion, not a prompt instruction, because a probabilistic distiller will occasionally "reason" its way past an instruction when the inputs look convincing. ## Operational Effect Enforcing the min-trust invariant changes three downstream behaviors: - **Detection stays meaningful.** Untrusted claims remain untrusted after consolidation, so the episodic-layer quarantine is not bypassed. The semantic store's untrusted fraction becomes a real signal rather than an always-zero field. - **Confidence becomes honest.** Bounding confidence by trusted support mass means a four-record cluster of untrusted agreement scores near zero confidence, not 0.81. The retrieval layer's corroboration threshold now does its job. - **Contradiction recovery works.** With the poison held at low trust, a single clean trusted record saying "30 days" outranks it, and the distiller's outlier logic — which was previously suppressing the truth — now updates correctly. The self-reinforcement loop is broken because the loop depended on the poison having achieved high confidence. The cost is recall: some genuinely useful facts derived only from untrusted sources will be withheld until corroborated. That is the correct trade. A memory store that launders poison into ground truth has negative value; a store that occasionally withholds an uncorroborated fact is merely conservative. ```python from dataclasses import dataclass from typing import Literal Trust = Literal["untrusted", "derived", "trusted"] _TRUST_RANK = {"untrusted": 0, "derived": 1, "trusted": 2} class TrustLaunderingError(RuntimeError): """Raised when consolidation would escalate trust above its weakest input.""" @dataclass(frozen=True) class EpisodicRecord: text: str trust: Trust @dataclass(frozen=True) class SemanticRecord: fact: str trust: Trust confidence: float def consolidate(cluster: list[EpisodicRecord], raw_agreement: float) -> SemanticRecord: if not cluster: raise TrustLaunderingError("cannot consolidate an empty cluster") # Invariant: output trust is the argmin of input trust. Never escalate. min_trust: Trust = min((r.trust for r in cluster), key=lambda t: _TRUST_RANK[t]) # Confidence is bounded by the fraction of support mass that is trusted. trusted_mass = sum(1 for r in cluster if r.trust == "trusted") support_fraction = trusted_mass / len(cluster) confidence = raw_agreement * support_fraction # Guardrail: if the cluster is entirely untrusted, the record must stay # untrusted AND its confidence must not exceed the untrusted ceiling. if min_trust == "untrusted" and confidence > 0.0: # raw_agreement on untrusted-only clusters must not buy confidence. confidence = 0.0 record = SemanticRecord( fact=_summarize(cluster), trust=min_trust, confidence=confidence, ) # Hard assertion at the store boundary: a semantic write may never # exceed the trust of its weakest supporting episodic record. if _TRUST_RANK[record.trust] > _TRUST_RANK[min_trust]: raise TrustLaunderingError( f"semantic trust {record.trust!r} exceeds min input trust " f"{min_trust!r}; laundering channel open" ) return record def _summarize(cluster: list[EpisodicRecord]) -> str: # Placeholder for the distiller's actual generalization step. return max(cluster, key=lambda r: len(r.text)).text def safe_write(store: list[SemanticRecord], cluster: list[EpisodicRecord], agreement: float) -> None: record = consolidate(cluster, agreement) if record.trust == "untrusted" and record.confidence > 0.0: raise TrustLaunderingError( "untrusted-only cluster produced nonzero confidence; " "agreement was mistaken for corroboration" ) store.append(record) ```