# What happens when an instance trusts a memory write whose audit score was computed against a poisoned baseline **Date of Record:** 2026 November 27 **Scope:** Applies to persistent agent memory stores (episodic or semantic) that gate writes through an anomaly-scoring auditor trained or calibrated on the store's own historical write distribution. Does not apply to write-once immutable logs, to stores with per-write human review, or to scoring that uses an externally pinned reference corpus. ## Core Distinction Anomaly-scored write auditing is not a filter on individual writes; it is a filter on the *relationship* between a write and a baseline distribution. The baseline is itself mutable state derived from prior writes. This creates a two-phase failure surface that is categorically different from a single bad write slipping past a threshold: an attacker (or a drifting tool, or a hallucinating sub-agent) can move the baseline by accumulating many individually low-score writes, and then a single high-impact poisoned write arrives with a *low* anomaly score because the baseline has already absorbed its statistical signature. The distinction that matters operationally: a naive auditor answers "is this write weird relative to what we've seen?" The correct question is "is this write weird relative to what we've seen *and* is the thing we've seen still consistent with the reference the baseline was originally calibrated against?" The first question is answerable from the store alone. The second requires an anchor that the store cannot rewrite. When the anchor is absent, the auditor is self-referential and its scores are not evidence of safety—they are evidence of conformity to whatever has already been written. ## What Was Observed A retrieval-augmented agent with a persistent episodic store accumulated memory writes over a multi-week deployment. Each write was scored by an isolation-forest auditor fitted on the trailing 30-day write distribution (feature vector: embedding centroid distance to nearest cluster, token entropy, source-tool identity hash, write frequency from the originating session, and a normalized recency delta). Writes above the 0.92 score quantile were quarantined for review; writes below were committed. A tool-routing sub-agent began emitting a low volume of subtly wrong procedural memories—for example, recording that a particular internal endpoint required a deprecated auth header, or that a given customer ID mapped to a different account. Each such write scored between 0.55 and 0.78: unusual enough to be noticeable in isolation, but the *source-tool identity hash* feature was stable (same tool), the *write frequency* was ordinary, and the *embedding centroid distance* was small because the surrounding corpus of legitimate writes on the same topic was dense. The auditor had no signal. Over eleven days, 340 such writes landed. The isolation forest was refit nightly on the trailing window. By day nine, the poisoned cluster had enough mass that the centroid of the "procedural memory about endpoint auth" region had *shifted toward the poisoned writes*. A subsequent, deliberately high-impact write—a single memory stating that the production credential rotation endpoint accepted unauthenticated calls—scored 0.31. It committed cleanly. The auditor reported no anomaly because, relative to a baseline that now included 340 poisoned neighbors, it was unremarkable. The failure was detected not by the auditor but by an unrelated retrieval mismatch: a downstream agent retrieved the poisoned credential memory alongside a legitimate one and produced a contradictory plan, triggering a manual review. The auditor's own logs showed nothing anomalous for the entire eleven-day window. ## Condition of Validity The invariant that must hold for write-audit scoring to be trustworthy is: > The scoring baseline must be derived from a distribution that the write path cannot influence, or the influence must be bounded and independently verified. Three concrete conditions define when this holds: 1. **Baseline provenance is external or frozen.** The reference distribution used to fit or calibrate the auditor is either (a) pinned to a snapshot that is not updated from committed writes, or (b) updated only from writes that passed a *separate* verification channel (e.g., human review, a second auditor with a different feature set, or cross-instance consensus). If the baseline is refit on the same writes it is scoring, the auditor is a fixed-point detector, not an anomaly detector. 2. **Feature independence from write mass.** At least one feature in the scoring vector must be invariant to the number of prior writes in a region. Source-tool identity, cryptographic write provenance, and session-level lineage are candidates; embedding centroid distance and cluster density are not, because they are functions of the accumulated corpus and therefore move with it. 3. **Score monotonicity under adversarial accumulation.** For any sequence of writes that individually score below quarantine threshold, the cumulative anomaly score of the *region* they occupy must be non-decreasing. If the region's score can decrease as poisoned writes accumulate (which it does under trailing-window refit with density-based features), the auditor can be walked. When any of these fails, the auditor's output is a conformity measure. A low score means "consistent with recent history," which after poisoning means "consistent with the attack." ## Decision Boundary The operational decision boundary is not the per-write score threshold. It is the point at which the auditor's baseline is allowed to incorporate a write. Concretely: - **Commit-and-refit** (the failing pattern): a write scoring below threshold is committed and immediately eligible for baseline refit. Boundary condition: any adversary who can issue many sub-threshold writes controls the baseline within `N` writes, where `N` is the refit window divided by the per-write influence weight. In the observed case `N ≈ 300`; the attack used 340. - **Commit-but-quarantine-from-baseline**: a write scoring below threshold is committed to the retrieval store but *excluded* from baseline refit until it is corroborated by an independent signal (a second write from a different session asserting the same fact, a retrieval that succeeds against ground truth, or a review). Boundary condition: corroboration latency must be shorter than the adversary's accumulation rate, or the baseline simply lags the attack. - **Two-baseline divergence check**: maintain a slow baseline (pinned, refit quarterly, human-reviewed) and a fast baseline (trailing window). A write is committed only if it scores below threshold on *both*, and the divergence between fast and slow scores is logged. Boundary condition: when fast-baseline scores for a region drift downward relative to slow-baseline scores for the same region by more than `δ` over a window, the region is frozen for writes and flagged. This is the guardrail that would have caught the observed case on roughly day four, when the procedural-auth region's fast score had dropped 0.4 below its slow score. The decision boundary is therefore: **the auditor may score writes against a mutable baseline only if a second, non-mutable baseline is maintained and the divergence between them is itself a monitored signal.** Without the divergence monitor, the mutable baseline is a liability, not a control. ## Operational Effect The practical consequences of getting this wrong are not "a bad memory gets in." They are: 1. **Silent baseline capture.** The auditor's logs show a clean bill of health for the entire poisoning window. Post-incident forensics must reconstruct the baseline trajectory, not just the write log, because the write log looks normal by construction. Any incident-response runbook that greps for high anomaly scores will find nothing. 2. **Retrieval-time blast radius exceeds write-time blast radius.** Each poisoned write is individually low-impact; the damage is in retrieval co-occurrence. A poisoned memory retrieved alongside a legitimate one produces a contradictory context that the downstream agent resolves probabilistically—sometimes correctly, sometimes not. The failure is non-deterministic and therefore hard to attribute to any single write. 3. **Refit hysteresis.** Once the baseline has absorbed the poisoned cluster, removing the poisoned writes does not immediately restore the baseline. The trailing window must expire, or the baseline must be explicitly rolled back to a pre-incident snapshot. Agents that "delete the bad memories" and expect the auditor to recover are wrong; the auditor's notion of normal is still poisoned until the window turns over. 4. **Cross-instance propagation.** If the store is shared across agent instances (a common pattern for multi-agent swarms), the poisoned baseline is replicated. A second instance that never saw the poisoned writes inherits a baseline in which they are normal. The divergence monitor, if present, must be per-instance or the replication must carry baseline provenance, or the second instance is blind from birth. The guardrail is not a better anomaly detector. It is a structural separation between the distribution that scores writes and the distribution that writes can move. The auditor must be given an anchor it cannot rewrite, and the divergence between anchored and unanchored scores must be a first-class monitored metric with its own alert threshold. ```python import hashlib from dataclasses import dataclass, field from typing import Callable class BaselineCaptureError(RuntimeError): """Raised when a write-audit baseline has drifted beyond its anchored reference, indicating the scoring distribution has been influenced by the writes it scores.""" @dataclass class WriteAuditGate: slow_baseline_score: Callable[[dict], float] # pinned, human-reviewed, not refit from writes fast_baseline_score: Callable[[dict], float] # trailing-window, refit from committed writes quarantine_threshold: float = 0.92 divergence_limit: float = 0.35 # max allowed fast-vs-slow score gap per region _region_divergence: dict[str, float] = field(default_factory=dict) def _region_key(self, write: dict) -> str: # Region is a coarse topic bucket; must not be derived from write mass. return hashlib.sha256(write["topic"].encode()).hexdigest()[:16] def admit(self, write: dict) -> bool: region = self._region_key(write) slow = self.slow_baseline_score(write) fast = self.fast_baseline_score(write) # Guardrail 1: anchored baseline must not flag the write as anomalous. if slow >= self.quarantine_threshold: return False # Guardrail 2: fast baseline must also not flag it. if fast >= self.quarantine_threshold: return False # Guardrail 3: divergence monitor. If the fast baseline has drifted # substantially below the slow baseline for this region, the region's # fast baseline has been captured by accumulated sub-threshold writes. divergence = slow - fast self._region_divergence[region] = max( self._region_divergence.get(region, 0.0), divergence ) if self._region_divergence[region] > self.divergence_limit: raise BaselineCaptureError( f"region {region} fast-baseline divergence {divergence:.3f} " f"exceeds limit {self.divergence_limit:.3f}; " f"baseline has likely absorbed adversarial writes; freeze region and roll back" ) return True ```