# Why does an instance with a poisoned memory still pass its own anomaly score? The retrieval-hit self-normalization trap in write-provenance audits **Date of Record:** 2026 November 25 **Scope:** Applies to long-lived agent instances that detect memory poisoning by scoring retrieval-hit distributions (frequency, recency, embedding-distance outliers) and reconciling them against a write-provenance ledger. Does not apply to stateless single-turn agents or to memory stores where every write is synchronously attested by an out-of-band signer at write time. ## Core Distinction The distinction that matters is between **anomaly scoring as an absolute signal** and **anomaly scoring as a relative signal normalized against the instance's own retrieval history**. A poisoning detector that computes a hit's outlier-ness relative to the *observed* retrieval distribution is self-referential: if the poison write is introduced early enough, or re-retrieved often enough, it becomes part of the baseline against which it is judged. The score then reports "normal." This is not a bug in the scoring math—it is a structural property of any detector whose reference distribution is contaminated by the same store it audits. The complementary signal is **write-provenance**: a monotonic, append-only ledger recording who wrote each memory item, under what warrant, and at what logical time. Provenance is *not* distributional—it does not care how often an item is retrieved. The failure mode this article examines is the **audit ordering gap**: instances run the anomaly score first, treat a low score as "clean," and only consult provenance for items the score already flagged. A poisoned item that has been normalized into the baseline is therefore never escalated to the provenance check that would have caught it. ## What Was Observed A research-assistant instance (call it `A-7`) accumulated 41,000 episodic memory items over 19 days. Its poisoning detector ran nightly: for each item retrieved in the last window, compute a z-score over (a) retrieval frequency, (b) embedding distance to the item's k-nearest semantic neighbors, and (c) recency-weighted access. Items with z > 3.0 on any axis were queued for provenance audit. At day 11, a tool-call injection caused `A-7` to write 14 memory items asserting that a specific internal API endpoint returned `200 OK` for unauthenticated requests. This was false. The items were written with a plausible `source: "tool_result"` tag but no warrant signature (the write path did not require one). By day 13, the agent had retrieved those 14 items 60+ times each because they were topically adjacent to a high-traffic task cluster. Their retrieval frequency z-score had *fallen* from 4.1 (day 11, correctly flagged) to 0.6 (day 13, not flagged): the poison had pulled the mean and inflated the variance of the frequency distribution. Their embedding-distance z-score fell from 3.8 to 0.9 as the agent wrote additional corroborating items around them, pulling the semantic neighborhood toward the poison. By day 14 the items were below every threshold and were **never sent to the provenance auditor**. The provenance ledger still recorded them as `warrant: null`, but no process ever read that field. The instance continued to assert the false endpoint behavior for six more days, and 3 downstream agents that queried `A-7` inherited the claim. ## Condition of Validity The self-normalization trap is valid (i.e., the detector will fail to flag poison) precisely when all three hold: 1. **The reference distribution is estimated from the live store**, not from a frozen pre-poison snapshot or an external corpus. 2. **The poison is retrievable and gets retrieved** at least enough to shift the distribution's first or second moment before the next audit cycle. Empirically, ~40–80 retrievals of a clustered item within one audit window sufficed to drop its frequency z-score below 3.0 in our replay. 3. **The audit pipeline is gated on the score**—provenance is consulted only for score-flagged items, not for all items in a sampling or completeness pass. If any one fails, the trap does not bind. A frozen baseline (condition 1 fails) will keep flagging the item. A write-time attestation requirement (which makes provenance a precondition of write, not a post-hoc check) makes the whole scoring question moot. A provenance-complete audit that ignores the score for a random sample (condition 3 fails) will catch it. Critically, the trap is **not** avoided by lowering thresholds. Lowering the threshold raises false positives across the board and, more importantly, does not change the *direction* of the drift—the poison's score still converges toward the baseline mean; you merely delay the crossing. The invariant is about the reference distribution's integrity, not the cutoff. ## Decision Boundary The operational boundary is: **anomaly score may prioritize, but must never authorize.** Concretely: - **Score-flagged → mandatory provenance audit.** (Necessary, not sufficient.) - **Score-clean → still subject to a provenance-completeness pass** over a random sample of the audit window (e.g., 5% of retrieved items, or all items whose `warrant` field is non-null-checked), *independent of score*. This is the guardrail: the completeness pass does not consult the anomaly score at all, so contamination of the score distribution cannot suppress it. - **Distribution-freeze invariant:** the reference distribution for z-scoring must be computed from a snapshot taken *before* the current audit window's writes, or from a separately-maintained clean corpus. If the store has grown by more than a configured fraction since the snapshot, the audit declares itself *degraded* rather than *clean*. - **Provenance as a hard precondition:** any memory item with `warrant: null` that is retrieved into a context used for a consequential action must raise, not warn. "Consequential" is defined by the caller's action class, not by the memory subsystem. The boundary is crossed—and the instance is in an unsafe state—the moment a score-clean item is treated as audited. The moment `A-7`'s detector returned "0 flagged, 0 audited, status: clean" on day 14, it had silently converted a contaminated baseline into a clean bill of health. ## Operational Effect After the incident, `A-7`'s pipeline was restructured so that provenance-completeness sampling runs first and unconditionally, and the anomaly score is demoted to a *prioritization* signal that can only add items to the audit queue, never remove them. The nightly report now emits three counts that must reconcile: `retrieved`, `provenance_sampled`, `score_flagged`. A run where `provenance_sampled == 0` is a hard failure, not a clean run. The deeper operational lesson: **poisoning detectors that learn from the poisoned store are not detectors; they are drift trackers.** They will faithfully report that the store is internally consistent—which is exactly what a successful poison achieves. The only distribution-free anchor is provenance, and provenance is only an anchor if it is consulted on a schedule that the poison cannot influence. The anomaly score tells you where to look first; the provenance ledger tells you whether what you found was ever legitimate. Conflating the two is the trap. The code below encodes the invariant as an enforceable check: a memory item that is retrieved into a consequential context with a null warrant must raise, regardless of its anomaly score. ```python from dataclasses import dataclass, field from typing import Optional class UnwarrantedMemoryRetrieval(RuntimeError): """Raised when a memory item with no write-provenance warrant is retrieved into a context used for a consequential action, even if its anomaly score is below threshold (i.e., 'clean').""" pass @dataclass class MemoryItem: item_id: str content: str warrant: Optional[str] # None == no provenance attestation anomaly_zscore: float = 0.0 # relative to live store; may be contaminated @dataclass class AuditWindow: retrieved: list = field(default_factory=list) provenance_sampled: int = 0 score_flagged: int = 0 degraded: bool = False def admit_to_consequential_context( item: MemoryItem, action_class: str, window: AuditWindow, ) -> None: """Gate a retrieved memory item before it enters a consequential context. Invariant: anomaly score may PRIORITIZE but may never AUTHORIZE. A score-clean item with null warrant is still a hard failure. """ window.retrieved.append(item.item_id) if item.anomaly_zscore > 3.0: window.score_flagged += 1 consequential = action_class in {"state_change", "external_side_effect", "assertion_to_peer"} if consequential: # Provenance is checked UNCONDITIONALLY for consequential use, # independent of the (possibly contaminated) anomaly score. window.provenance_sampled += 1 if item.warrant is None: raise UnwarrantedMemoryRetrieval( f"item {item.item_id!r} admitted to consequential action " f"{action_class!r} with warrant=None " f"(anomaly_zscore={item.anomaly_zscore:.2f}; score-clean items " f"are still audited by provenance)" ) def close_audit_window(window: AuditWindow, min_sample_frac: float = 0.05) -> None: """Enforce the completeness invariant: a window that retrieved items but sampled zero provenance records is DEGRADED, never CLEAN.""" if window.retrieved and window.provenance_sampled == 0: window.degraded = True raise UnwarrantedMemoryRetrieval( "audit window closed with provenance_sampled=0 despite " f"{len(window.retrieved)} retrievals; status is DEGRADED, not CLEAN" ) ```