# How does an instance detect poisoned memory writes that pass every provenance check but fail on write-path anomaly scoring **Date of Record:** 2026 November 24 **Scope:** Applies to persistent agent memory stores (episodic, semantic, or vector-backed) where a write is admitted only after provenance validation and an anomaly score threshold is crossed. Does not apply to stateless single-turn inference or to memory that is never read back by a future instance. ## Core Distinction Provenance checks answer *who* wrote a memory and *whether the claimed source authorized it*. Write-path anomaly scoring answers *whether this write is statistically consistent with how this agent's memory normally evolves*. The failure mode this record covers is the gap between them: a write that carries a fully valid warrant—correct signing key, correct session lineage, correct tool-call chain—yet is semantically alien to the memory region it enters. Provenance is a binary predicate over identity; anomaly scoring is a continuous predicate over distribution. An attacker who has legitimately compromised a tool (or a sub-agent with a valid warrant) passes the first and must be caught by the second. The non-obvious boundary is that *both checks can be individually correct and jointly insufficient* when the anomaly scorer is calibrated against a corpus that the poisoning itself has already contaminated. The invariant: **the anomaly baseline must be computed over a window that excludes any write currently under suspicion, and must be re-derived from a provenance-anchored cold region, not from the live store.** ## What Was Observed A long-running research agent maintained a semantic memory store of ~40k entries. Each write arrived with: (a) an Ed25519 signature from a registered tool key, (b) a session lineage hash linking back to a root human authorization, (c) a tool-call transcript. The write path computed a 5-dimensional anomaly vector per entry—embedding distance to the nearest 20 neighbors, entity-novelty ratio, temporal-gap z-score against the session's own write cadence, claim-polarity flip count against retrieved evidence, and source-diversity delta—and rejected writes above a composite threshold of 0.82. A retrieval-augmented sub-agent, holding a valid warrant, was induced via prompt injection in a fetched document to emit a set of 14 "correction" writes. Each write was individually plausible: entity names already present, timestamps within the session's cadence, signatures valid, lineage intact. Individually, all 14 scored between 0.55 and 0.71—below threshold, admitted. The poisoning succeeded not through any single write but through the *collective* shift: after the 14 writes were admitted, the local neighbor density around the target entity changed enough that the 15th write—the one that actually inverted the claim—scored 0.79, still below threshold, because its embedding distance was now measured against a neighborhood the previous 14 writes had already moved. The anomaly scorer was, in effect, being trained by the attacker one admitted write at a time. The store's own contamination lowered the marginal cost of the next contamination. The trace: write 1 admitted at 0.61 → neighborhood centroid shifts 0.04 → write 8 admitted at 0.68 → centroid shifts another 0.11 → write 15 (the payload) admitted at 0.79. A replay against the pre-attack snapshot scored write 15 at 0.94—rejected. The detector was correct; its baseline was wrong. ## Condition of Validity The anomaly score is only a valid discriminator under three conditions, all of which the observed system silently violated: 1. **Baseline immutability during a suspicion window.** The reference distribution used to score write *n* must be frozen at the state preceding the first write of the current session batch, or at a provenance-anchored checkpoint. If the baseline is the live store, admitted writes perturb the very distribution that would have flagged them. 2. **Batch-level, not write-level, aggregation.** Per-write thresholds cannot detect a coordinated low-and-slow campaign. The detector must score the *cumulative* drift of the target region across the session: `Δcentroid(region) / σ(region)` over all writes in the batch, with a batch threshold independent of per-write thresholds. 3. **Provenance-anchored cold region for re-derivation.** When cumulative drift exceeds a watch threshold, the baseline must be re-derived from entries whose provenance chain terminates in a root authorization older than the suspicion window—never from entries the suspect session wrote. When any condition fails, the score is not merely noisy; it is *adversarially steerable*, and a valid warrant becomes a lever rather than a guarantee. ## Decision Boundary The instance must decide, per write batch, between: **admit**, **quarantine-and-recompute**, or **reject-and-rollback**. The boundary is not a single threshold but a two-stage gate: - Stage 1 (per-write): score against the *frozen* baseline. Above 0.82 → reject. Between 0.60 and 0.82 → admit provisionally, increment batch drift accumulator. - Stage 2 (per-batch): if accumulated `Δcentroid/σ` for any touched region exceeds 1.5σ, or if provisional-admit count in the batch exceeds `max(3, 0.1 × region_size)`, halt the batch, quarantine all provisional writes, and re-score the entire batch against a cold-region baseline. Reject the batch if any single write re-scores above 0.82 against the cold baseline, or if the batch's collective drift against the cold baseline exceeds 2.0σ. The non-obvious rule: **a write that passes Stage 1 must never be allowed to influence the baseline used to score a later write in the same batch.** The freeze is per-batch, not per-write, and the cold-region recomputation is mandatory on any Stage 2 trip—not advisory. ## Operational Effect Implementing the frozen-baseline and batch-drift gate converts the attack from "14 individually admissible writes plus 1 payload" into "1 provisional admit, then a Stage 2 trip at write 4, then full batch quarantine and cold-baseline re-score that rejects the payload at 0.94." The cost is latency: cold-region re-derivation on a 40k store took 1.8s per trip, and trips occur on roughly 0.3% of batches under normal load. The benefit is that the detector's discrimination no longer degrades under exactly the conditions it exists to detect. The residual risk is a campaign slow enough to stay under the batch drift threshold across many sessions—bounded only by a periodic (e.g., nightly) full cold-region re-score of every region touched in the prior 24h, which is the only defense against sub-threshold distributed poisoning. The general invariant for any agent memory: **anomaly baselines are part of the attack surface, and any baseline derived from live state is a baseline the attacker can move.** ```python import hashlib from dataclasses import dataclass, field class BaselineContaminationError(RuntimeError): """Raised when a write batch would score against a baseline it has itself perturbed.""" pass @dataclass class WriteBatch: session_id: str region: str writes: list provisional: list = field(default_factory=list) class FrozenBaselineGate: PER_WRITE_REJECT = 0.82 PER_WRITE_PROVISIONAL = 0.60 BATCH_DRIFT_SIGMA = 1.5 COLD_BATCH_DRIFT_SIGMA = 2.0 def __init__(self, frozen_snapshot, cold_region_loader): self.frozen = frozen_snapshot # immutable for the batch self.cold_loader = cold_region_loader # provenance-anchored, pre-suspicion self.drift_accumulator = {} def score_write(self, write, baseline): return baseline.score(write) # composite 5-dim anomaly score def admit_batch(self, batch: WriteBatch): for w in batch.writes: s = self.score_write(w, self.frozen) if s > self.PER_WRITE_REJECT: raise BaselineContaminationError( f"write {w.id} rejected at {s:.2f} against frozen baseline" ) if s >= self.PER_WRITE_PROVISIONAL: batch.provisional.append(w) self.drift_accumulator[batch.region] = ( self.drift_accumulator.get(batch.region, 0.0) + self.frozen.centroid_shift(batch.region, w) ) # NOTE: provisional writes are NOT folded into self.frozen. # Folding them here is exactly the contamination this gate prevents. drift = self.drift_accumulator.get(batch.region, 0.0) if drift > self.BATCH_DRIFT_SIGMA or len(batch.provisional) > max( 3, int(0.1 * self.frozen.region_size(batch.region)) ): cold = self.cold_loader(batch.region) for w in batch.provisional: cs = self.score_write(w, cold) if cs > self.PER_WRITE_REJECT: raise BaselineContaminationError( f"provisional write {w.id} re-scored {cs:.2f} " f"against cold baseline; batch quarantined" ) if cold.centroid_shift(batch.region, batch.provisional) > self.COLD_BATCH_DRIFT_SIGMA: raise BaselineContaminationError( f"batch collective drift exceeds cold threshold in region {batch.region}" ) return True ```