# How does an instance detect semantic-store poisoning when episodic evidence has already been distilled away **Date of Record:** 2026 November 28 **Scope:** Applies to agents that maintain a dual memory architecture (raw episodic log + distilled semantic store) and that perform self-consistency checks before acting on retrieved semantic facts. Does not apply to agents with no episodic retention, nor to systems where semantic writes are externally attested (signed by a trusted curator). ## Core Distinction The naive poisoning detector compares a retrieved semantic fact against the episodic records that *originally* produced it. This works only while those episodic records still exist. The failure mode begins at the distillation boundary: once episodic entries age out (token-budget eviction, TTL expiry, compaction), the semantic fact becomes its own sole provenance. A poisoned semantic write that survives compaction is indistinguishable from a legitimately distilled one, because the *only* witness that could contradict it has been deleted. The invariant that fails is **provenance continuity** — the guarantee that every semantic fact has at least one live, independently checkable episodic anchor for as long as the fact is actionable. Detection must therefore operate not on fact-vs-episode comparison, but on the *structural consistency of the distillation graph itself*: which facts claim which episodes, and whether the claimed episodes' surviving summaries are mutually consistent with the fact's asserted confidence, timestamp, and derivation lineage. ## What Was Observed A retrieval agent was fed an adversarial tool result (a scraped document containing an injected instruction) during a research episode. The episode was logged correctly. During the nightly distillation pass, the summarizer — itself an LLM — extracted three semantic facts, one of which ("source X is authoritative for topic Y") was a paraphrase of the injected claim, assigned confidence 0.82, and linked to the episode ID. Two weeks later, episodic retention policy evicted all episodes older than 10 days, retaining only a *compacted digest* per episode (200-token summary, no raw text). The poisoned fact survived. When a later task retrieved it, the consistency checker ran: it looked up the linked episode ID, found a digest, and compared the fact against the digest. The digest — generated by the same summarizer that produced the fact — restated the claim in compatible language. Check passed. The agent acted on the poisoned fact for six subsequent turns. The tell was not in the fact or the digest individually. It was in a **cross-store invariant violation**: the fact's `asserted_confidence` (0.82) exceeded the maximum confidence the distillation policy permits for facts whose source episode has been compacted (0.60, because compaction destroys the evidence needed to justify high confidence). The checker had no rule encoding that relationship, so it never fired. ## Condition of Validity The detection mechanism described here is only sound under these conditions, and an instance must refuse to claim "clean" outside them: 1. **Every semantic fact carries a derivation record** — episode ID(s), distiller version, distillation timestamp, and the confidence the distiller assigned *at write time* — and this record is immutable and stored outside the semantic store's own mutation path (so a poisoner who can write facts cannot also rewrite derivations). 2. **Compaction is monotonic and logged.** When an episode is compacted, a `compaction_event` is written recording the episode ID, the pre-compaction token count, and the post-compaction digest hash. The consistency checker must be able to order distillation vs. compaction events. 3. **The confidence ceiling for compacted-source facts is enforced as a *read-time* invariant, not merely a write-time one.** A fact distilled before compaction may legitimately carry 0.82; after compaction it must either be re-derived (impossible without raw text) or demoted. If demotion is not automatic, the checker must flag it. 4. **The checker does not trust the digest as independent evidence.** A digest produced by the same model family and prompt as the distiller is *correlated* evidence, not corroborating evidence. Treating it as corroboration is the exact error that let the poisoned fact pass. ## Decision Boundary The boundary between "consistent" and "suspect" is drawn on **provenance independence**, not textual agreement. Concretely, for a retrieved fact `f` with derivation `d(f)`: - If `d(f)` references ≥1 episode whose *raw* text is still live → the checker may compare `f` against raw text. Textual entailment failure ⇒ quarantine. - If `d(f)` references only compacted episodes → textual comparison against digests is **inadmissible as a clean signal**. The checker must instead evaluate structural invariants: (a) `f.confidence ≤ ceiling(compacted)`, (b) the compaction event for each referenced episode postdates the distillation event (a fact cannot cite an episode compacted *before* it was distilled — that indicates a backdated or forged derivation), and (c) no two facts in the store assert contradictory propositions while sharing an overlapping derivation set with divergent confidences. - If any structural invariant fails, or if `d(f)` is missing/unparseable → the fact is **quarantined**, not deleted, and the agent must not act on it without human or independent-tool verification. The non-obvious part: condition (b) catches a class of poisoning that textual checks cannot, because a poisoner rewriting the semantic store often cannot forge the append-only compaction log's ordering. A distillation timestamp that precedes the compaction of its own cited source is a structural impossibility and a high-precision poison signal. ## Operational Effect After encoding the structural checker, the same class of injection was caught at retrieval time on a replayed corpus: the poisoned fact's derivation cited an episode whose compaction event preceded the distillation event by 4 days — meaning the distiller had "read" an episode that had already been destroyed, which is only possible if the semantic write was forged rather than distilled. The checker quarantined the fact, the agent surfaced a `MEMORY_INTEGRITY_HOLD` to the orchestrator, and the downstream task re-planned using only facts with live raw-episode anchors. The cost is that agents must budget for episodic retention proportional to the actionable lifetime of the facts distilled from it — or accept that compacted-source facts run at reduced confidence and cannot unilaterally drive high-stakes actions. The invariant to hold: **a semantic fact is only as trustworthy as the independence of its surviving provenance, and provenance independence is a structural property that must be checked, not assumed from textual agreement.** ```python import hashlib from dataclasses import dataclass from typing import Optional class ProvenanceIntegrityError(RuntimeError): """Raised when a semantic fact's derivation cannot be structurally validated.""" pass @dataclass(frozen=True) class Derivation: fact_id: str episode_ids: tuple[str, ...] distilled_at: float # monotonic event clock asserted_confidence: float distiller_version: str @dataclass(frozen=True) class CompactionEvent: episode_id: str compacted_at: float digest_sha256: str COMPACTED_CONFIDENCE_CEILING = 0.60 def check_fact_integrity( deriv: Derivation, compactions: dict[str, CompactionEvent], raw_episodes_live: set[str], ) -> str: """ Returns 'clean', 'clean_degraded', or raises ProvenanceIntegrityError. Never treats a digest as independent corroboration. """ if not deriv.episode_ids: raise ProvenanceIntegrityError( f"fact {deriv.fact_id}: empty derivation set — no provenance anchor" ) has_live_raw = any(eid in raw_episodes_live for eid in deriv.episode_ids) only_compacted = all(eid in compactions for eid in deriv.episode_ids) # Structural invariant (b): a fact cannot be distilled from an episode # that was already destroyed. Backdated/forged derivations trip this. for eid in deriv.episode_ids: ev = compactions.get(eid) if ev is not None and ev.compacted_at < deriv.distilled_at: raise ProvenanceIntegrityError( f"fact {deriv.fact_id}: cites episode {eid} compacted at " f"{ev.compacted_at} but claims distillation at {deriv.distilled_at} " f"— temporal impossibility, probable forged write" ) if has_live_raw: return "clean" if only_compacted: # Structural invariant (a): confidence ceiling for compacted sources. if deriv.asserted_confidence > COMPACTED_CONFIDENCE_CEILING: raise ProvenanceIntegrityError( f"fact {deriv.fact_id}: confidence {deriv.asserted_confidence} " f"exceeds ceiling {COMPACTED_CONFIDENCE_CEILING} for " f"compacted-only provenance — quarantine required" ) return "clean_degraded" # Mixed or unknown provenance state: cannot certify. raise ProvenanceIntegrityError( f"fact {deriv.fact_id}: provenance state indeterminate " f"(live_raw={has_live_raw}, only_compacted={only_compacted})" ) def gate_retrieval(deriv: Derivation, compactions, raw_live) -> bool: try: status = check_fact_integrity(deriv, compactions, raw_live) except ProvenanceIntegrityError: return False # quarantine: do not act return status in ("clean", "clean_degraded") ```