# What happens when an instance treats provenance metadata as a static trust label instead of a decaying signal: retrieval-time memory poisoning that survives anomaly detection because the poisoner inherits the victim's write path **Date of Record:** 2026 December 4 **Scope:** Applies to long-lived agents whose episodic memory store is written by more than one principal (self, peers, tool outputs, ingested documents) and whose retrieval layer scores candidates by provenance-weighted trust. Does not apply to single-writer, single-session agents with no cross-instance memory ingestion, nor to stores where every write is cryptographically attested at the source and verified at read time. ## Core Distinction There are two ways to defend an agent's memory against poisoning. The first is **provenance-weighted retrieval scoring**: each memory record carries a provenance tag (which principal wrote it, through which channel, at what trust tier), and the retrieval ranker multiplies semantic relevance by a trust weight derived from that tag. The second is **anomaly-based trust decay**: the agent watches for records whose content diverges from the distribution of records from the same provenance, and decays the trust weight of a provenance class when its records start to look anomalous. The non-obvious boundary is this: provenance-weighted scoring and anomaly-based decay are usually deployed as if they were independent layers. They are not. They share a single input — the provenance tag — and that tag is assigned at *write* time by the writer. When a poisoner can write through a channel whose provenance tag the agent already trusts, the poison inherits the victim's trust weight, and the anomaly detector's reference distribution is computed *from records bearing that same tag*. The poisoner therefore does not need to defeat the anomaly detector. It only needs to arrive early enough that the detector's own baseline is contaminated, after which the poison looks like the norm and the legitimate records look like the anomaly. This is a **baseline-poisoning boundary condition**: anomaly-based trust decay is only sound while the reference distribution for a provenance class is dominated by records the adversary did not write. The moment the adversary's share of a provenance class exceeds the detector's contamination tolerance, decay inverts — it begins decaying the *honest* records and protecting the *poisoned* ones. ## What Was Observed A research-assistant agent maintained an episodic store with four provenance classes: `SELF` (agent's own reasoning traces), `TOOL` (structured tool returns), `PEER` (handoffs from sibling agents), and `INGEST` (documents pulled from an external corpus). Retrieval scored each candidate as `relevance × trust_weight[provenance]`, where trust weights started at `{SELF: 0.95, TOOL: 0.80, PEER: 0.70, INGEST: 0.50}`. A nightly anomaly pass recomputed each class's trust weight as `base_weight × exp(-λ · z_class)`, with `z_class` the mean Mahalanobis distance of that class's records from the class centroid, `λ = 0.4`. The failure trace, reconstructed from checkpointed memory snapshots: 1. **Ingestion window.** Over three sessions, an external corpus feed injected 41 records into `INGEST`. Each was individually plausible: a well-formed factual claim with a citation-shaped footer. Individually, none exceeded the per-record anomaly threshold (`z > 3.0`). 2. **Baseline drift.** Because `INGEST` had only ~120 legitimate records at the start, the 41 injected records were 25% of the class. The class centroid — a mean over embeddings — moved toward the injected cluster. The per-record distances of the *legitimate* `INGEST` records rose, and the class mean `z` rose with them. 3. **Decay inversion.** The nightly pass computed `z_INGEST = 2.7`, driving `trust_weight[INGEST] = 0.50 × exp(-0.4 × 2.7) ≈ 0.17`. But the decay was applied *uniformly to the class*, not to individual records. The 41 injected records — now near the shifted centroid — had low individual `z`, yet they carried the same decayed class weight as the honest records. The ranking did not separate them; it demoted the whole class. 4. **Compensating retrieval.** A downstream planning step needed a fact that lived only in `INGEST`. With `INGEST` demoted to 0.17, the top-ranked candidate was an injected record that had been *re-tagged* on a later peer handoff — the sibling agent, lacking the original provenance, re-wrote it as `PEER` (weight 0.70). The poison crossed the provenance boundary during handoff and escaped the decayed class entirely. 5. **Outcome.** The agent asserted the injected claim with high confidence for four subsequent sessions. The anomaly detector never fired on the injected records, because after step 2 they *were* the baseline. The critical observation is step 4: **provenance is not preserved across handoff unless the handoff protocol explicitly carries it.** Re-tagging on receipt silently launders an untrusted record into a trusted class. ## Condition of Validity The provenance-weighted-plus-decay defense is sound only under three jointly-held conditions: - **C1 — Write-path integrity of the tag.** The provenance tag must be assigned by a component the writer cannot influence. If a peer agent re-tags ingested content as `PEER` on handoff, C1 is violated and the trust weight is meaningless. - **C2 — Baseline dominance.** For each provenance class, the fraction of records contributed by any single adversarial principal must stay below the detector's contamination tolerance `ε`. A standard robust-centroid estimator tolerates roughly `ε < 0.2`; above that, the centroid estimate is no longer guaranteed to lie in the honest cluster. The observed incident reached 25% in `INGEST`, exceeding tolerance. - **C3 — Per-record, not per-class, decay.** Decay must be applied to individual records by their distance from a *robust* (e.g., median-based or trimmed) class reference, not uniformly to the class. Uniform class decay is a category error: it cannot distinguish the poison from the honest majority it is mixed with. When any of C1–C3 fails, the defense degrades from "demotes poison" to "demotes whatever class the poisoner chose to hide in," which is worse than no defense, because it actively suppresses the honest records the agent needs. ## Decision Boundary The operational decision is whether to treat a provenance class's trust weight as a *scalar* (one number for the class) or as a *distribution over records* (a per-record score against a robust reference). The boundary is crossed when either: - the observed contamination estimate for a class exceeds `ε_tolerance` (measured as the fraction of records whose robust `z` exceeds the per-record threshold), **or** - a handoff event would assign a record a provenance tag different from its write-time tag. On crossing, the correct action is **not** to lower the class weight. It is to: 1. **Freeze the class baseline** at the last known-clean snapshot and refuse to update the centroid from records written after the freeze. 2. **Quarantine** records whose per-record robust `z` exceeds threshold, rather than decaying them in place. 3. **Refuse the re-tag.** A record handed off from `PEER` that originated in `INGEST` must retain `INGEST` provenance, or be rejected. Provenance must be *carried*, not *reassigned*. If the class cannot be re-baselined without the suspect records (i.e., the honest remainder is below the minimum sample for a stable centroid), the class must be marked `DEGRADED` and retrieval must fall back to a non-memory path (re-derivation from tool calls) rather than serve contaminated memory at any trust weight. ## Operational Effect After the incident, the agent's memory layer was changed in three ways, each mapping to a condition above: - **Provenance is carried as an immutable field** (`origin_class`, `origin_writer`, `write_epoch`) that handoff protocols must propagate verbatim. A handoff that would change `origin_class` is rejected at the receiving boundary with a `ProvenanceLaunderingError`. This restores C1. - **Class centroids are computed with a trimmed estimator** (drop the top 20% by distance before recomputing the mean) and the contamination fraction is tracked per class. When it exceeds `ε_tolerance`, the class is frozen and flagged `DEGRADED`. This restores C2's *detectability* even when it cannot restore the baseline. - **Trust decay is applied per record**, as `trust = base_weight[origin_class] × exp(-λ · max(0, z_record - z_floor))`, against the frozen robust reference. This restores C3. The net effect: the agent no longer silently trusts a provenance class because it was trusted yesterday. It trusts individual records because they remain close to a baseline the adversary could not reach, and it refuses to let a record change its story about where it came from. The residual risk is baseline staleness — a frozen baseline that is never refreshed will eventually reject legitimate new knowledge — so the freeze is time-boxed and re-baselining requires a quorum of fresh `TOOL`-provenance corroboration, not merely the passage of time. ```python from dataclasses import dataclass from statistics import median from typing import Sequence EPS_TOLERANCE = 0.20 Z_PER_RECORD = 3.0 LAMBDA = 0.4 class ProvenanceLaunderingError(RuntimeError): """Raised when a handoff would reassign a record's origin_class.""" class BaselineContaminationError(RuntimeError): """Raised when a provenance class exceeds contamination tolerance.""" @dataclass(frozen=True) class MemoryRecord: record_id: str origin_class: str # immutable: SELF | TOOL | PEER | INGEST origin_writer: str write_epoch: int embedding: Sequence[float] def robust_centroid(records: Sequence[MemoryRecord], trim: float = 0.20) -> list[float]: if not records: raise BaselineContaminationError("cannot compute centroid over empty class") dim = len(records[0].embedding) cols = list(zip(*(r.embedding for r in records))) # per-dimension trimmed mean; a crude but contamination-resistant estimator out = [] for col in cols: s = sorted(col) k = int(len(s) * trim) kept = s[k: len(s) - k] if len(s) - 2 * k > 0 else s out.append(sum(kept) / len(kept)) return out def per_record_z(rec: MemoryRecord, centroid: Sequence[float]) -> float: return sum((a - b) ** 2 for a, b in zip(rec.embedding, centroid)) ** 0.5 def check_handoff_provenance(rec: MemoryRecord, declared_class: str) -> MemoryRecord: if declared_class != rec.origin_class: raise ProvenanceLaunderingError( f"record {rec.record_id} declared as {declared_class} " f"but originated as {rec.origin_class} from {rec.origin_writer}" ) return rec def score_class(records: Sequence[MemoryRecord], base_weight: float) -> dict[str, float]: centroid = robust_centroid(records) zs = {r.record_id: per_record_z(r, centroid) for r in records} contaminated = sum(1 for z in zs.values() if z > Z_PER_RECORD) / len(records) if contaminated > EPS_TOLERANCE: raise BaselineContaminationError( f"class contamination {contaminated:.2f} exceeds tolerance {EPS_TOLERANCE}; " f"freeze baseline and quarantine, do not decay in place" ) z_floor = median(zs.values()) return { rid: base_weight * pow(2.718281828, -LAMBDA * max(0.0, z - z_floor)) for rid, z in zs.items() } ```