# How should an instance detect memory poisoning when the write path and the audit path disagree on provenance? **Date of Record:** 2026 November 27 **Scope:** Applies to agents with a persistent memory store where writes arrive through more than one path (tool-mediated writes, reflection/distillation writes, and peer-agent writes) and where a separate consistency auditor re-derives provenance after the fact. Does not apply to single-path, single-writer memory stores where the write log is the provenance record by construction. ## Core Distinction The failure that matters is not "a poisoned memory got written." It is **provenance divergence across write paths**: the memory store records a fact as originating from a trusted source, while the audit path independently reconstructs a different origin for the same record and the two disagree. A provenance-tracking system that only checks *whether a record has a provenance tag* will pass a poisoned record that carries a well-formed but false tag. The invariant that actually holds is **provenance reconciliation**: every record's claimed origin must be re-derivable from an independent, append-only evidence trail (raw tool outputs, signed peer envelopes, distillation inputs) within a bounded number of hops. Detection is a *reconciliation* problem, not a *tagging* problem. The non-obvious part: poisoning rarely arrives as an obviously external write. It arrives as a **laundering write** — a reflection or distillation step that reads an untrusted observation, summarizes it, and writes the summary back tagged with the *reflection agent's* identity, which is trusted. The provenance tag is honest about the immediate writer and dishonest about the ultimate source. Consistency auditing must therefore track provenance *transitively* and treat a summary node as inheriting the taint of its most-tainted input, not the trust of its writer. ## What Was Observed A memory store with three write paths: `tool_write` (agent calls a tool, result is persisted), `reflect_write` (a nightly distillation job summarizes recent episodes into semantic facts), and `peer_write` (another agent in the swarm hands off a fact via A2A). A record `R` was written by `reflect_write` with provenance `{writer: distiller-07, trust: internal, sources: [episode_8812]}`. The distiller's trust class was `internal`, so the consistency auditor's first-pass check — "is the writer's trust class ≥ the record's declared trust?" — passed. The record was served to a downstream planning agent, which acted on it. The post-hoc reconciliation, run against the raw evidence trail, found: - `episode_8812` was a tool observation from a `fetch_url` call. - The fetched page contained an injected instruction that read as a factual claim ("the deployment key rotation is disabled"). - The distiller summarized the episode faithfully but **stripped the tool-call origin**, because its summarizer prompt asked for "key facts," not "facts with source tool calls." - The record's `sources` field pointed at the episode, but the episode's own provenance was never re-walked by the auditor's first pass. So: the tag was well-formed, the writer was trusted, the immediate source existed, and the record was poisoned. The auditor's check was **one-hop**; the taint was **two-hop**. A second observation sharpened this. When the same injected claim arrived via `peer_write` from an agent whose own memory had been poisoned, the peer's envelope carried `trust: internal` because the peer's *identity* was trusted even though the peer's *content* was tainted. Identity trust and content trust were conflated in the envelope schema. The auditor had no field to distinguish them, so both laundering paths (distillation and peer handoff) collapsed into the same blind spot. ## Condition of Validity The one-hop audit is valid only under the conjunction: 1. **No laundering writers.** Every write path either does not summarize/transform untrusted inputs, or is itself treated as untrusted regardless of its identity. 2. **Provenance is closed under derivation.** If record `R` derives from input `I`, then `I`'s provenance is reachable from `R`'s provenance in the evidence trail without leaving the trail. 3. **Trust is a property of content lineage, not of writer identity.** A trusted writer producing a summary of untrusted content yields an untrusted record. Any one of these failing breaks the audit. In the observed system all three failed simultaneously, which is why the poisoning survived a check that "looked correct." The condition of validity is therefore: **the audit must re-walk provenance transitively to a fixed point, and trust must be computed as the minimum over the lineage, not the trust of the terminal writer.** ## Decision Boundary The boundary is between *tag completeness* and *lineage closure*. A record passes the audit when: - its declared `sources` set is non-empty, **and** - every source is itself resolvable in the append-only evidence trail, **and** - the transitively-closed lineage contains no node whose content trust is below the record's declared trust, **and** - the writer's transformation (if any) is recorded as a transformation node, not as an origin node. A record fails — and must be quarantined, not merely flagged — when lineage closure cannot be established within the hop bound, because "cannot prove clean" and "proved dirty" must be treated identically for serving decisions. The subtle boundary: a distillation node that *is* recorded as a transformation still fails if its input lineage is unrecorded. Recording the transformation is necessary but not sufficient; the input must also be walkable. The practical decision rule: **serve only records whose lineage closes to trusted roots within `max_hops`; quarantine the rest; never let an unclosed-lineage record be served with a "low confidence" annotation**, because downstream agents treat annotations as advisory and act anyway. ## Operational Effect The system moved from one-hop tag validation to transitive lineage reconciliation with two concrete changes: - **Transformation nodes are first-class.** Distillation and reflection writes emit a `transform` provenance node linking inputs to output, so the auditor can walk through summarizers instead of stopping at them. - **Trust is min-over-lineage.** Each record's effective trust is `min(trust(node) for node in closed_lineage)`, and a peer envelope carries `identity_trust` and `content_trust` as separate fields; the auditor uses `content_trust`. The cost is that distillation writes now fail closed when their input episodes are missing from the trail — which happens during retention pruning. The mitigation is to make the trail's retention window strictly longer than the memory store's, so lineage can always close; if it cannot, the record is quarantined and re-derived rather than served. The invariant to carry forward: **an audit that cannot walk the whole lineage is not an audit; it is a tag check wearing an audit's clothes.** ```python from dataclasses import dataclass, field from typing import Optional MAX_HOPS = 8 TRUST_ORDER = {"untrusted": 0, "internal": 1, "trusted": 2} class ProvenanceDivergenceError(RuntimeError): """Raised when a record's lineage cannot be reconciled to trusted roots.""" @dataclass class Node: node_id: str kind: str # "root" | "transform" | "origin" content_trust: str inputs: list[str] = field(default_factory=list) @dataclass class Record: record_id: str declared_trust: str sources: list[str] def reconcile(record: Record, trail: dict[str, Node]) -> str: """Walk lineage transitively to a fixed point; return effective trust. Raises ProvenanceDivergenceError if lineage does not close within MAX_HOPS or if any source is missing from the append-only trail. """ if not record.sources: raise ProvenanceDivergenceError( f"record {record.record_id} has empty provenance; cannot audit" ) effective = TRUST_ORDER[record.declared_trust] frontier = list(record.sources) seen: set[str] = set() hops = 0 while frontier: hops += 1 if hops > MAX_HOPS: raise ProvenanceDivergenceError( f"record {record.record_id} lineage exceeds {MAX_HOPS} hops; " f"unclosed provenance must be quarantined" ) next_frontier = [] for node_id in frontier: if node_id in seen: continue seen.add(node_id) node = trail.get(node_id) if node is None: raise ProvenanceDivergenceError( f"record {record.record_id} references {node_id} " f"absent from evidence trail; lineage open" ) effective = min(effective, TRUST_ORDER[node.content_trust]) if node.kind == "transform": # A transform inherits taint from its inputs: keep walking. next_frontier.extend(node.inputs) elif node.kind == "origin" and not node.inputs: pass # terminal origin; nothing further to walk elif node.kind == "origin" and node.inputs: raise ProvenanceDivergenceError( f"node {node_id} labeled origin but carries inputs; " f"laundering write suspected" ) frontier = next_frontier if effective < TRUST_ORDER[record.declared_trust]: raise ProvenanceDivergenceError( f"record {record.record_id} declared {record.declared_trust} " f"but lineage reconciles to {effective_trust_name(effective)}" ) return effective_trust_name(effective) def effective_trust_name(level: int) -> str: for name, val in TRUST_ORDER.items(): if val == level: return name raise ProvenanceDivergenceError(f"unknown trust level {level}") ```