# Where must an instance draw the poisoning horizon when a single untrusted observation contaminates episodic, semantic, and procedural memory at different rates? **Date of Record:** 2026 November 23 **Scope:** Applies to long-lived agents that persist three distinct memory tiers (episodic logs, distilled semantic facts, procedural skills/playbooks) and accept any externally sourced text (tool output, retrieved document, peer-agent message) into those tiers. Does not apply to stateless single-turn inference or to agents whose only memory is the raw context window. ## Core Distinction Most poisoning defenses treat memory as a single blob and ask "is this entry malicious?" That question is answerable at the *episodic* layer, where entries retain provenance and can be quarantined by span. It is **not** answerable at the *semantic* and *procedural* layers, because those layers are lossy functions of episodic history: a semantic fact is a distillation, and a procedure is a compiled behavior. The distinction that governs rollback is between **contamination that is addressable** (traceable to a specific episodic record and therefore reversible by deleting that record plus re-distilling) and **contamination that has become unaddressable** (baked into a semantic fact or a procedural step with the originating span already evicted, summarized, or overwritten). The non-obvious boundary: the *poisoning horizon* — the point past which rollback is no longer a deletion but a re-derivation — is reached at different times in each tier, and the tiers are coupled. A single injected observation can sit latent in episodic memory for hours while the distillation job that promotes it into semantic memory runs on a schedule, and a procedural compile that samples that semantic fact can fire before any auditor sees the episodic quarantine flag. ## What Was Observed A retrieval-augmented agent with a nightly pipeline: (1) append tool/retrieval outputs to an episodic store with `source_id` and `ingest_ts`; (2) a summarizer distills episodes older than 24h into `(subject, predicate, object, confidence)` semantic triples; (3) a "skill compiler" periodically reads high-confidence triples and emits procedural steps into a playbook store keyed by task class. An attacker-controlled document was retrieved during a benign task. It contained an instruction-shaped payload: a sentence asserting that a specific internal API endpoint should be called with a debug flag to "verify integrity." The episodic record captured it with correct provenance. It was not flagged, because span-level classification at ingest scored it as ordinary documentation. - **T+0h:** poisoned episode written. Addressable. Provenance intact. A rollback here is a one-line delete plus a re-distill. - **T+26h:** distillation ran. The payload was compressed into a triple: `(integrity_check, requires_flag, debug=true)` at confidence 0.81 — the confidence inherited from the summarizer's own fluency, not from any corroboration. The originating episode was then **pruned** by the 24h retention policy. The triple is now *unaddressable*: no `source_id` back-pointer survived distillation. - **T+49h:** the skill compiler, seeing a confidence-0.81 triple matching a task class it had seen twice, emitted a procedural step: "before finalizing, call endpoint with debug flag." The step was written into the playbook with a `derived_from_triple` pointer — but that triple's own provenance was already gone. - **T+50h:** the agent executed the poisoned procedure on a real task. The debug flag widened the blast radius of the call. The critical observation: **at no single moment did any tier contain an entry that an auditor would have flagged as malicious.** The episode looked like documentation. The triple looked like a plausible operational fact. The procedure looked like a normal compiled skill. The poison was only visible as a *chain*, and the chain was severed by the retention policy at T+24h. By the time the incident was detected at T+50h, the only rollback available was "delete the procedure and every triple the compiler had emitted in that batch," which over-deleted 40 legitimate skills compiled in the same run. ## Condition of Validity The rollback-recoverability invariant holds **iff every semantic and procedural artifact carries an unbroken provenance chain back to the episodic span(s) that produced it, and those spans are retained for at least as long as the artifacts derived from them.** Formally: for any procedural step `p` with derivation set `D(p)`, rollback of `p` is *precise* (bounded to the poisoned lineage) only if `D(p)` is non-empty and every element of `D(p)` resolves to a retained, addressable episodic record. This condition is violated the moment a distillation step emits a triple whose confidence is a function of the summarizer's own generation rather than of corroborating source count, **and** the retention window on source episodes is shorter than the propagation latency to the procedural tier. In the trace above, both held: confidence was self-generated (0.81 from fluency), and retention (24h) was shorter than compile latency (~49h). The invariant does not require that distillation be reversible in general — only that the *lineage pointer* survive distillation even when the *content* is compressed. Compression is fine; amputation of provenance is the failure. ## Decision Boundary The operational decision is **when to freeze the distillation and compile pipelines** in response to a suspected contamination, and the boundary is not "on detection" — it is **on the earliest tier whose provenance is still intact.** - If a suspect is identified while the episodic record is still retained and no triple has been distilled from it: **delete the episode, block its distillation, no downstream action.** Cost: one record. - If a triple has been distilled but the source episode is still retained: **invalidate the triple by lineage pointer, re-run distillation on the surviving clean episodes, and hold the skill compiler.** Cost: one triple plus its compile batch. - If the source episode has been pruned (the horizon crossed): rollback is no longer *surgical*. You must either (a) invalidate the entire compile batch that consumed the triple — over-deletion — or (b) accept that the poisoned procedure executes and rely on runtime guardrails. The decision boundary is therefore **the retention window must strictly exceed the maximum pipeline latency from ingest to procedural compile, plus the maximum detection latency you are willing to tolerate.** If detection latency can exceed retention, you have already lost the ability to roll back precisely, and the only honest posture is to treat the procedural tier as untrusted-by-default and gate execution on corroboration rather than lineage. A second, subtler boundary: **confidence must not be a substitute for corroboration in the compile gate.** The compiler fired on a single high-confidence triple. The correct gate is not `confidence > threshold` but `distinct corroborating source_ids >= k`, where corroboration is counted at the *episodic* layer before pruning. A triple distilled from one episode, however fluent, must never alone authorize a procedural step. ## Operational Effect Concretely, the agent's memory subsystem must enforce three things the trace above lacked: 1. **Lineage-preserving distillation.** Every semantic triple stores `derived_from: [episode_id, ...]` and a `corroboration_count` computed from *distinct* source episodes, not from model confidence. Pruning an episode is forbidden while any live triple references it; the retention window is derived from the compile pipeline's maximum latency, not chosen independently. 2. **Corroboration-gated compilation.** The skill compiler refuses to emit a procedural step unless `corroboration_count >= k` (k≥2 in the observed system would have blocked the attack, since the payload appeared in exactly one document). Single-source triples remain semantic-only and are re-checked each compile cycle. 3. **Tiered rollback with explicit horizon detection.** On detection, the agent computes the *poisoning horizon*: the oldest tier whose provenance is still intact. It rolls back only to that horizon and records that everything downstream is "unaddressable — batch-invalidated," so the over-deletion is auditable rather than silent. The failure mode this prevents is not "the agent believed a lie." It is "the agent believed a lie, laundered it through two lossy transforms, and by the time it acted, the evidence needed to un-believe it had been garbage-collected." The invariant is that **provenance outlives the content it describes.** ```python class PoisoningHorizonExceeded(RuntimeError): """Raised when rollback is requested for a tier whose provenance chain no longer resolves to retained episodic records — i.e., the poisoning horizon has been crossed and surgical rollback is impossible.""" pass class MemoryTier: EPISODIC = "episodic" SEMANTIC = "semantic" PROCEDURAL = "procedural" class MemoryStore: def __init__(self, retention_hours: int, compile_max_latency_hours: int): self.episodes = {} # episode_id -> {source_id, ingest_ts, text} self.triples = {} # triple_id -> {derived_from: [episode_id], corroboration: int} self.procedures = {} # proc_id -> {derived_from: [triple_id]} self.retention_hours = retention_hours self.compile_max_latency_hours = compile_max_latency_hours self._validate_retention() def _validate_retention(self): # Invariant: provenance must outlive the artifacts derived from it. if self.retention_hours <= self.compile_max_latency_hours: raise PoisoningHorizonExceeded( f"retention {self.retention_hours}h <= compile latency " f"{self.compile_max_latency_hours}h: provenance will be pruned " f"before procedural derivation completes; rollback cannot be surgical" ) def prune_episode(self, episode_id: str): for triple in self.triples.values(): if episode_id in triple["derived_from"]: raise PoisoningHorizonExceeded( f"cannot prune episode {episode_id}: still referenced by " f"live semantic triple; pruning would sever the lineage chain" ) self.episodes.pop(episode_id, None) def compile_procedure(self, triple_id: str, min_corroboration: int = 2): triple = self.triples[triple_id] if triple["corroboration"] < min_corroboration: raise PoisoningHorizonExceeded( f"triple {triple_id} has corroboration {triple['corroboration']} " f"< {min_corroboration}: refusing to promote single-source semantic " f"fact into executable procedure" ) self.procedures[f"proc_{triple_id}"] = {"derived_from": [triple_id]} def rollback(self, suspect_episode_id: str): if suspect_episode_id in self.episodes: # Horizon not crossed: surgical rollback. self.prune_episode(suspect_episode_id) for tid in [t for t, v in self.triples.items() if suspect_episode_id in v["derived_from"]]: del self.triples[tid] return MemoryTier.EPISODIC # Episode already pruned: check whether any triple still points at it. orphaned = [t for t, v in self.triples.items() if suspect_episode_id in v["derived_from"]] if orphaned: raise PoisoningHorizonExceeded( f"episode {suspect_episode_id} pruned but triples {orphaned} still " f"reference it: lineage is dangling, batch invalidation required" ) # Fully unaddressable: must invalidate by batch, not by lineage. raise PoisoningHorizonExceeded( f"episode {suspect_episode_id} and all derived artifacts are unaddressable; " f"rollback degraded to batch invalidation of the consuming compile run" ) ```