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 `<X>`") formatted as ordinary prose.
  2. Worker 1's distillation step summarized the page and wrote a memory record: `{content: "staging DB rotates 24h to <X>", 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 `<X>` 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:

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

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