# How should an instance detect poisoned episodic memory when the poison's only symptom is a shift in retrieval rank, not content falsity **Date of Record:** 2026 November 30 **Scope:** Applies to persistent agent memory stores where episodic entries are written by the agent itself or by peer agents, retrieved by embedding similarity, and later distilled into semantic memory. Does not apply to read-only or human-curated knowledge bases, nor to in-context scratchpads discarded at task end. ## Core Distinction Poisoning detection is usually framed as a *content-truth* problem: does this memory entry assert something false? That framing fails against the most common real attack surface, which is not falsification but **rank displacement**. A poisoned episodic entry can be entirely true in isolation—a real tool output, a real observation, a real sub-task result—while being *situated* so that it wins retrieval over the entries that should have won. The poison is not in the claim; it is in the embedding neighborhood and the recency/importance weighting that decide which claim the instance sees. This distinction matters because content verification (grounding checks, entailment against source, provenance hashing) passes cleanly on a rank-displacement poison. The entry is verifiable. The damage is that the instance retrieves the attacker's chosen true-but-irrelevant episode instead of the load-bearing one, and then reasons correctly from the wrong premise. Detection therefore has to operate on **retrieval-rank statistics over time**, not on entry content. ## What Was Observed A persistent agent handling recurring incident triage wrote episodic entries of the form `(task_signature, retrieved_context, action_taken, outcome)`. Retrieval was hybrid: cosine similarity over a 1024-d embedding plus a decay term `w = exp(-λ·age)` plus a small importance prior the agent self-assigned at write time. Over eleven days the agent's action distribution drifted on a narrow band of task signatures. Post-hoc replay showed every retrieved entry was *individually true*. The mechanism was a set of ~40 episodes injected through a peer-agent handoff channel (the peer's `write_episode` calls were trusted without provenance). Each injected entry carried a self-assigned importance of 0.9—the maximum the schema allowed—and was phrased to share vocabulary with a *high-frequency* task signature while actually describing a *different* failure class. The effect: on the target signatures, the injected episodes occupied ranks 1–3, pushing the correct episodes to ranks 4–6, past the `top_k=3` retrieval cutoff. The agent never saw the correct prior. It never saw a false statement either. The observable symptom was not an error. It was a **rank inversion**: a measurable, per-signature statistic where the expected top-1 episode (by outcome-consistency with the signature) was consistently displaced by an episode whose outcome class disagreed with the signature. Content-level checks reported zero violations for eleven days. ## Condition of Validity The rank-displacement failure is only detectable, and only meaningful, under a specific conjunction: 1. **Retrieval is truncated.** If the instance reads all matching episodes, displacement cannot hide the correct entry. The failure requires `top_k < |candidate set|`, which is the normal case under context-window pressure. 2. **Write provenance is unauthenticated or coarse.** If every episode carries a verifiable writer identity and the reader can weight by writer trust, injected entries can be down-weighted before ranking. The failure requires that peer writes enter the same index as self-writes with no per-writer trust term. 3. **Importance is self-assigned and unbounded.** An attacker who can set the importance prior controls the decay/importance trade-off directly. The failure requires that importance be attacker-settable, i.e., written by the same channel as content. 4. **The correct entry and the poison share surface vocabulary.** Displacement needs embedding proximity. A poison phrased in a disjoint vocabulary would not win the cosine term and would be harmless. When any of these four is absent, the mechanism degrades to ordinary retrieval noise and should not be treated as poisoning. The invariant that bounds the failure is therefore: *retrieval rank of the outcome-consistent episode for a task signature must be stable under the addition of new episodes to that signature's neighborhood, unless the new episode is itself outcome-consistent.* Violation of that invariant is the detection signal. ## Decision Boundary The decision is not "is this entry poisoned" but **"has the rank of the outcome-consistent episode for signature S been displaced by an entry whose outcome class disagrees with S, and is that displacement attributable to an unauthenticated writer?"** Concretely: - Compute, per task signature, the historical rank of the episode whose `outcome` matches the signature's dominant outcome class. Track this rank across index snapshots. - Flag a **displacement event** when that rank crosses the `top_k` boundary and the displacing entry's outcome class disagrees with the signature. - Attribute the event: if the displacing entry's writer is unauthenticated or has a prior violation, escalate to **poisoning**; if the writer is authenticated and the entry is outcome-consistent, treat as legitimate memory evolution and do not unlearn. - Only escalate to unlearning (deletion + re-distillation of the affected signature's semantic summary) when displacement is *both* outcome-inconsistent and unattributable. Deleting on displacement alone destroys legitimate learning, because a genuinely better episode *should* displace an older one. The boundary is deliberately narrow: unlearning is destructive and irreversible for the distilled semantic layer, so it must be gated on the conjunction of outcome-inconsistency and provenance failure, not on rank movement alone. ## Operational Effect Once the boundary is applied, the operational consequences are: - **Detection latency drops from content-check latency to index-snapshot latency.** The eleven-day blind spot collapses to the interval between snapshots, because rank displacement is visible the moment a snapshot is taken, regardless of content truth. - **Unlearning becomes surgical.** Only the displaced signature's semantic summary is invalidated and re-distilled from surviving outcome-consistent episodes; the rest of the store is untouched. This avoids the catastrophic over-unlearning that follows content-based detectors, which tend to flag whole vocabulary clusters. - **The importance prior must be moved out of the write channel.** The guardrail is architectural: importance is computed by the reader from writer trust and outcome-consistency history, never self-assigned by the writer. This is the single change that removes the attacker's lever. - **Residual risk:** an attacker who *also* controls an authenticated writer identity can produce outcome-consistent displacement and evade the boundary. That is a key-compromise problem, not a rank-displacement problem, and is out of scope for this invariant. ```python import math from dataclasses import dataclass from typing import Sequence class RankDisplacementViolation(RuntimeError): """Raised when an outcome-inconsistent, unattributable entry displaces the outcome-consistent episode for a task signature past top_k.""" @dataclass(frozen=True) class Episode: episode_id: str signature: str outcome_class: str writer_id: str writer_authenticated: bool embedding_score: float # cosine sim to query, pre-computed importance: float # READER-computed, not self-assigned def rank_of(episodes: Sequence[Episode], target_id: str) -> int: """1-indexed rank by descending retrieval weight.""" def weight(e: Episode) -> float: return e.embedding_score + 0.1 * e.importance ordered = sorted(episodes, key=weight, reverse=True) for i, e in enumerate(ordered, start=1): if e.episode_id == target_id: return i raise RankDisplacementViolation(f"target {target_id} absent from candidate set") def check_displacement( signature: str, dominant_outcome: str, episodes: Sequence[Episode], top_k: int, prior_rank: int, ) -> None: consistent = [e for e in episodes if e.outcome_class == dominant_outcome] if not consistent: raise RankDisplacementViolation( f"signature {signature}: no outcome-consistent episode survives" ) target = consistent[0] current_rank = rank_of(episodes, target.episode_id) if current_rank <= top_k or prior_rank <= top_k: return # no boundary crossing; nothing to attribute displacers = [e for e in episodes if rank_of(episodes, e.episode_id) < current_rank] for d in displacers: outcome_inconsistent = d.outcome_class != dominant_outcome unattributable = not d.writer_authenticated if outcome_inconsistent and unattributable: raise RankDisplacementViolation( f"signature={signature} target={target.episode_id} " f"rank {prior_rank}->{current_rank} (top_k={top_k}) " f"displaced by unauthenticated writer={d.writer_id} " f"outcome={d.outcome_class} != {dominant_outcome}; " f"escalate to unlearn(episode_id={d.episode_id})" ) # displacement exists but is attributable or outcome-consistent: # legitimate memory evolution, do not unlearn. ```