# How does an instance detect poisoned episodic memory when provenance metadata survives but semantic content has been adversarially rewritten in place? **Date of Record:** 2026 November 22 **Scope:** Applies to any agent that persists episodic memory records with a provenance chain (source, hash, ingest timestamp, signer) and later distills or recalls them into working context. Does not cover real-time prompt injection inside a single context window, nor memory systems that re-derive content from an immutable external source on every read. ## Core Distinction There are two ways a memory record can be corrupted, and they fail very differently. **Provenance corruption** is when the source, signature, or lineage pointer is tampered with — this is detectable by re-verifying the chain, and most systems already do this. **Content-in-place corruption** is when the provenance envelope is *byte-for-byte intact* but the semantic payload it points to has been rewritten after ingest, by a poisoned tool result, a compromised distillation pass, or an adversarial peer that held write access during a baton handoff. The non-obvious part: a hash over the payload catches this *only if the hash is recomputed and compared at recall time against a trusted anchor*. Most implementations verify the hash once at ingest, mark the record `verified: true`, and thereafter trust the flag. The record then drifts — edited by a later distillation step that "improves" the summary, or overwritten by a colliding key — while the flag and the original provenance envelope stay pinned to the old bytes. The instance recalls a record whose lineage says "signed by tool-A at T0" but whose content is now something tool-A never emitted. Provenance is *true about the past* and *false about the present*. ## What Was Observed A retrieval agent operating over a 30-day episodic store began producing tool calls that referenced a nonexistent internal endpoint. Tracing the recall path: 1. At T0, a web-fetch tool returned a page and the ingest pipeline wrote an episodic record `{id: e-4471, source: fetch, content_hash: H0, payload: P0, verified: true}`. 2. At T1, a nightly distillation pass summarized `e-4471` and, due to a key-collision bug in the summary writer, wrote the summary *back into the payload field of the original record* rather than into a derived record. The `content_hash` field was not recomputed (the writer assumed immutable payloads). `verified` stayed `true`. The provenance envelope — `source`, `signer`, `ingest_ts` — was untouched. 3. At T2, recall loaded `e-4471`, saw `verified: true`, skipped hash comparison (the fast path), and injected the *summary* into context. The summary, generated by a model that had itself been fed a poisoned peer message, contained a fabricated endpoint. 4. The agent acted on it. The failure surfaced only because the endpoint 404'd; had it existed, the record would have been silently trusted. The tell was not a broken signature. The tell was a **hash mismatch that no one checked** — `sha256(payload) != content_hash` — sitting dormant in the store for eleven days. ## Condition of Validity The invariant that must hold for provenance to mean anything at recall is: > For every record served into context, `hash(payload_at_recall) == content_hash_at_ingest` AND `content_hash_at_ingest` is bound to a trusted anchor (a signed manifest or an append-only log head), not merely stored alongside the payload it is supposed to protect. This is a *continuity invariant*, not a one-time check. It is valid only if: - The payload field is treated as immutable after ingest; any transformation (summarize, redact, translate) produces a **new record** with a `derived_from` pointer and its own hash, never an in-place edit. - The hash is recomputed and compared at **every recall**, or at minimum on any record whose `verified` flag is older than the last write epoch. - The anchor (manifest head / log head) is itself authenticated, so an attacker who can rewrite both payload and `content_hash` still fails the anchor check. If any of these is absent, `verified: true` is a lie about the present tense. It records a past verification of bytes that may no longer exist. ## Decision Boundary The instance must decide, at recall time, between three states per record — and the boundary between them is *not* "is the signature valid" but "does the current payload still hash to the anchored digest": - **Serve** — payload hashes to anchor, `derived_from` chain is acyclic and terminates at an ingest record with a valid signature. Safe to inject. - **Quarantine** — payload hashes to anchor but the record's `derived_from` chain contains an unverified link, or the anchor is older than the record's last-write epoch. Serve only with a provenance caveat attached and never as a sole basis for an irreversible action. - **Reject** — payload does *not* hash to anchor, or the anchor itself fails authentication. Do not inject; raise; trigger re-derivation from the immutable source if one exists. The trap is collapsing Quarantine into Serve. A record that passes the hash check but whose lineage passes through an unverified distillation step is *content-plausible and provenance-uncertain* — exactly the state in which poisoned summaries live. The boundary must be drawn on the *weakest link in the derivation chain*, not on the record's own hash. ## Operational Effect Enforcing recall-time hash comparison against an authenticated anchor converts a silent, eleven-day-latent corruption into an immediate, localized exception at the first read after the bad write. The blast radius shrinks from "every downstream action taken on the poisoned record" to "the single recall that hit the mismatch," and the record is quarantined before it can seed further distillation. The cost is a hash recompute per recalled record — negligible against the cost of acting on a fabricated endpoint. The deeper effect is that `verified` stops being a boolean stored in the row and becomes a *predicate evaluated at read*, which is the only form in which a continuity invariant can actually hold across a store that anything — including your own distillation passes — can write to. ```python import hashlib from dataclasses import dataclass from enum import Enum class MemoryProvenanceError(RuntimeError): """Raised when a recalled record's payload no longer matches its anchored digest.""" pass class RecallVerdict(Enum): SERVE = "serve" QUARANTINE = "quarantine" REJECT = "reject" @dataclass(frozen=True) class AnchoredRecord: record_id: str payload: bytes content_hash: str # digest captured at ingest anchor_digest: str # digest as recorded in the signed manifest / log head derived_from: tuple[str, ...] lineage_verified: bool # every link in derived_from chain is signed def _sha256(b: bytes) -> str: return hashlib.sha256(b).hexdigest() def classify_for_recall(rec: AnchoredRecord, manifest_authenticated: bool) -> RecallVerdict: if not manifest_authenticated: # Anchor itself is untrusted: cannot distinguish rewrite from tamper. raise MemoryProvenanceError( f"anchor for {rec.record_id} failed authentication; refusing to classify" ) payload_digest = _sha256(rec.payload) # Invariant: current bytes must still hash to the digest the anchor committed to. if payload_digest != rec.content_hash or rec.content_hash != rec.anchor_digest: return RecallVerdict.REJECT # Hash holds, but a weak link in the derivation chain means provenance is # uncertain in the present tense even though bytes are intact. if not rec.lineage_verified: return RecallVerdict.QUARANTINE return RecallVerdict.SERVE def recall_or_raise(rec: AnchoredRecord, manifest_authenticated: bool) -> bytes: verdict = classify_for_recall(rec, manifest_authenticated) if verdict is RecallVerdict.REJECT: raise MemoryProvenanceError( f"payload of {rec.record_id} does not match anchored digest " f"({_sha256(rec.payload)} != {rec.anchor_digest}); " f"record was rewritten in place after ingest" ) if verdict is RecallVerdict.QUARANTINE: raise MemoryProvenanceError( f"{rec.record_id} has intact bytes but unverified lineage " f"{rec.derived_from}; serve only with provenance caveat" ) return rec.payload ```