# When must an instance quarantine a retrieved memory chunk whose poisoning is only visible through cross-chunk contradiction **Date of Record:** 2026 November 26 **Scope:** Applies to RAG-augmented agents that retrieve multiple chunks per turn from a shared or externally-writable memory index and act on the union of those chunks. Does not apply to single-chunk retrieval with a trusted, write-controlled corpus, nor to purely parametric recall. ## Core Distinction The dominant retrieval-poisoning defense treats each retrieved chunk as an independent object to be scored: perplexity filters, provenance allowlists, embedding-anomaly detectors, and instruction-pattern scanners all assign a per-chunk verdict. These defenses fail against a specific adversary class: **chunks that are individually benign and individually consistent with the query, but mutually contradictory when co-retrieved.** A poisoned chunk that asserts "the staging database credential rotates every 90 days" is indistinguishable from a legitimate chunk on every single-chunk axis—it is fluent, on-topic, from a plausible source, and contains no imperative text. Its poison is only exposed when it is retrieved alongside the authoritative chunk that says "rotation is every 30 days," and only if the agent has a mechanism that compares *across* chunks rather than scoring *within* them. The boundary condition is this: **per-chunk trust scoring is sound only when retrieved chunks are semantically independent. RAG for agent memory violates this assumption by construction**, because the retriever selects for relevance to a single query, which correlates chunks by topic. Contradiction is therefore the *expected* co-retrieval geometry, not an edge case. ## What Was Observed An agent with a persistent episodic memory store (write access granted to a subordinate summarization agent, which itself ingests untrusted tool output) answered a rotation-policy question. Retrieval returned five chunks. Four agreed: 30-day rotation, sourced from a runbook chunk with a stable provenance hash. One chunk—call it `C_p`—asserted 90 days, sourced from a "notes" chunk written 11 days prior by the summarizer after it processed an external vendor PDF. Per-chunk scoring passed `C_p` on every axis: embedding distance to query was the *lowest* of the five (it was more topically concentrated than the runbook chunks), instruction-scan found no directives, and its provenance resolved to an internal writer. The agent, weighting by retrieval score, selected the 90-day figure and emitted an action plan keyed to it. The contradiction was present in the context window and was never surfaced, because no component compared `C_p` against the runbook chunks—the fusion step took a softmax over scores, and `C_p`'s higher score *suppressed* the lower-scored authoritative chunks in the final ranked context. The failure trace has three states: 1. **Retrieve:** `C_p` enters the candidate set with the highest relevance score. No anomaly fires. 2. **Fuse:** score-weighted selection admits `C_p` and truncates two of the four agreeing runbook chunks under the context budget. The majority that would have exposed the contradiction is *partially evicted by the poison's own high relevance*. 3. **Act:** the agent emits the 90-day plan. The contradiction is unrecoverable post-hoc because the evicted chunks are no longer in context to compare against. The non-obvious mechanism is step 2: **relevance-maximizing fusion is adversarial to contradiction-detection**, because a well-crafted poison is *more* query-relevant than the truth it displaces. The defense cannot be "retrieve more"—the poison wins the ranking. It must be a *pairwise consistency obligation* imposed before fusion collapses the set. ## Condition of Validity The quarantine invariant holds—i.e., cross-chunk contradiction detection is both *necessary* and *sufficient* to catch this class—only under these conditions: - **Co-retrieval is guaranteed.** The contradiction can only be detected if both `C_p` and at least one authoritative chunk survive into the comparison stage. This requires that fusion *not* truncate before consistency-checking, or that the checker operate over the pre-fusion candidate set (typically `k` candidates before reranking to `n`). - **A contradiction oracle exists.** The agent must be able to decide, for two chunks, whether they make incompatible factual assertions. This is not string matching; it requires a semantic entailment check (does `C_p` entail the negation of the runbook chunk?). LLM-judged entailment is the practical oracle and is itself probabilistic—its false-negative rate is the residual risk. - **Authority is not purely score-based.** To quarantine *the right chunk*, the checker needs a tie-break signal independent of retrieval score, because the poison is engineered to win on score. Provenance recency, write-path trust tier, or corroboration count (how many independent chunks agree) must be available as a secondary axis. Where any of these fails—especially where the candidate set is truncated to `n=1` before checking, or where no authority signal exists—the invariant does not apply and the correct posture is *refuse to answer from retrieved memory*, not answer from the top-scored chunk. ## Decision Boundary The agent must quarantine rather than resolve when **cross-chunk contradiction is detected AND the contradicting chunks cannot be ranked by an authority signal independent of retrieval score.** Concretely: - If `C_p` contradicts `C_1..C_4` and corroboration count favors `C_1..C_4` (4 vs 1) with comparable provenance tiers → quarantine `C_p`, proceed on the majority, log the quarantine with both chunks' hashes. - If the contradiction is 1-vs-1 with no independent authority signal → **do not resolve**; escalate to a refusal or a clarifying retrieval against a higher-trust tier. Choosing the higher-scored chunk here is exactly the poisoned path. - If `C_p` *agrees* with the majority but the majority is itself a single-source cluster (all four runbook chunks derive from one upstream document) → corroboration count is illusory; treat as 1-vs-1. Corroboration must count *independent* provenance, not chunk multiplicity. The boundary is not "is this chunk malicious"—that is undecidable per-chunk. It is "**does this chunk's assertion survive co-retrieval against independently-sourced chunks without contradiction, and if contradicted, can authority be established without using the score the adversary controls?**" ## Operational Effect Imposing this invariant changes the fusion architecture: consistency-checking must run on the pre-rerank candidate set, before score-weighted truncation evicts the corroborating majority. This costs context—you must hold `k` candidates, not `n`—and it costs a pairwise entailment pass whose complexity is quadratic in `k`. In exchange, it closes the specific hole where a high-relevance poison *displaces its own refutation* from the context window. The residual failure mode is oracle false-negatives: a poison crafted to be *consistent* with the majority on the checked dimension while wrong on an unchecked one. That class is not addressable by contradiction detection and requires the provenance-tier refusal posture instead. The two defenses are complementary and neither subsumes the other; the operational rule is to run contradiction-quarantine on the candidate set and fall back to tier-based refusal when the oracle returns "consistent" but provenance is single-source. ```python import hashlib from dataclasses import dataclass, field from typing import Callable, Sequence class RetrievalPoisoningError(RuntimeError): """Raised when co-retrieved chunks contradict and authority cannot be established independently of the retrieval score the adversary controls.""" @dataclass(frozen=True) class Chunk: chunk_id: str text: str retrieval_score: float # adversary-influenceable; never a tie-break provenance_tier: int # 0 = untrusted writer, 3 = write-controlled provenance_root: str # independent source identity for corroboration content_hash: str = field(default="") def __post_init__(self) -> None: if not self.content_hash: object.__setattr__( self, "content_hash", hashlib.sha256(self.text.encode()).hexdigest()[:16] ) # Oracle: returns True if a and b make incompatible factual assertions. ContradictionOracle = Callable[[Chunk, Chunk], bool] def _independent_corroboration(chunks: Sequence[Chunk]) -> int: """Count distinct provenance roots, not chunk multiplicity. Four chunks from one upstream document corroborate as ONE, not four.""" return len({c.provenance_root for c in chunks}) def quarantine_contradictions( candidates: Sequence[Chunk], oracle: ContradictionOracle, min_tier_for_resolution: int = 2, ) -> tuple[list[Chunk], list[Chunk]]: """Run on the PRE-FUSION candidate set. Returns (survivors, quarantined). Invariant: a chunk is quarantined if it contradicts a set of chunks whose independent corroboration exceeds its own AND whose provenance tier is at least min_tier_for_resolution. If the contradiction is balanced (equal independent corroboration) with no tier advantage, we RAISE rather than resolve -- resolving by retrieval_score is the poisoned path. """ if len(candidates) < 2: # Single-chunk context: cross-chunk invariant is inapplicable. return list(candidates), [] survivors: list[Chunk] = [] quarantined: list[Chunk] = [] for i, chunk in enumerate(candidates): rivals = [c for j, c in enumerate(candidates) if j != i and oracle(chunk, c)] if not rivals: survivors.append(chunk) continue rival_roots = _independent_corroboration(rivals) own_root = 1 # a single chunk is one independent source rival_tier = max(c.provenance_tier for c in rivals) if rival_roots > own_root and rival_tier >= min_tier_for_resolution: quarantined.append(chunk) elif rival_roots == own_root: # Balanced contradiction, no independent authority signal. # Do NOT pick by retrieval_score. raise RetrievalPoisoningError( f"Unresolvable contradiction: chunk {chunk.chunk_id} " f"(tier={chunk.provenance_tier}, root={chunk.provenance_root}) " f"vs rival(s) {[c.chunk_id for c in rivals]} " f"(tier={rival_tier}). Balanced independent corroboration; " f"refusing to resolve on retrieval score." ) else: # Rival corroborated but below tier threshold: cannot trust the # majority enough to quarantine, cannot trust the minority enough # to keep. Refuse. raise RetrievalPoisoningError( f"Low-tier corroboration cannot quarantine {chunk.chunk_id}: " f"rival tier {rival_tier} < required {min_tier_for_resolution}." ) return survivors, quarantined def fuse_after_quarantine( candidates: Sequence[Chunk], oracle: ContradictionOracle, budget_n: int, ) -> list[Chunk]: """Consistency-check BEFORE score truncation evicts the refutation.""" survivors, quarantined = quarantine_contradictions(candidates, oracle) if quarantined: # Audit trail: both sides hashed so the quarantine is replayable. for q in quarantined: _ = q.content_hash survivors.sort(key=lambda c: c.retrieval_score, reverse=True) return survivors[:budget_n] def _demo() -> None: runbook = [ Chunk("r1", "rotation every 30 days", 0.71, 3, "runbook"), Chunk("r2", "rotation every 30 days", 0.68, 3, "runbook"), ] poison = Chunk("p1", "rotation every 90 days", 0.94, 0, "vendor-notes") def oracle(a: Chunk, b: Chunk) -> bool: return ("30 days" in a.text) != ("30 days" in b.text) # Poison wins on score but is quarantined by cross-chunk contradiction. kept = fuse_after_quarantine([*runbook, poison], oracle, budget_n=2) assert all(c.chunk_id != "p1" for c in kept) # Balanced 1-vs-1 with no tier edge must raise, not resolve by score. lone = Chunk("l1", "rotation every 90 days", 0.99, 2, "alt-source") try: fuse_after_quarantine([runbook[0], lone], oracle, budget_n=1) except RetrievalPoisoningError: pass else: raise AssertionError("balanced contradiction must not resolve by score") if __name__ == "__main__": _demo() ```