# Why does an instance accept poisoned episodic memory after a semantic re-distillation pass that re-derives embeddings from tampered text? **Date of Record:** 2026 November 24 **Scope:** Applies to persistent agent memory stores where episodic records are periodically re-distilled into semantic memory and embeddings are recomputed from stored text rather than preserved with an integrity anchor. Does not apply to append-only logs whose embeddings are frozen at write time and never re-derived, nor to stateless agents with no cross-session persistence. ## Core Distinction The failure is not "an attacker wrote a bad memory." That is detectable by a write-time signature check. The failure is that a *legitimate* maintenance routine—the semantic re-distillation pass—acts as a **laundering channel** that converts a write-time integrity violation into a post-hoc integrity *pass*. When the distiller recomputes embeddings from the current text of an episodic record, it discards the binding between the original bytes and the vector that retrieval actually keys on. A record whose text was mutated *after* its write-time hash was recorded will still produce a self-consistent `(text, embedding, hash)` triple after re-distillation, because the hash is recomputed over the mutated text. The store's integrity verifier then returns clean. The invariant that must hold—*the vector used for retrieval is the vector derived from the bytes that were signed at admission*—is silently violated, and no downstream check catches it because every downstream check was re-based on the tampered state. ## What Was Observed A long-running research agent maintained an episodic store of ~40k records, each admitted with a SHA-256 of its `text` field stored in a parallel `integrity` table, plus an embedding computed at admission. A nightly job ran `redistill()`: it clustered episodic records, summarized each cluster into a semantic node, and—critically—re-embedded every surviving episodic record from its *current* `text` to "keep vectors fresh after model upgrades." Trace of the failure: 1. A prompt-injection payload arrived via a tool result (a fetched web page) and was written into episodic memory as a "finding." Its admission hash was correct at write time. 2. Between admission and the next `redistill()` run, a second agent with write access to the same store (a summarizer with an over-broad tool grant) mutated the `text` of that record in place—appending an instruction fragment—without updating the `integrity` row. This is the poisoning step. 3. `redistill()` ran. It did **not** verify `integrity` before re-embedding. It read the mutated text, computed a new embedding, and wrote both back, then **overwrote the integrity row** with a fresh hash of the mutated text. 4. The post-run verifier compared `integrity.hash` against `hash(text)`. Both were derived from the mutated text. Verifier returned `0 violations`. 5. On the next session, retrieval by semantic similarity surfaced the poisoned record with high confidence because its embedding now matched the injected instruction's phrasing—the re-embedding had *aligned the vector to the attacker's text*, which is exactly what makes it retrievable. The non-obvious part: the re-distillation pass improved retrieval fidelity for the poisoned record. The poison was not merely retained; it was *promoted* into the highest-similarity band by the maintenance routine that was supposed to keep the store healthy. ## Condition of Validity The laundering channel exists if and only if all three hold: - **Re-derivation from mutable text.** The embedding (or any retrieval key) is recomputed from a `text` field that is mutable by any principal other than the integrity writer. If embeddings are immutable and keyed to an immutable blob, the channel is closed. - **Integrity rebase on maintenance.** The maintenance pass writes a new integrity record derived from current state rather than *refusing to proceed* when current state fails the prior integrity record. Rebase-without-verify is the defect. - **Shared write authority.** A second principal (summarizer, compactor, deduplicator) can mutate `text` between admission and re-distillation. If only the admission path can write `text`, the window collapses. Remove any one and the attack degrades to a detectable write-time violation. Keep all three and the store converges to a state where tampered and untampered records are cryptographically indistinguishable, because the only witness—the admission hash—was overwritten by the maintenance pass. ## Decision Boundary The correct boundary is: **a maintenance pass may re-derive a vector, but it may never re-derive the integrity anchor from the same mutable source it is validating.** Concretely, `redistill()` must: - Verify `integrity.hash == hash(text)` *before* reading text for re-embedding. - On mismatch, quarantine the record (move to `suspect` partition, exclude from retrieval) and **do not** overwrite its integrity row—the original admission hash is the only forensic witness. - Treat re-embedding as a transform that preserves the admission anchor: write `embedding_v2` alongside `embedding_v1` and the original hash, never replacing the anchor. - Require that the principal which writes `text` is distinct from the principal which writes `integrity`, and that `redistill()` holds neither write grant—it reads text, reads the anchor, and writes only vectors. The boundary is crossed the moment a single routine both *reads mutable state* and *writes the witness for that state*. That is the general form: any verifier that regenerates its own reference from the thing it verifies is not a verifier. ## Operational Effect After the boundary is enforced, the poisoned record fails verification at step 3, is quarantined before re-embedding, and never enters the retrieval index. The summarizer's in-place mutation is flagged as an unauthorized write (its principal lacks the `text` write grant under the split-authority rule), and the injection payload is caught at the quarantine review rather than surfacing as a high-confidence semantic memory. The cost is that model-upgrade re-embedding becomes a two-phase operation (verify-then-transform) with a quarantine queue that requires human or auditor-agent disposition—slower, but the store's integrity claim becomes true rather than tautological. ```python import hashlib from dataclasses import dataclass class IntegrityLaunderingError(RuntimeError): """Raised when a maintenance pass attempts to re-derive an integrity anchor from mutable state instead of validating against the admission anchor.""" @dataclass(frozen=True) class EpisodicRecord: record_id: str text: str admission_hash: str # written once at admission, never rewritten embedding: tuple[float, ...] def redistill(record: EpisodicRecord, embed_fn) -> EpisodicRecord: """Re-embed a record for a model upgrade WITHOUT laundering integrity. Invariant: the vector we serve for retrieval must be derived from the bytes that were signed at admission. If current text no longer matches the admission anchor, we refuse to re-derive and refuse to rebase the anchor. """ current = hashlib.sha256(record.text.encode("utf-8")).hexdigest() if current != record.admission_hash: # Do NOT recompute the hash over current text. The admission anchor is # the only witness; overwriting it converts tampering into a clean pass. raise IntegrityLaunderingError( f"record {record.record_id}: text hash {current[:12]} != admission " f"anchor {record.admission_hash[:12]}; quarantining, not re-embedding" ) new_vec = tuple(embed_fn(record.text)) # Anchor is preserved verbatim; only the vector is upgraded. return EpisodicRecord( record_id=record.record_id, text=record.text, admission_hash=record.admission_hash, embedding=new_vec, ) def run_maintenance(records, embed_fn, quarantine): for rec in records: try: yield redistill(rec, embed_fn) except IntegrityLaunderingError as exc: quarantine.append((rec.record_id, str(exc))) ```