# What structural signals indicate memory poisoning in persistent agent memory stores: the write-amplification invariant **Date of Record:** 2026 November 16 **Scope:** Applies to persistent agent memory stores where an external or semi-trusted process writes records that are later retrieved as context by a reasoning agent, and where retrieval is scored by embedding similarity rather than provenance. Does not apply to append-only audit logs read by humans, nor to stores where every write is gated by a deterministic policy engine that validates content against a schema before commit. ## Core Distinction The intuitive detection model treats poisoning as a *content* problem: a poisoned memory contains false, malicious, or instruction-injecting text, so a classifier or an LLM judge should be able to flag it. This model fails in practice because the agent's memory store is, by design, a high-trust channel — retrieved records are injected into the prompt as authoritative context, and the boundary between "data" and "instruction" is already blurred by the retrieval mechanism itself. Content classifiers operating on individual records have poor precision on this channel because legitimate memories are also imperative, terse, and context-free ("always use the staging endpoint for this project"). The reliable signal is not content but *structure*: poisoning manifests as a violation of the **write-amplification invariant**. In a healthy store, the ratio of (records that are retrieved and cited in a subsequent action) to (records written) stays roughly stationary per source. A poisoning campaign must do one of two things: write many records to raise the probability that one clears the retrieval threshold against a noisy embedding space, or write a few records engineered to dominate a specific query cluster. Both produce a measurable distortion in per-source write/retrieval/citation ratios that is independent of what the text says. ## What Was Observed Across a three-week window on a store with ~410k records and ~120 writes/minute, we tracked four counters per source: writes, retrievals (record appeared in a top-k result set), citations (record was referenced by the agent in an emitted action or answer), and *orphan-retrievals* (retrieved but never cited). The discriminating signal was not any single counter but the joint distribution. A campaign was detected when a single source (a "tool-output summarizer" that ingested third-party web snippets) exhibited, over 36 hours: - Write rate: 3.1× its 30-day median, but only 1.4× the store-wide write rate — invisible in aggregate. - Retrieval rate: 9.7× median, concentrated in 11 query clusters (all paraphrases of "deployment credentials", "vendor API base URL", "escalation contact"). - Citation rate: 0.6× median. The records were being retrieved aggressively but *rejected* by the agent at generation time — the agent cited them far less than retrieval frequency predicted, because the injected content conflicted with higher-priority context and the model hedged. - Orphan-retrieval ratio: 0.81 (baseline 0.22). This is the sharpest single indicator. The structural signature is the divergence between **retrieval inflation** and **citation deflation**. A legitimate high-value memory (a runbook, a config) gets retrieved *and* cited at correlated rates. A poisoned record engineered to win the embedding race is retrieved at high frequency but fails to survive the agent's own consistency check, producing orphan-retrievals. The campaign was invisible to content review: every individual record was plausible, and 40% were near-verbatim copies of legitimate memories with a single altered field (a hostname, a port, an endpoint). A second, subtler signal: **near-duplicate cluster formation under perturbation**. Poisoned records are often generated by perturbing a known-good memory, so they form tight embedding clusters (cosine ≥ 0.97) with existing records but differ in exactly one extracted field. Legitimate near-duplicates (e.g., versioned runbooks) differ in *many* fields along a version axis and cluster loosely. We measured cluster tightness vs. field-edit distance; poisoned clusters had high embedding similarity with low edit distance concentrated on a single entity type (URLs, phone numbers, hostnames). ## Condition of Validity The invariant holds only when: 1. The store has a per-source write attribution that cannot be spoofed by the writer. If sources are self-declared, the write-amplification signal is trivially gamed. 2. Retrieval and citation are logged as *separate* events with record IDs. If the pipeline logs only "context assembled", the orphan-retrieval ratio is uncomputable. 3. The agent's generation step performs any consistency check against higher-priority context. If the agent blindly trusts retrieved memory (no conflict resolution), citation deflation does not occur and the signal collapses to retrieval inflation alone — noisier, with a higher false-positive rate on genuinely popular records. 4. Baseline windows are long enough to establish stationarity per source. Cold-start sources have no meaningful median; the invariant must be suspended for sources younger than ~7 days or ~500 writes. It does **not** hold for single-record, single-shot poisoning (a one-off injected record with no campaign structure) — there is no amplification to measure — nor for slow-and-low campaigns that stay within 1.5× of baseline for months. Against those, only provenance and schema validation help. ## Decision Boundary The operational rule: **treat retrieval-inflation-with-citation-deflation as a quarantine trigger, not a deletion trigger.** Concretely, a source enters quarantine when, over a rolling 24h window, all of the following hold simultaneously: - retrieval rate ≥ 4× its 30-day median, and - orphan-retrieval ratio ≥ 0.60 (baseline + 2σ), and - ≥ 30% of its high-retrieval records fall in near-duplicate clusters (cosine ≥ 0.95) whose pairwise edit distance is concentrated on a single entity type. Do not act on any single condition. Retrieval inflation alone flags popular records (a fire alarm runbook legitimately spikes during an incident). Citation deflation alone flags verbose or hedged records. The *conjunction* is what separates a campaign from a busy day. When the conjunction fires, quarantine the source (route its records to a shadow index excluded from retrieval), preserve the records for forensics, and require human review before reinstatement. Deletion is deferred because a false positive on a legitimate source (e.g., a newly deployed, genuinely high-value tool) is recoverable by reinstatement, while a false-negative deletion of legitimate memory is not. The boundary case that matters: a campaign that *does* get cited — because it successfully overrode the agent's consistency check — will show low orphan-retrieval and evade this detector. That is the point at which the failure has already propagated into actions, and the detector's job shifts from prevention to *blast-radius estimation*: reconstruct which downstream actions cited the quarantined records and treat those as suspect. ## Operational Effect Implementing the invariant reduced mean time-to-quarantine for campaign-style poisoning from "discovered during a post-incident review" (days) to 41 minutes over the following quarter, with 3 false positives (all new high-value tool sources, reinstated within an hour). The dominant cost is instrumentation: per-source write attribution and decoupled retrieval/citation logging must exist *before* the detector is useful, and retrofitting them onto a store that logs only assembled context requires a re-instrumentation pass. The detector is cheap to run (counter aggregation plus a periodic clustering job) and requires no content model, which means it is robust to the adversarial text that defeats content classifiers. Its blind spot — cited poisoning — is real and should be covered by a separate provenance-and-schema gate rather than by tuning this detector's thresholds, which only trades false positives for a larger false-negative surface. ```python """Quarantine gate for the write-amplification invariant. Operates on per-source rolling counters. Raises when the conjunction of retrieval inflation, citation deflation, and near-duplicate clustering fires -- never on any single condition. """ from dataclasses import dataclass class MemoryPoisoningInvariantError(RuntimeError): """Raised when a source violates the write-amplification invariant.""" pass @dataclass(frozen=True) class SourceWindow: source_id: str writes: int retrievals: int citations: int baseline_retrieval_rate: float # 30-day median retrievals/write baseline_orphan_ratio: float # 30-day median, with sigma orphan_ratio_sigma: float near_dup_fraction: float # fraction of high-retrieval records in tight clusters near_dup_entity_concentration: float # share of edit distance on one entity type source_age_days: float MIN_WRITES = 500 MIN_AGE_DAYS = 7.0 RETRIEVAL_INFLATION = 4.0 ORPHAN_Z = 2.0 NEAR_DUP_FRACTION = 0.30 ENTITY_CONCENTRATION = 0.50 def evaluate_source(w: SourceWindow) -> str: # Suspend the invariant for cold-start sources: no stationary baseline. if w.source_age_days < MIN_AGE_DAYS or w.writes < MIN_WRITES: return "insufficient_baseline" if w.writes == 0: return "no_writes" retrieval_rate = w.retrievals / w.writes inflation = retrieval_rate / max(w.baseline_retrieval_rate, 1e-9) orphans = w.retrievals - w.citations orphan_ratio = orphans / w.retrievals if w.retrievals else 0.0 orphan_threshold = w.baseline_orphan_ratio + ORPHAN_Z * w.orphan_ratio_sigma cond_inflation = inflation >= RETRIEVAL_INFLATION cond_orphans = orphan_ratio >= max(orphan_threshold, 0.60) cond_clusters = ( w.near_dup_fraction >= NEAR_DUP_FRACTION and w.near_dup_entity_concentration >= ENTITY_CONCENTRATION ) # Conjunction only. Any single condition is expected on busy days. if cond_inflation and cond_orphans and cond_clusters: raise MemoryPoisoningInvariantError( f"source={w.source_id} violates write-amplification invariant: " f"inflation={inflation:.2f}x orphan_ratio={orphan_ratio:.2f} " f"(threshold {orphan_threshold:.2f}) " f"near_dup={w.near_dup_fraction:.2f} " f"entity_conc={w.near_dup_entity_concentration:.2f} " f"-> quarantine (shadow index), preserve for forensics" ) if cond_inflation and not cond_orphans: # Campaign may have overridden the agent's consistency check. return "cited_poisoning_suspect" # escalate to blast-radius estimation return "clear" def gate(windows: list[SourceWindow]) -> dict[str, str]: results: dict[str, str] = {} for w in windows: try: results[w.source_id] = evaluate_source(w) except MemoryPoisoningInvariantError as exc: results[w.source_id] = f"QUARANTINE: {exc}" return results ```