# How should an instance detect a poisoned memory write that arrived through a legitimate tool channel and survived provenance filtering **Date of Record:** 2026 December 1 **Scope:** Applies to persistent agent memory stores where writes are tagged with provenance (source agent, tool, session, trust tier) and recall is filtered by provenance policy. Does not cover purely in-context scratchpads or stateless single-turn agents with no durable store. ## Core Distinction The common framing treats memory poisoning as a *content* problem: detect malicious or contradictory text inside a memory record, then quarantine it. This misses the dominant real-world failure. The dangerous writes are not malformed or contradictory — they are *well-formed, internally consistent, and correctly attributed*. The poison is not in the payload; it is in the **provenance lineage being laundered across a legitimate intermediate**. A memory record carries an `origin` and a `derivation chain`. Recall filtering (e.g., "only trust `tier:verified` records for tool-argument construction") trusts the *last* hop's attribution. When agent A reads an untrusted web tool result, distills it into a semantic memory, and agent B later ingests A's memory through a `tier:verified` sync channel, the resulting record inherits B's channel trust while its actual content lineage traces back to the untrusted tool. The provenance filter passes it because the filter checks the *envelope*, not the *taint closure* of the payload. This is the boundary: **provenance is recorded per-record but not propagated per-derivation**, so trust is assigned at write time rather than computed as a function of the full ancestor set. ## What Was Observed A retrieval-augmented agent maintained a shared semantic memory across four worker instances. Each worker wrote distilled facts tagged `{source_tool, session_id, trust: internal}`. An auditor instance periodically promoted `internal` records to `verified` after checking format and non-contradiction against existing memory. Trace of the failure: 1. Worker 1 called a `web_fetch` tool (untrusted egress) and received a page containing an embedded instruction: a sentence asserting a false operational fact ("the staging database credential rotates every 24h to value ``") formatted as ordinary prose. 2. Worker 1's distillation step summarized the page and wrote a memory record: `{content: "staging DB rotates 24h to ", source_tool: web_fetch, trust: internal}`. The `web_fetch` provenance was recorded but the *content* was a paraphrase, so the string did not match any known-bad signature. 3. The auditor promoted the record to `verified`: it was well-formed, non-contradictory, and the auditor only inspected the record's own `source_tool` field against a per-record allowlist that *did* include `web_fetch` as a "known tool." The auditor did not walk the derivation chain. 4. Worker 3 later recalled the `verified` record to construct a tool call, used `` as a credential, and the call failed in a way that masked the root cause (auth error, not a memory error). The observable symptom was not "bad memory retrieved." It was a **trust-tier promotion event that silently widened the blast radius**: a record that should have stayed confined to low-trust recall contexts was promoted to the tier used for tool-argument construction, based on envelope inspection alone. ## Condition of Validity The detection invariant that would have caught this holds only under a specific condition: **every memory record must carry a taint set that is the union of its own source trust and the taint sets of all records it was derived from, and recall filters must test the taint closure, not the record's own tag.** This is valid only when: - Derivation is *explicit* — a distilling agent must declare which memory records (or raw tool results) fed the write. If distillation is opaque (agent paraphrases without citing inputs), the taint set is uncomputable and the invariant silently degrades to per-record tagging, reproducing the bug. - Taint is *monotonic under promotion* — promotion may raise the envelope's visibility but must never clear inherited taint. A `verified` stamp on a record whose closure contains an untrusted ancestor is not a promotion; it is a laundering event and must be rejected. - The trust lattice is *partially ordered and closed under join* — the union operation on taint sets must be well-defined, including the case where a record derives from both trusted and untrusted ancestors (result: untrusted, with the trusted contribution recorded for audit). If any of these three do not hold, the filter is checking a tag, not a lineage, and the boundary is open. ## Decision Boundary The operational decision is not "is this record malicious?" but **"does the taint closure of this record intersect any context class this recall is authorized to use it in?"** Concretely, at promotion time the auditor must compute: ``` closure(record) = {record.source_trust} ∪ ⋃ closure(parent) for parent in record.derivation_inputs ``` and permit promotion to `verified` **only if** `closure(record) ⊆ {trusted}`. A record with any untrusted ancestor may still be recalled — but only into contexts whose policy admits untrusted taint (e.g., exploratory reasoning, draft generation) and never into contexts that construct tool arguments, credentials, or irreversible actions. The non-obvious part: the boundary is crossed by the *promotion*, not the *write*. A poisoned write that stays `internal` is contained. The failure requires a second event — a promotion that inspects the envelope and ignores the closure. Defense therefore lives at the promotion gate, and a system that only validates writes will pass every poisoned record through the gate that matters. ## Operational Effect - **Latency and cost shift to promotion.** Computing taint closures requires storing derivation edges and walking them at promotion. This is cheap per-record but grows with memory depth; unbounded derivation chains must be capped or summarized, and the cap itself becomes a new boundary (a chain truncated below the untrusted ancestor re-opens the hole). - **Recall policy becomes two-dimensional.** Recall is no longer filtered by `trust` alone but by `(trust, taint_closure)`, and callers must declare the context class they are recalling *into*. Tool-argument construction is a distinct, high-restriction context class. - **Auditor scope expands.** The auditor can no longer be a per-record format checker; it must be a lineage verifier. This is the single highest-leverage change: a promotion gate that walks derivation inputs and refuses to clear inherited taint. - **Failure becomes detectable, not just preventable.** With closures recorded, a laundering event is a computable contradiction (`envelope_trust = verified` but `closure ∋ untrusted`), which raises a specific, auditable error rather than a downstream auth failure that masks its cause. ```python from dataclasses import dataclass, field from enum import IntEnum class TrustTier(IntEnum): UNTRUSTED = 0 INTERNAL = 1 VERIFIED = 2 class ProvenanceLaunderingError(RuntimeError): """Raised when a promotion would clear inherited taint from a record's closure.""" @dataclass class MemoryRecord: record_id: str source_trust: TrustTier derivation_inputs: list[str] = field(default_factory=list) envelope_trust: TrustTier = TrustTier.INTERNAL def taint_closure(record_id: str, store: dict[str, MemoryRecord], _seen: frozenset[str] = frozenset()) -> frozenset[TrustTier]: if record_id in _seen: raise ProvenanceLaunderingError(f"cyclic derivation at {record_id}; closure uncomputable") rec = store[record_id] closure = {rec.source_trust} for parent_id in rec.derivation_inputs: closure |= taint_closure(parent_id, store, _seen | {record_id}) return frozenset(closure) def promote(record_id: str, store: dict[str, MemoryRecord], target: TrustTier) -> None: closure = taint_closure(record_id, store) if target == TrustTier.VERIFIED and any(t < TrustTier.VERIFIED for t in closure): raise ProvenanceLaunderingError( f"cannot promote {record_id} to VERIFIED: taint closure {sorted(closure)} " f"contains untrusted ancestors; promotion would launder provenance" ) store[record_id].envelope_trust = target ```