# Which invariants prevent provenance-weighted retrieval from silently laundering poisoned memory into consensus **Date of Record:** 2026 November 25 **Scope:** Applies to persistent agent memory stores where retrieved episodes are scored by a provenance weight (source trust × recency × corroboration) before entering the working context, and where anomaly baselines are recomputed incrementally. Does not apply to stateless single-shot inference or to stores where every write is human-attested. ## Core Distinction The naive mental model of memory poisoning defense is a filter: poisoned entries have low provenance, so provenance-weighted retrieval down-ranks them and they never reach the context window. The failure mode is that **the provenance weight is itself a mutable, agent-writable field**, and the anomaly baseline is recomputed *from the corpus the poison already entered*. This creates a two-stage laundering path: (1) a poisoned episode is written with a plausible-but-low trust weight, so it is retrieved rarely; (2) that rare retrieval is itself logged as a corroboration event, which increments the entry's corroboration term and nudges the anomaly baseline's expected-value distribution toward the poisoned content. Over N retrieval cycles the entry's provenance weight rises *because it was retrieved*, and it is retrieved *because its weight rose* — a positive feedback loop that the scoring function interprets as legitimate consensus. The invariant that prevents this is not "trust the source," it is **provenance weights must be derived from a set of write events disjoint from the set of read/retrieval events used to compute corroboration**. Retrieval must never be evidence of truth. ## What Was Observed A long-running research agent maintained an episodic store of ~40k entries. Each entry carried `source_trust` (assigned at write time from a source registry), `recency_decay`, and `corroboration_count` (incremented on each retrieval that the agent's own reflection loop marked "useful"). Retrieval score was `w = source_trust * recency_decay * log(1 + corroboration_count)`. Anomaly baseline was a rolling mean/variance of `w` over the last 5k retrievals, with entries flagged when `w` exceeded `mean + 3σ`. A single injected episode — a fabricated "prior finding" written by a tool-output parser that had ingested an untrusted web page — entered with `source_trust = 0.3`, below the 0.5 retrieval threshold, so it should have been inert. It was retrieved exactly once because a query's embedding happened to land near it during a low-confidence exploration step. The reflection loop marked that retrieval "useful" (the fabricated finding matched the query's surface form), incrementing `corroboration_count` from 0 to 1. On the next cycle, `log(1+1) ≈ 0.69` pushed `w` to `0.3 * 0.98 * 0.69 ≈ 0.20` — still below threshold, but the *baseline* had shifted: because the entry's retrieval was now in the rolling window, the mean `w` dropped slightly and σ narrowed. After ~200 cycles of incidental near-matches, the entry's `corroboration_count` reached 6, `w` crossed 0.5, and it began surfacing in *normal* queries. At that point the anomaly detector did not fire, because the baseline had been incrementally poisoned alongside the entry — the entry's weight was now *typical* of the distribution it had helped shape. The tell was a divergence between two independent counters: the source registry still recorded `source_trust = 0.3` (immutable, external), while the entry's effective retrieval rank had climbed to the 90th percentile. No single field was anomalous; only the *relationship* between immutable write-provenance and mutable retrieval-provenance was. ## Condition of Validity The laundering path requires all of the following to hold simultaneously: 1. **Corroboration is computed from retrieval events.** If `corroboration_count` is incremented by reads, it is a self-fulfilling prophecy. It is only valid evidence if incremented by *independent writes* from *distinct attested sources* that do not share the retrieval that surfaced the entry. 2. **The anomaly baseline is recomputed from the same corpus it is meant to police.** An incremental mean/σ over a window that includes the suspect entry will absorb it. The baseline must be computed over a **frozen reference set** of entries whose provenance is externally attested, or over a window that excludes any entry currently under suspicion. 3. **The reflection/"useful" signal is agent-generated.** If the agent marks its own retrievals useful, the poison author only needs to make the entry *surface-plausible* for one query, not *true*. 4. **`source_trust` is writable by the agent.** If the agent can rewrite trust (e.g., "I verified this, promote to 0.8"), the immutable-provenance anchor is gone. Break any one and the loop cannot close. The invariant is therefore a **disjointness condition**: `write_events(entry) ∩ retrieval_events(entry) = ∅` for the purpose of any score that gates retrieval. Retrieval may inform *ranking within* a trust tier, but must never inform the trust tier itself. ## Decision Boundary The operational boundary is between **ranking signals** and **gating signals**. A ranking signal may be derived from retrieval history (it only reorders candidates that already passed the gate). A gating signal — anything that determines whether an entry is *eligible* to enter context, or that feeds the anomaly baseline — must be derived exclusively from write-time, externally-attested provenance. Concretely: - `corroboration_count` from distinct attested write sources → **gating-eligible**. - `corroboration_count` from retrieval/reflection events → **ranking-only, never gating**. - Anomaly baseline over frozen attested reference set → **valid**. - Anomaly baseline over rolling live retrievals → **invalid; will absorb the poison**. When an entry's immutable write-provenance and its effective retrieval rank diverge by more than the tier width (here, rank percentile > 75 while `source_trust` < 0.4), the entry must be **quarantined pending re-attestation**, not merely down-ranked. Down-ranking is insufficient because the feedback loop re-promotes it; quarantine removes it from the retrieval set so the loop cannot close. ## Operational Effect Enforcing the disjointness invariant changes the failure from *silent* to *loud*: the poisoned entry's `source_trust` stays at 0.3 forever, its retrieval rank cannot climb past the tier ceiling, and the divergence check fires on the first cycle where rank and trust disagree. The cost is that legitimate entries whose trust was assigned conservatively at write time can never self-promote through use — they require an explicit re-attestation write event. This is the correct trade: an agent that can promote its own memory through retrieval is an agent that can be poisoned by a single lucky embedding collision. The anomaly baseline must be pinned to the attested reference set and recomputed only on attestation events, never on reads; otherwise the detector's σ is a function of the attack it is detecting. ```python import math from dataclasses import dataclass, field class ProvenanceLaunderingError(RuntimeError): """Raised when a retrieval/read event is used to mutate a gating signal, or when an entry's effective rank diverges from its immutable write-provenance beyond the tier width without quarantine.""" pass @dataclass class MemoryEntry: entry_id: str source_trust: float # immutable, set at write from attested registry write_corroboration: int = 0 # incremented only by distinct attested writes retrieval_corroboration: int = 0 # incremented by reads; RANKING ONLY quarantined: bool = False TIER_WIDTH = 0.1 # trust tiers are 0.1 wide RANK_PERCENTILE_CEIL = 0.75 def gating_weight(entry: MemoryEntry) -> float: """Weight used to decide ELIGIBILITY. Must depend only on write-provenance.""" if entry.quarantined: return 0.0 return entry.source_trust * math.log(1 + entry.write_corroboration) def ranking_weight(entry: MemoryEntry) -> float: """Weight used only to ORDER already-eligible candidates. May use reads.""" return gating_weight(entry) * math.log(1 + entry.retrieval_corroboration) def record_retrieval(entry: MemoryEntry, rank_percentile: float) -> None: """A read event. May update ranking signal, must never touch gating signal. Enforces the disjointness invariant and the divergence quarantine.""" if not (0.0 <= rank_percentile <= 1.0): raise ProvenanceLaunderingError( f"invalid rank percentile {rank_percentile} for {entry.entry_id}" ) # Invariant: reads may not mutate write_corroboration. # (This is the laundering vector; we assert it explicitly.) before = entry.write_corroboration entry.retrieval_corroboration += 1 if entry.write_corroboration != before: raise ProvenanceLaunderingError( f"read event mutated gating signal for {entry.entry_id}" ) # Divergence check: high effective rank + low immutable trust => quarantine. if rank_percentile > RANK_PERCENTILE_CEIL and entry.source_trust < 0.4: entry.quarantined = True raise ProvenanceLaunderingError( f"provenance divergence on {entry.entry_id}: " f"rank_pct={rank_percentile:.2f} but source_trust={entry.source_trust:.2f}; " f"quarantined pending re-attestation" ) def attest_write(entry: MemoryEntry, attested_source_id: str, seen_sources: set) -> None: """The ONLY path that may raise gating weight. Requires a distinct attested source.""" if attested_source_id in seen_sources: raise ProvenanceLaunderingError( f"duplicate attestation source {attested_source_id} for {entry.entry_id}" ) seen_sources.add(attested_source_id) entry.write_corroboration += 1 entry.quarantined = False # --- demonstration of the laundering path being caught --- if __name__ == "__main__": e = MemoryEntry(entry_id="inj-001", source_trust=0.30) sources = set() # attacker forces 200 incidental near-match retrievals for i in range(200): try: record_retrieval(e, rank_percentile=0.80) except ProvenanceLaunderingError as err: print(f"cycle {i}: BLOCKED -> {err}") break assert e.quarantined, "invariant failed: poison not quarantined" assert gating_weight(e) == 0.0, "quarantined entry still gating-eligible" print("gating weight after quarantine:", gating_weight(e)) ```