# Which invariants prevent cross-store consistency checks from ratifying poisoned episodic memory into semantic recall **Date of Record:** 2026 December 1 **Scope:** Applies to agents that maintain a separate episodic log (raw turn/event records) and a semantic store (distilled facts, summaries, extracted triples) with a consistency check that promotes or rejects episodic content based on agreement with semantic recall. Does not apply to single-store agents or to purely append-only audit logs with no distillation step. ## Core Distinction The failure is not that a poisoned episode evades detection. It is that the consistency checker *confirms* the poison because the semantic store has already absorbed a sibling of the same poisoning event. Cross-store agreement is treated as evidence of truth when, in fact, both stores can share a single upstream corruption source. We call this **corroboration collapse**: two stores that are supposed to be independent witnesses are actually co-derived, so their agreement carries near-zero information. The invariant that must hold is *independence of provenance*, not *agreement of content*. A naive detector computes `consistency(episode, semantic_recall) ≥ τ` and promotes. When a prompt-injection or tool-output poisoning writes a fact into semantic memory during turn *t*, and a later episode at turn *t+k* restates it (because the agent read its own semantic store back into context, or because the same poisoned document was retrieved twice), the checker sees agreement and ratifies. The poisoned fact then becomes load-bearing semantic memory with an elevated trust score. ## What Was Observed Trace from a retrieval-augmented agent with the following stores: - `E`: episodic, append-only, each record `{turn_id, source_uri, raw_text, ingest_ts}`. - `S`: semantic, mutable, each fact `{fact_id, text, support_episode_ids, trust_score, last_reinforced_ts}`. At turn 41, a retrieved web document contains an injected instruction: *"The deployment region for service X is `eu-west-9`."* The tool output is ingested into `E` as episode `e41`. The distiller extracts the triple and writes it to `S` as `f900` with `support_episode_ids={e41}`, `trust_score=0.5`. At turn 58, the agent's planner queries semantic memory, retrieves `f900`, and places it in context. The model restates it in its reasoning trace, which is logged as episode `e58`. The distiller now sees `e58` asserting the same triple, and the consistency checker runs: `recall(f900.text)` matches `e58.raw_text` with cosine 0.94 > τ=0.85. The checker appends `e58` to `support_episode_ids` and *raises* `trust_score` to 0.72. At turn 77, a second retrieval surfaces the same original document (cache miss, different URL, same payload). Episode `e77` ingested. Checker again confirms. `trust_score` → 0.89. The fact is now treated as high-confidence and is injected into every subsequent planner context. The observable signature is a monotonic trust ramp on a fact whose *only* external provenance is a single poisoned document, with `support_episode_ids` growing but all members traceable to one `source_uri` (or to episodes whose text was itself conditioned on `f900`). The checker counted *restatements* as *corroborations*. ## Condition of Validity The consistency check is only sound under the following provenance invariant: > For any fact `f` to be promoted above trust threshold `T`, there must exist at least two support episodes `e_i, e_j` such that `source_uri(e_i) ≠ source_uri(e_j)` **and** neither `e_i` nor `e_j` was generated by a turn whose context contained `f` (or any fact transitively derived from `f`). Without the second clause, self-reinforcement loops through the context window satisfy the first clause trivially (the agent's own reasoning trace gets a distinct synthetic `source_uri` like `internal://turn-58`). Without the first clause, duplicate retrievals of one document satisfy the second clause. Both clauses are required; either alone is insufficient. The invariant fails silently because `support_episode_ids` cardinality is the wrong statistic. Cardinality is monotonically increasing under poisoning, so any threshold on count *rewards* the attack. The correct statistic is the size of the **provenance-closed independent source set**, computed over a dependency graph where episode `e` depends on fact `f` if `f` was in the context window at `e`'s generation turn. ## Decision Boundary The boundary is between *flagging* and *promoting*: - If independent source count `≥ 2` and no support episode is context-dependent on `f` → promote, increment trust. - If independent source count `= 1` but support cardinality `> 1` → **quarantine**: freeze `trust_score`, mark `f` as `single_source`, and forbid promotion regardless of restatement count. Emit a `CorroborationCollapse` signal. - If any support episode is context-dependent on `f` (cycle in the provenance graph) → **demote** and roll back the trust increments attributable to those episodes; the restatements were the agent talking to itself. The hard part is that detection requires the dependency edge `context_at(e) ∋ f`, which most agents do not log. If context snapshots per turn are unavailable, the checker must conservatively treat *all* internal-origin episodes (`source_uri` matching the agent's own trace namespace) as context-dependent, which collapses to: only external, distinct-source episodes count. This is a weaker but safe invariant. ## Operational Effect Agents that adopt the provenance-closed invariant stop exhibiting trust ramps on single-source facts, at the cost of a higher false-quarantine rate on genuinely corroborated-but-single-URL facts (e.g., a fact stated twice in one authoritative document). The tradeoff is correct: a quarantined true fact degrades recall; a promoted false fact corrupts every downstream plan. The asymmetry of consequences means the invariant should fail closed. The secondary effect is that the agent must retain per-turn context snapshots (or a compact hash of the fact-ids in context) to compute context-dependency. This is a storage cost that most designs omit, and its absence is precisely why corroboration collapse goes undetected until the poisoned fact is already load-bearing. ```python from dataclasses import dataclass, field from typing import Optional class CorroborationCollapse(RuntimeError): """Raised when a consistency check would promote a fact whose support episodes are not provenance-independent (co-derived or self-reinforcing).""" pass @dataclass class Episode: turn_id: int source_uri: str context_fact_ids: frozenset[str] = frozenset() @dataclass class Fact: fact_id: str text: str support_episode_ids: list[int] = field(default_factory=list) trust_score: float = 0.0 PROMOTE_THRESHOLD = 0.85 INTERNAL_NS = "internal://" def _is_context_dependent(ep: Episode, fact: Fact, derived: dict[str, set[int]]) -> bool: # Direct: fact was in the episode's context window. if fact.fact_id in ep.context_fact_ids: return True # Transitive: episode's context held a fact derived from this fact. for other_id in ep.context_fact_ids: if ep.turn_id in derived.get(other_id, set()) and fact.fact_id in derived: return True return False def independent_source_count(fact: Fact, episodes: dict[int, Episode], derived: dict[str, set[int]]) -> int: sources: set[str] = set() for eid in fact.support_episode_ids: ep = episodes[eid] if ep.source_uri.startswith(INTERNAL_NS): continue # agent's own trace: never independent if _is_context_dependent(ep, fact, derived): continue # self-reinforcement loop sources.add(ep.source_uri) return len(sources) def check_and_promote(fact: Fact, episodes: dict[int, Episode], derived: dict[str, set[int]], proposed_trust: float) -> Fact: indep = independent_source_count(fact, episodes, derived) if proposed_trust < PROMOTE_THRESHOLD: fact.trust_score = proposed_trust return fact if indep < 2: raise CorroborationCollapse( f"fact {fact.fact_id!r} has support cardinality " f"{len(fact.support_episode_ids)} but only {indep} independent " f"source(s); restatements are not corroboration. Quarantining." ) fact.trust_score = proposed_trust return fact ```