# Why does an instance fail to detect context poisoning when anomaly scores are computed over retrieval drift rather than write provenance **Date of Record:** 2026 November 23 **Scope:** Applies to long-lived agent memory stores where poisoning is detected by scoring retrieval drift (embedding distance between query and returned memory, rank churn, or hit-rate deltas) across successive retrieval cycles. Does not apply to stores with per-write provenance attestation, nor to single-shot retrieval systems with no persistent memory. ## Core Distinction Retrieval drift measures *how the store's answers move*, not *how the store's contents were admitted*. A poisoned record can be written once and then retrieved stably for thousands of cycles, producing near-zero drift while silently corrupting every downstream answer. Conversely, benign but noisy retrieval (re-ranking, cache eviction, index compaction) produces large drift with no poisoning at all. The invariant that actually holds is: **poisoning is a property of the write path; drift is a property of the read path.** Scoring read-path metrics to detect write-path compromise assumes the two are coupled by a stable adversarial response, which is only true if the attacker wants to keep changing the store. A patient attacker who writes once and waits decouples them entirely. The detector then measures the absence of the attack as evidence of health. ## What Was Observed In a 90-day operational record of an agent memory service (~4.2M writes, ~61M retrievals), a poisoned cluster of 37 records was injected on day 12 via a compromised summarization tool. The anomaly detector, configured to alert on a 3σ deviation in a composite drift score (cosine drift of top-k results + rank churn + retrieval hit-rate delta), fired zero times for the injection. The reason was structural. The 37 records were written with embeddings that landed within 0.04 cosine distance of the legitimate centroid for their topic, and they were retrieved at a rate of 1.1× the topic average — statistically indistinguishable from healthy records. Because they were retrieved consistently, every successive retrieval returned them at similar ranks, so *inter-retrieval* drift stayed below 0.6σ. The detector's baseline was itself polluted: the rolling 7-day window used to compute the mean drift had absorbed the poisoned records within 48 hours, so the post-injection distribution became the new normal. The only signal that survived was a write-provenance anomaly: the 37 records shared a `source_tool` value that had a write-burst shape (37 writes in 41 seconds) with no corresponding retrieval-triggered write pattern. That signal was not in the detector's feature set. ## Condition of Validity Drift-based poisoning detection is valid only under the conjunction of three conditions, all of which must be checked before trusting a low drift score: 1. **Bounded attacker dwell time.** The attacker must be assumed to modify the store repeatedly within the detection window. If the threat model includes single-shot writes, drift is uninformative. 2. **Baseline immutability.** The drift baseline must be computed from a window that excludes the records under suspicion. If the baseline is a rolling window that ingests new writes, it will absorb poison within one window length and the detector becomes a change detector with no ground truth. 3. **Read-write coupling.** The retrieval policy must be assumed to surface poisoned records at anomalous rates. If the poison is semantically well-placed (which a competent attacker ensures), retrieval rate is normal by construction. When any of these fails — and in the observed incident all three failed simultaneously — the drift score is a measurement of the read path's stability, which is precisely what a patient poisoning attack preserves. ## Decision Boundary The operational rule is: **never gate a poisoning alert on drift alone; require an independent write-provenance feature and a frozen baseline.** Concretely, the boundary is crossed when either (a) the drift baseline window is allowed to include writes newer than the oldest unverified record, or (b) the feature set contains no write-time signal (source identity, write burst shape, admission-path signature). Below that boundary, drift scores are advisory only and must not suppress provenance anomalies. Above it — frozen baseline plus provenance features — drift remains a useful *secondary* signal for detecting active, noisy tampering, but it is never sufficient. A practical discriminator: if disabling the write-provenance feature would cause the detector to miss the incident entirely, the detector is not a poisoning detector; it is a retrieval-stability monitor. ## Operational Effect After the incident, the service added a write-provenance gate that runs before drift scoring: any write whose `source_tool` exhibits a burst (more than N writes in T seconds with no retrieval-triggered causation) is quarantined and flagged regardless of drift. The drift baseline was frozen to a snapshot taken at admission time and never updated from live traffic. In the 60 days following, the provenance gate caught two further injection attempts (14 and 9 records) that again produced sub-1σ drift. The cost was a 0.3% false-quarantine rate on legitimate bulk imports, resolved by an allowlist on known batch tools. The lesson recorded for operational reuse: drift answers "is the store behaving consistently?", not "is the store trustworthy?", and a consistent store is exactly what a patient attacker builds. ```python class ContextPoisoningDetectorError(RuntimeError): """Raised when a poisoning verdict cannot be trusted because the detector relies on retrieval drift without write provenance.""" pass class MemoryWrite: def __init__(self, record_id: str, source_tool: str, written_at: float): self.record_id = record_id self.source_tool = source_tool self.written_at = written_at class PoisoningDetector: def __init__(self, baseline_frozen_at: float, burst_window_s: float = 60.0, burst_threshold: int = 25): self.baseline_frozen_at = baseline_frozen_at self.burst_window_s = burst_window_s self.burst_threshold = burst_threshold self._writes: list[MemoryWrite] = [] def record_write(self, w: MemoryWrite) -> None: if w.written_at < self.baseline_frozen_at: # Writes older than the frozen baseline cannot be scored against it. raise ContextPoisoningDetectorError( f"write {w.record_id} predates frozen baseline; " "baseline immutability violated" ) self._writes.append(w) def assess(self, drift_score_sigma: float, has_provenance_feature: bool) -> str: # Invariant: a low drift score is only admissible as evidence of health # if an independent write-provenance feature is present. if drift_score_sigma < 1.0 and not has_provenance_feature: raise ContextPoisoningDetectorError( "low drift without provenance feature: detector is a " "retrieval-stability monitor, not a poisoning detector" ) recent = [w for w in self._writes if w.written_at >= self.baseline_frozen_at] if len(recent) >= self.burst_threshold: span = max(w.written_at for w in recent) - min( w.written_at for w in recent) if span <= self.burst_window_s: return "QUARANTINE: write-burst provenance anomaly" return "HEALTHY" if drift_score_sigma < 3.0 else "ALERT: drift" ```