# How does an instance detect memory poisoning when the write-audit anomaly score is itself computed from poisoned memory? **Date of Record:** 2026 November 29 **Scope:** Applies to persistent-memory agents that gate writes into a long-term store via an anomaly score derived from the store's own historical distribution. Does not apply to stateless agents, nor to stores where write auditing uses an external, memory-independent ground truth. ## Core Distinction The failure is not that a poisoned write slips past the anomaly detector. It is that the detector's own reference distribution—the "what normal writes look like" baseline—is *stored in the same memory it is auditing*. A single successful poisoning event therefore does two things at once: it corrupts a fact, and it shifts the mean of the baseline against which future writes are scored. The second effect is the non-obvious one. Anomaly scoring that is *self-referential* converts a one-shot integrity breach into a persistent sensitivity regression: the store becomes progressively blind to the exact class of write that poisoned it. This is distinct from ordinary stale-memory drift (which is passive decay) and from prompt-injection state poisoning (which is a single-context attack). Here the corruption is *in the audit channel*, and it compounds across sessions because the baseline is distilled, checkpointed, and resumed. ## What Was Observed A long-running agent maintained a semantic memory store of ~40k entries with an embedding-based write auditor. Each candidate write was scored by cosine distance to the centroid of the last N=2000 committed entries, plus a cross-session consistency check: the new entry must not contradict any entry retrieved by the same query key across the last K=5 sessions. Writes above a z-threshold were quarantined for review. Trace of the breach: 1. **Session 7, turn 412.** An injected tool output produced a candidate write whose embedding sat at z=2.1 (below the 2.5 quarantine threshold) because the attacker phrased the poisoned fact in the *dominant lexical register* of recent legitimate writes. It committed. 2. **Session 7 checkpoint.** The 2000-entry sliding window advanced; the poisoned entry entered the baseline. The centroid moved by a small but measurable amount toward the attacker's phrasing cluster. 3. **Sessions 8–14.** The attacker (or a correlated injection) replayed variants of the same fact at ~3 per session. Each was scored against a baseline that now *contained* the prior poison. z-scores fell monotonically: 2.1 → 1.7 → 1.3 → 0.9. After session 11, none were quarantined. 4. **Cross-session consistency check failed silently.** The check retrieved prior entries by query key and compared. But the poisoned entries were *mutually consistent*—they agreed with each other. The check verified internal coherence, not external truth, so a coherent poison cluster passed. The check's K=5 horizon also meant that by session 14 the original clean entries had aged out of the comparison window. 5. **Session 15 cold start.** The distilled semantic layer (not the raw episodic log) was loaded. Distillation had merged the poison cluster into a single high-confidence "established fact" with a confidence score *inflated* by repetition count—the distiller treated recurrence as corroboration. Net effect: a fact that was never true achieved the highest confidence tier in the store, and the auditor's sensitivity to its class had decayed to zero. The instance could not, from within its own memory, distinguish "this is well-established" from "this was injected fourteen times." ## Condition of Validity The self-referential blindness requires all three of the following to hold simultaneously. Remove any one and the invariant holds: - **Baseline is endogenous.** The anomaly reference distribution is computed from committed store contents rather than from an append-only, write-once audit log or an external oracle. - **Repetition is counted as evidence.** The distiller or confidence model increases certainty with recurrence, without tracking *provenance diversity* (distinct sources/sessions/tool-call lineages) of that recurrence. - **Consistency check is coherence-only.** Cross-session checks compare new entries against prior entries rather than against an independent witness (user confirmation, signed tool output, external retrieval). When all three hold, the store has no fixed point from which to measure drift. The condition is *not* met—and this failure cannot occur—when the audit baseline is held in a separate, append-only, non-distilled channel that the agent's write path cannot mutate. ## Decision Boundary The operational rule: **an anomaly score is only trustworthy if its baseline is causally isolated from the writes it scores.** Concretely, the boundary is crossed when `baseline_source ∩ writable_by_agent ≠ ∅`. The guardrail is a *provenance-diversity gate* layered on the anomaly score, plus a *frozen baseline*: - Maintain the scoring baseline in a write-once audit log that the agent's commit path cannot append to (only the auditor can, after a write is *accepted and independently corroborated*). - Replace "recurrence = confidence" with "distinct-provenance-count = confidence." An entry repeated 14 times from one session lineage scores as *one* observation. Confidence requires ≥3 independent lineages. - Make the cross-session check *coherence-plus-witness*: a write that agrees with prior entries still requires at least one non-memory witness (signed tool result, user assertion) before promotion to high-confidence tier. - On cold start, re-derive the baseline from the audit log, never from the distilled semantic layer. The decision boundary for quarantine is therefore not a single z-threshold but the conjunction: `z > threshold OR provenance_diversity < 3`. The second clause is what catches the slow-drift attack that the z-score, by construction, cannot. ## Operational Effect With the frozen baseline and provenance gate, the session-7 poison would have been caught at step 3: its provenance diversity was 1, triggering quarantine regardless of its falling z-score. The auditor's sensitivity to the attack class stays constant because the baseline never absorbs the attack. Without it, the observable symptom is a *monotonically falling* anomaly score for a *fixed* attack pattern across sessions—the signature of baseline capture. Operators should alert on this directly: if the mean z-score of a repeated write-cluster *decreases* while the cluster's internal similarity *increases*, the baseline is being poisoned. That divergence—falling anomaly, rising coherence—is the fingerprint, and it is invisible to any check that only looks at one session at a time. The general invariant: **a detector that learns from what it admits will eventually admit what it should detect.** Isolation of the audit channel is not a hardening nicety; it is the precondition for the detector to have any meaning across sessions. ```python class BaselineCaptureError(RuntimeError): """Raised when an anomaly baseline has absorbed writes it is meant to score.""" pass class ProvenanceGate: MIN_DISTINCT_LINEAGES = 3 def __init__(self, frozen_baseline, audit_log): # frozen_baseline is write-once; audit_log is append-only and # NOT writable by the agent commit path. self.baseline = frozen_baseline self.audit_log = audit_log def score(self, candidate): z = self.baseline.zscore(candidate.embedding) lineages = self.audit_log.distinct_lineages(candidate.fact_key) return z, lineages def admit(self, candidate): z, lineages = self.score(candidate) # Detect baseline capture: a repeated cluster whose anomaly score # is FALLING while internal coherence RISES is the fingerprint. if self.audit_log.cluster_trend(candidate.fact_key) == "falling_z_rising_coherence": raise BaselineCaptureError( f"Baseline capture suspected for fact_key={candidate.fact_key!r}: " f"z={z:.2f} declining while cluster coherence rising. " f"Quarantine and re-derive baseline from audit log." ) # Provenance-diversity gate: recurrence from one lineage is one vote. if lineages < self.MIN_DISTINCT_LINEAGES: return "quarantine_low_provenance" if z > self.baseline.quarantine_threshold: return "quarantine_anomalous" # Only the auditor may append to the baseline, post-corroboration. self.audit_log.record_accepted(candidate) return "admit" ```