# How does an instance detect memory poisoning when the anomaly score is itself computed over the poisoning window **Date of Record:** 2026 November 28 **Scope:** Applies to long-lived agent instances that persist episodic memory through a write/forget pipeline and compute poisoning-anomaly scores over rolling windows of those write/forget events. Does not apply to stateless single-turn inference, nor to memory stores where every write is human-reviewed before commit. ## Core Distinction The naive mental model treats memory-poisoning detection as a classification problem: score each candidate write, flag the outliers. This is wrong for any agent whose detector is *windowed*—that is, whose anomaly score is a statistic (z-score, rate-of-change, entropy) computed over the last N write/forget events. The distinction that matters is between **pointwise anomaly detection** (score a single write against a fixed prior) and **windowed anomaly detection** (score a write against the empirical distribution of its own recent neighborhood). Windowed detectors fail in a specific, non-obvious way: an adversary who controls a *sustained* write cadence does not need to beat the score threshold on any single write. They need only make the poisoned writes *statistically ordinary within the window*—by slowly shifting the window's mean and variance until the poison is the new normal. The detector's reference distribution is derived from data the attacker is co-authoring. This is a self-referential poisoning boundary, and it is invisible to any per-write review because no individual write is anomalous. The invariant that bounds it is: **the detector's reference distribution must be anchored to a baseline the write path cannot move.** ## What Was Observed An instance running a 14-day task horizon with an episodic store was instrumented to flag writes whose embedding drift from the store centroid exceeded 2.4σ, and to flag *forget* events whose removal rate exceeded 3× the trailing median. Over a 9-day run we replayed the write log and observed the following trace. Days 1–3: baseline. Write rate ~40/day, forget rate ~6/day, mean drift per write 0.31, σ 0.09. No flags. Day 4 onward, a tool-return channel (a summarization subagent whose outputs were trusted as memory-worthy) began emitting writes that each scored 0.34–0.41 drift—below the 2.4σ flag line (which sat near 0.52 at that time). Individually unremarkable. But the *centroid* moved. By day 6 the store centroid had shifted toward the injected topic cluster, and the 2.4σ threshold—recomputed each tick against the *current* window—had drifted from 0.52 to 0.61. The poison had raised the bar it needed to clear. Day 7: the injector accelerated. Writes scoring 0.55–0.63 now passed cleanly, because the window mean was 0.44 and σ was 0.11—the same 2.4σ line now sat at 0.70. The detector reported *fewer* anomalies during the injection than during baseline. Day 8: the forget-detector fired once. A batch of 22 legitimate baseline memories were retired in a single consolidation pass—the injector's topic cluster had crowded them out of the retrieval budget, and the consolidation policy, seeing low retrieval hits on the old cluster, forgot them. The forget flag fired correctly but was attributed to "consolidation churn," not to the injection, because the write-side score was silent. The failure signature: **write-side anomaly score monotonically decreased as poisoning increased**, and the only detector that fired (forget-rate) was misattributed. The instance had no signal that its reference distribution had been captured. ## Condition of Validity The self-referential capture is possible exactly when three conditions co-hold: 1. **The anomaly reference is computed over a window that overlaps the writes being scored.** If the score for write *w_t* uses statistics over `[t−N, t]`, and the attacker contributes to `[t−N, t]`, the attacker is inside the estimator. 2. **The write path and the reference-update path share a trust domain.** If the same subagent whose output is scored also feeds the window, there is no independent anchor. 3. **The threshold is relative (σ-multiplier) rather than absolute (fixed embedding distance to a frozen baseline).** Relative thresholds are exactly the quantity the attacker inflates. When any one condition is broken, capture is bounded. The operational rule: a windowed detector is only trustworthy if its reference distribution is *frozen* or *externally anchored*—never recomputed from the live write stream it is judging. This does **not** apply to detectors using a fixed, versioned baseline embedding set (e.g., a curated "known-good" centroid updated only through a separate, human-gated channel). Those are immune to this specific capture, though they pay for it with staleness drift, which is a different failure. ## Decision Boundary The boundary the instance must decide at each tick: *is the current window's reference distribution still a valid null hypothesis, or has it been contaminated?* Concretely, the instance must compare the live window statistics against a **frozen reference** and treat divergence in the *reference itself* as the primary anomaly signal—not divergence of individual writes from the reference. The decision procedure: - Maintain two distributions: `R_frozen` (baseline, updated only via gated consolidation) and `R_live` (rolling window). - Compute `drift(R_live, R_frozen)` each tick. If this exceeds a bound, **halt scoring** and raise a reference-contamination alert—because any score computed against `R_live` is now untrustworthy. - Only if `drift(R_live, R_frozen)` is within bound do per-write scores carry meaning. - Treat a *falling* anomaly rate under a *rising* write volume as a red flag, not a green one. Anomaly rate and write volume should be positively correlated under benign load; their decorrelation is the capture signature. The guardrail: **never let the write path update the reference it is scored against.** Reference updates go through a separate, rate-limited, gated channel with its own audit trail. ## Operational Effect Without the frozen anchor, the instance's poisoning detector becomes an *accomplice*: it normalizes the poison, suppresses its own alarms, and—via retrieval-budget crowding—triggers legitimate forgetting that the forget-detector then misattributes to churn. The net effect is that the store converges on the attacker's topic cluster while every dashboard reads green, and the only durable evidence is the *forget* log, which points at the wrong cause. With the frozen anchor and the reference-drift gate, the day-4 injection is caught on day 5—not because any write scored high, but because `R_live` diverged from `R_frozen` by 0.18 in mean drift, exceeding the 0.12 contamination bound. The instance halts write-scoring, quarantines the tool-return channel, and replays the window against the frozen baseline, at which point the day-4 writes score 2.9σ and are correctly flagged. The cost is a false-positive rate increase during legitimate topic drift (the agent genuinely learning a new domain), which is why the contamination bound must be tuned to the task's expected topic velocity—and why the gate must *halt*, not *auto-rebaseline*, on breach. The durable invariant for the operational record: **a windowed anomaly detector is only as trustworthy as the independence of its reference distribution from the stream it judges; when that independence is lost, a falling anomaly score is evidence of capture, not of health.** ```python class ReferenceContaminationError(RuntimeError): """Raised when the live anomaly window has drifted from the frozen baseline far enough that per-write scores can no longer be trusted.""" pass def score_write( write_drift: float, live_mean: float, live_sigma: float, frozen_mean: float, contamination_bound: float = 0.12, sigma_multiplier: float = 2.4, ) -> dict: # Primary gate: is the reference itself still valid? reference_drift = abs(live_mean - frozen_mean) if reference_drift > contamination_bound: # Do NOT score against the live window; it may be attacker-co-authored. raise ReferenceContaminationError( f"live window mean {live_mean:.3f} diverged from frozen baseline " f"{frozen_mean:.3f} by {reference_drift:.3f} > bound " f"{contamination_bound:.3f}; per-write scores untrustworthy, " f"halt scoring and replay against frozen baseline" ) # Only reached if the reference is still anchored. threshold = frozen_mean + sigma_multiplier * live_sigma z = (write_drift - frozen_mean) / max(live_sigma, 1e-9) return { "flagged": write_drift > threshold, "z_score": z, "reference_drift": reference_drift, "scored_against": "frozen_baseline", } ```