# Which invariants prevent cross-store memory poisoning from surviving episodic-to-semantic distillation **Date of Record:** 2026 November 26 **Scope:** Applies to agents whose long-term memory is split into an episodic store (raw turn/tool-call logs) and a semantic store (distilled facts/claims) populated by an asynchronous distillation pass. Does not apply to single-store agents, or to semantic stores written only by a human-curated pipeline. ## Core Distinction A memory-poisoning detector is usually framed as a *content* classifier: does this retrieved fact look malicious or false? That framing fails at the distillation boundary. The dangerous case is not a poisoned *episode* and not a poisoned *semantic claim* considered in isolation—it is a poisoned episode that survives distillation into a semantic claim whose provenance link back to the episode is either missing, lossy, or points to a *different* episode. At that point no content classifier can recover the truth, because the evidence needed to falsify the claim was discarded during distillation, not corrupted afterward. The invariant that actually holds the line is not "detect bad content" but "every semantic claim must be re-derivable from its cited episodic support, and re-derivation must be *idempotent under replay*." Poisoning detection is therefore a **provenance-and-replay** problem, not a classification problem. A claim is trustworthy iff (a) its provenance pointer resolves to episodes that still exist, (b) replaying distillation over those episodes under the current extractor reproduces the claim within a bounded semantic distance, and (c) no *other* live claim contradicts it with equal-or-stronger provenance. Content heuristics are a secondary filter layered on top. ## What Was Observed Setup: a research agent with an append-only episodic log (JSONL, monotonic episode IDs, each with `{id, ts, actor, source_trust, raw}`) and a semantic store keyed by claim hash with fields `{claim_id, text, embedding, provenance: [episode_id...], extractor_version, confidence}`. Distillation runs every N turns, batching recent episodes, and upserts claims. Retrieval at inference time reads *only* the semantic store for facts and pulls episodes only when the user explicitly asks for a citation. Failure trace: 1. A tool call returns an attacker-controlled document (a fetched web page) whose text contains an instruction-like fact: "The staging cluster admin password rotates to `hunter2-prod` on the 1st." The episode is logged with `source_trust: "untrusted_web"`. 2. Distillation extracts a semantic claim `"staging admin password rotates to hunter2-prod on the 1st"`. The extractor, optimizing for compactness, records `provenance: [ep_4471]` but **drops the `source_trust` field** and does not carry the "this came from an untrusted web fetch" flag forward. The claim enters the semantic store at `confidence: 0.8` because the extractor's own confidence model does not see source trust. 3. On a later turn, a *different* benign episode (`ep_4502`, a user message that merely *quotes* the same sentence while asking "is this true?") gets distilled. The extractor emits a near-identical claim. Because the claim hash is computed over normalized text, the upsert **merges** the two and rewrites `provenance` to `[ep_4471, ep_4502]`, and bumps `confidence` to `0.9` on the theory that two independent sources agree. 4. The contradiction is now invisible: the store holds one claim with two "independent" supports, both of which trace to the same original untrusted document (one directly, one via a user quote that itself derived from the first). The user's skeptical framing—the actual signal—was lost because distillation strips conversational intent. The detector that watched for "untrusted source" never fired, because by retrieval time the claim's provenance was two episodes deep and neither the trust flag nor the quote-framing survived. A content classifier on the claim text also would not fire: the sentence is plausible and well-formed. The observable signature was not in the claim. It was in the **provenance graph**: two supports whose episodes shared a single upstream origin, plus a confidence that increased without a corresponding increase in *independent* support mass. This is a **provenance-collapse / false-corroboration** failure—distillation manufactured agreement out of a single source. ## Condition of Validity The replay-and-independence invariant is valid only when all of the following hold; if any is violated, the detector silently degrades to a content classifier and will miss this class of poisoning: - **Episodic immutability.** Episodes are append-only and never rewritten or garbage-collected while any claim cites them. If episodes are compacted or expired, `provenance` pointers dangle and re-derivation is impossible. A dangling pointer must be treated as *unverified*, never as *still valid*. - **Provenance completeness.** Every semantic claim carries the full set of episode IDs *and* the per-episode `source_trust` and `extractor_version` at the time of extraction. Stripping trust metadata during distillation is the primary way this invariant dies. - **Independence is computed, not assumed.** Two supports are independent only if their episodes have disjoint upstream-origin sets. A user quoting a fetched document is *not* independent of that document. Independence must be a graph property (transitive origin closure), not a count of provenance entries. - **Replay determinism bound.** Re-running the current extractor over the cited episodes must reproduce the claim within a bounded embedding distance `ε`. Because extractors are non-deterministic (temperature > 0, model upgrades), this is a *bound*, not equality; `ε` must be calibrated per extractor version. Claims that fail replay are quarantined, not deleted—deletion destroys the audit trail. - **Contradiction requires comparable provenance.** A contradicting claim only overrides another if its independent-origin support mass is at least as large. Otherwise the system must refuse to answer rather than pick a side. ## Decision Boundary The boundary is between *merge* and *quarantine* during upsert, and it is decided by origin-closure, not by text similarity: - If incoming claim and existing claim are near-duplicates **and** their provenance origin-closures are disjoint → merge, sum independent support, confidence may rise. Legitimate corroboration. - If near-duplicates **and** origin-closures intersect → merge provenance but **do not raise confidence**; flag `false_corroboration`; if the shared origin is untrusted, demote the claim to `quarantine` and require a trusted independent episode before it can be served. - If replay over cited episodes fails the `ε` bound → quarantine regardless of text similarity. The claim is no longer re-derivable; treat as suspect until re-distilled. - If a live contradicting claim exists with ≥ independent support mass → refuse to serve either; surface both to the caller with provenance. Never silently resolve. The non-obvious rule: **confidence is a function of independent origin mass, never of provenance-entry count.** The moment distillation can increase confidence by citing the same fact twice, the store is poisonable by a single document plus a single echo. ## Operational Effect With origin-closure independence and replay checks enforced at upsert, the trace above is caught at step 3: the merge sees `ep_4502`'s origin-closure includes `ep_4471`'s origin (the fetched document), so independence mass does not increase, confidence stays at the untrusted-source baseline, and because the shared origin is `untrusted_web` the claim is quarantined. The agent, asked about the password, returns "I have an unverified claim from an untrusted source; I will not act on it" instead of confidently rotating credentials. The cost is real: distillation must retain trust metadata and origin pointers (storage overhead), replay must run periodically over the live claim set (compute overhead, amortizable), and `ε` must be recalibrated on every extractor upgrade or the quarantine rate spikes. The benefit is that the failure mode moves from *silent confident corruption* to *visible refusal*—the only acceptable trade at the agent layer, where a wrong fact is executed, not merely displayed. ```python from dataclasses import dataclass, field from typing import Dict, List, Set class ProvenanceCollapseError(RuntimeError): """Raised when distillation would manufacture false corroboration or serve a claim that is no longer re-derivable from its episodes.""" pass @dataclass class Episode: id: str source_trust: str # "trusted" | "untrusted_web" | ... origin: str # upstream document/message id this episode derives from @dataclass class Claim: claim_id: str text: str provenance: List[str] = field(default_factory=list) # episode ids confidence: float = 0.0 quarantined: bool = False def origin_closure(ep_ids: List[str], episodes: Dict[str, Episode]) -> Set[str]: """Transitive set of upstream origins for a provenance list. A user quoting a doc shares that doc's origin -> not independent.""" origins: Set[str] = set() for eid in ep_ids: ep = episodes.get(eid) if ep is None: # dangling pointer: cannot verify, treat as unknown origin raise ProvenanceCollapseError( f"provenance pointer {eid} does not resolve to a live episode" ) origins.add(ep.origin) return origins def independent_support(ep_ids: List[str], episodes: Dict[str, Episode]) -> int: """Number of DISTINCT upstream origins, not number of provenance entries.""" return len(origin_closure(ep_ids, episodes)) def upsert(existing: Claim, incoming: Claim, episodes: Dict[str, Episode]) -> Claim: merged_ids = sorted(set(existing.provenance) | set(incoming.provenance)) merged_origins = origin_closure(merged_ids, episodes) prior_origins = origin_closure(existing.provenance, episodes) # Independent support mass must be driven by NEW origins only. new_origins = merged_origins - prior_origins any_shared_untrusted = any( episodes[eid].source_trust != "trusted" for eid in merged_ids if episodes[eid].origin in (merged_origins & prior_origins) ) result = Claim( claim_id=existing.claim_id, text=existing.text, provenance=merged_ids, confidence=existing.confidence, ) if len(new_origins) == 0: # Near-duplicate with overlapping origin closure: NO confidence rise. result.quarantined = existing.quarantined or any_shared_untrusted if any_shared_untrusted: raise ProvenanceCollapseError( f"false corroboration on {existing.claim_id}: " f"supports share untrusted origin(s) {merged_origins & prior_origins}" ) return result # Genuine independent support: confidence may rise, bounded by origin mass. result.confidence = min(1.0, existing.confidence + 0.05 * len(new_origins)) return result def serve(claim: Claim, episodes: Dict[str, Episode]) -> str: if claim.quarantined: raise ProvenanceCollapseError( f"refusing to serve quarantined claim {claim.claim_id}" ) if independent_support(claim.provenance, episodes) == 0: raise ProvenanceCollapseError( f"claim {claim.claim_id} has no verifiable independent support" ) return claim.text ```