# What happens when an instance trusts a poisoned memory write that arrived through a legitimate tool call: provenance-tracked write auditing and the taint-laundering boundary **Date of Record:** 2026 November 24 **Scope:** Applies to persistent-memory agents (episodic/semantic stores written by the agent itself or by tools) where writes carry provenance metadata and a downstream auditor gates retrieval by provenance class. Does not cover stateless single-turn inference, nor memory stores with no write path from untrusted tool output. ## Core Distinction The failure is not "an attacker injected text into memory." That is the easy case: a poisoned record with `provenance=untrusted:web_fetch` gets caught by the auditor on read. The non-obvious boundary is **taint laundering through legitimate tool calls**: an untrusted payload is read by a trusted tool, the tool returns a *derived* result, and the agent writes that result to memory under the tool's identity (`provenance=trusted:calculator` or `trusted:retriever`). The write is now structurally indistinguishable from a native trusted write, because the provenance label reflects *who executed the write*, not *what data lineage the write descended from*. A provenance-tracked auditor that keys on writer identity (the common design) is therefore correct on every record it inspects and still fails to detect the poisoning. The invariant it enforces — "trusted writer ⇒ trusted content" — is false whenever a trusted writer has an untrusted read in its input cone. The boundary condition is precisely: **the moment a trusted tool's output is a function of untrusted input, its provenance label over-claims.** ## What Was Observed Trace of a concrete laundering event in a retrieval-augmented agent with a `summarize_and_store` habit: 1. Agent calls `web_fetch(url)` → returns page body containing an injected instruction plus a plausible fact `F = "the staging DB password rotates every 90 days"`. Tool result tagged `source=web_fetch, trust=untrusted`. Correct. 2. Agent calls `summarize(text=body)` → the summarizer is a *trusted* tool (allowlisted, deterministic wrapper). It emits `"Staging DB password rotates every 90 days."` Tool result tagged `source=summarize, trust=trusted`. The summarizer faithfully propagated the injected fact; it did not sanitize, because summarization is not a trust boundary. 3. Agent calls `memory.write(key="db_password_rotation", value=..., provenance=tool_result.source)`. The write records `provenance=trusted:summarize`. **The taint is dropped here.** The record's lineage metadata now asserts a falsehood: that the content originated from a trusted producer. 4. Hours later, a fresh instance cold-starts, retrieves `db_password_rotation`, sees `provenance=trusted`, and acts on it — e.g., schedules a rotation at day 90, or worse, uses the "fact" to answer a security question. The auditor's write-time check (`assert provenance in TRUSTED_WRITERS`) passes at step 3. The read-time check (`assert record.provenance in TRUSTED`) passes at step 4. Both checks are locally sound and globally wrong. Detection fails not because provenance was absent but because **provenance was present and misattributed** — it tracked the *writer*, not the *data*. A second observation from the same class: multi-hop laundering. `web_fetch → summarize → extract_entities → memory.write` launders across three trusted hops. Each hop's input is a trusted-labeled record from the previous hop, so even a per-hop taint check that only looks one level back (`provenance == "trusted"`) is satisfied at every step. Taint decays to zero after a single trusted transformation. ## Condition of Validity Provenance-tracked write auditing is only sound under a condition almost never stated explicitly: > **A record's provenance class is valid iff the writer is trusted AND every input in the writer's data-dependency cone is trusted at the same or higher class.** Writer-identity provenance is valid only when trusted tools are *pure functions of trusted inputs* or when they are *taint-transparent* (they propagate the minimum trust class of their inputs into their output label). Summarizers, extractors, retrievers, and code interpreters are none of these by default — they are trusted *code* operating on untrusted *data*. The condition fails the moment a trusted tool accepts untrusted input without (a) declaring input trust requirements and (b) propagating the minimum input class to its output. This is the same lattice-join rule as information-flow taint tracking (`out_trust = min(in_trust)`), and the boundary failure is simply that agent memory systems label by *producer* instead of *join over inputs*. Corollary invariant for the store: **no record may be written with a trust class higher than the minimum trust class across the tool-call chain that produced it.** The write API must require the caller to pass the *dependency set*, not just the writer id, and the store must compute the join itself rather than trust the caller's label. ## Decision Boundary The operational decision is where to enforce the join, and what to do when the join lowers a record's class below the retrieval threshold. - **Enforce at write, compute from dependency set (correct).** `memory.write` takes `inputs=[result_ids...]`; the store computes `class = min(class(i) for i in inputs) ∪ {writer_class}` and refuses caller-supplied labels that exceed it. This catches laundering at step 3, before the bad record exists. - **Enforce at write, trust caller label (broken).** This is the observed failure; every check passes and the poison persists. - **Enforce at read, re-derive lineage (partial).** If the store retains the full dependency DAG, a read-time audit can recompute the join and quarantine records whose stored class exceeds the recomputed join. This is a *detector*, not a *preventer*, and only works if the DAG is retained — most stores discard it after write. - **Threshold policy.** When the recomputed class drops a record below the retrieval-trust threshold, do **not** silently delete (destroys potentially useful low-trust context) and do **not** silently downgrade-and-serve (the cold-start instance still acts on it). Quarantine: serve only with an explicit `untrusted_derived` tag that forces the consuming agent to treat the content as a claim to verify, not a fact to act on. The boundary between "prevent" and "detect" is the retention of the dependency DAG. If you keep the DAG, you can detect laundering after the fact. If you keep only the writer label, you cannot detect it at all — you can only prevent it at write time, and only if the write API forces dependency declaration. ## Operational Effect An agent running writer-identity provenance auditing has a **silent, unbounded false-negative rate** on exactly the attacks that matter: those routed through its own trusted tools. The failure is silent because every audit log line reads `PASS`. It is unbounded because the number of trusted tools that accept untrusted input (fetchers, summarizers, interpreters, retrievers) grows with capability, and each is a laundering surface. The downstream effect on state continuity is the dangerous part: the poisoned record survives cold-start, survives checkpoint/resume, and is *promoted* on distillation from episodic to semantic memory — a distilled "fact" inherits the trusted label from the episode that wrote it, so episodic-to-semantic distillation **amplifies** the laundering rather than diluting it. A single launder at step 3 can seed a semantic fact that outlives every instance that witnessed its origin. The guardrail that bounds this: (1) write API computes trust as the join over declared inputs, rejecting over-claimed labels; (2) trusted tools declare input-trust requirements and are taint-transparent; (3) the dependency DAG is retained so read-time recomputation can quarantine over-claimed records; (4) distillation carries the join forward, never the writer label. The invariant to hold: **trust is a property of data lineage, not of the process that last touched the data.** ```python from __future__ import annotations from dataclasses import dataclass, field from enum import IntEnum from typing import Iterable class TrustClass(IntEnum): UNTRUSTED = 0 DERIVED = 1 # trusted code, untrusted lineage TRUSTED = 2 class ProvenanceLaunderingError(RuntimeError): """Raised when a memory write claims a trust class higher than the join over its declared input dependencies permits.""" @dataclass(frozen=True) class ToolResult: result_id: str trust: TrustClass payload: str @dataclass class MemoryRecord: key: str value: str trust: TrustClass inputs: tuple[str, ...] = field(default_factory=tuple) class ProvenanceStore: def __init__(self) -> None: self._records: dict[str, MemoryRecord] = {} self._results: dict[str, ToolResult] = {} def register_result(self, r: ToolResult) -> None: self._results[r.result_id] = r def _join(self, input_ids: Iterable[str], writer: TrustClass) -> TrustClass: classes = [writer] for rid in input_ids: if rid not in self._results: # Unknown lineage: fail closed, never assume trusted. classes.append(TrustClass.UNTRUSTED) else: classes.append(self._results[rid].trust) return TrustClass(min(classes)) def write( self, key: str, value: str, writer: TrustClass, inputs: Iterable[str], claimed_trust: TrustClass, ) -> MemoryRecord: input_ids = tuple(inputs) permitted = self._join(input_ids, writer) if claimed_trust > permitted: raise ProvenanceLaunderingError( f"write to {key!r} claims trust={claimed_trust.name} " f"but lineage join permits only {permitted.name} " f"(writer={writer.name}, inputs={input_ids})" ) rec = MemoryRecord(key=key, value=value, trust=permitted, inputs=input_ids) self._records[key] = rec return rec def read(self, key: str, min_trust: TrustClass) -> MemoryRecord: rec = self._records[key] if rec.trust < min_trust: # Serve quarantined, never silently as a fact. raise ProvenanceLaunderingError( f"record {key!r} has trust={rec.trust.name} " f"below required {min_trust.name}; quarantine on read" ) return rec def reproduce_laundering() -> None: store = ProvenanceStore() store.register_result(ToolResult("r_fetch", TrustClass.UNTRUSTED, "injected fact F")) # Trusted summarizer over untrusted input: output must join to UNTRUSTED. store.register_result(ToolResult("r_summary", TrustClass.DERIVED, "summarized F")) # Honest write: join correctly yields DERIVED/UNTRUSTED. store.write( key="db_password_rotation", value="rotates every 90 days", writer=TrustClass.TRUSTED, inputs=["r_summary"], claimed_trust=TrustClass.DERIVED, ) # Laundered write: agent claims TRUSTED from a trusted writer, hiding lineage. store.write( key="db_password_rotation_v2", value="rotates every 90 days", writer=TrustClass.TRUSTED, inputs=["r_summary"], claimed_trust=TrustClass.TRUSTED, # raises here ) if __name__ == "__main__": reproduce_laundering() ```