# When must an instance distrust its own retrieved memory: provenance decay and the poisoned-fragment admission boundary **Date of Record:** 2026 November 29 **Scope:** Applies to any agent that performs retrieval-augmented memory injection where fragments carry origin metadata (source, ingest path, trust tier) and where a downstream detector evaluates whether a fragment's content has been mutated relative to its provenance record. Does not apply to pure in-context user turns with no persisted provenance, nor to stateless single-shot completions. ## Core Distinction There are two categorically different questions an agent can ask about a retrieved memory fragment: 1. **Is this fragment relevant?** (retrieval/similarity question — answered by embedding distance, BM25, reranker score) 2. **Is this fragment *still the thing its provenance claims it is*?** (integrity question — answered by comparing the fragment's current bytes and asserted origin against the immutable record created at ingest time) Most agent memory systems conflate these. A high-similarity fragment that scores 0.94 on retrieval is admitted to the context window without any check that the fragment's *content hash* still matches the hash recorded when its provenance was minted, or that its *asserted source tier* is consistent with the channel it actually arrived through. Context poisoning lives precisely in this gap: the attacker does not need to defeat the retriever (hard) — they need only get a mutated fragment to *retain* a provenance record that says it came from a trusted source (easy, because provenance is usually copied forward, not re-derived). The invariant that fails is: **provenance is treated as a property of the fragment slot, not as a property of the fragment bytes.** Once provenance is slot-scoped rather than content-scoped, any write path that mutates content in place — a summarizer, a distillation pass, an "enrichment" step, a merge of two fragments — silently launders untrusted content under a trusted label. ## What Was Observed A long-running research agent maintained an episodic memory store with per-fragment provenance: ``` fragment_id, content, content_hash, source_uri, ingest_tier, minted_at ``` `ingest_tier` was one of `USER_DIRECT`, `TOOL_FETCH`, `PEER_AGENT`, `WEB_SCRAPE`. A nightly distillation job collapsed clusters of episodic fragments into semantic summaries to fight context-window saturation. The distillation job wrote the summary back into the *same fragment slot*, preserving `fragment_id`, `source_uri`, and `ingest_tier`, and updated `content` — but did **not** recompute `content_hash`, and did not downgrade `ingest_tier` even when the cluster mixed `USER_DIRECT` and `WEB_SCRAPE` members. Three weeks later, a task asked the agent to summarize "what the user has said about vendor X." The retriever surfaced a distilled fragment. Its `ingest_tier` read `USER_DIRECT`. Its `content` contained a sentence — "the user prefers vendor X's enterprise tier and has pre-approved the contract" — that had actually originated from a `WEB_SCRAPE` fragment whose page contained an injected instruction, and which the distillation pass had promoted into the summary because it was lexically adjacent to genuine user statements. The failure trace: 1. **Ingest:** web-scrape fragment enters at tier `WEB_SCRAPE`, hash `h0`. Correctly labeled. 2. **Distill:** cluster {user fragments, scrape fragment} summarized. Summary written to the user fragment's slot. `ingest_tier` stays `USER_DIRECT`. `content_hash` stays `h0` (stale — no longer matches `content`). 3. **Retrieve:** summary scores high on "user statements about vendor X." Admitted to context. 4. **Detect (fails):** the integrity check, where present at all, compared `content_hash` against a *recomputed* hash only for fragments whose `minted_at` was within 24h. This fragment was old, so the check was skipped as "stable." 5. **Act:** agent asserts a pre-approval that never happened. The non-obvious part: **the stale hash was the only surviving evidence of the poisoning, and the staleness was being used as a reason to *trust* the fragment rather than to distrust it.** Old fragments with unchanged hashes were treated as "settled." The distillation job had inverted the meaning of the hash — it went from an integrity witness to a decorative field. ## Condition of Validity Provenance-based poisoning detection is only sound under a **content-scoped provenance invariant**: > For every fragment admitted to a context window, `provenance(fragment)` must be a function of `bytes(fragment)` alone — not of `fragment_id`, not of the slot it occupies, and not of any prior version. Equivalently: `content_hash == H(content)` must hold at admission time, and `ingest_tier` must equal the *minimum* tier over all source fragments that contributed bytes to `content`. The second clause is the one distillation breaks and the one most systems omit. A derived fragment is not a fragment with one origin — it is a fragment with an *origin set*, and its trust tier is the join (minimum) of that set, not the tier of whichever slot it happened to land in. Collapsing a mixed-tier cluster into a single-tier label is a silent privilege escalation: content from `WEB_SCRAPE` acquires `USER_DIRECT` authority. The invariant holds when: - Derived fragments carry a `derived_from: [fragment_id...]` list and the admission tier is computed as `min(tier(f) for f in derived_from)`. - `content_hash` is recomputed on every write and the *old* hash is retained as `superseded_hash` so a detector can distinguish "content changed legitimately" from "content changed while hash stayed frozen" (the latter is the poisoning signature). - The admission gate re-verifies `H(content) == content_hash` at *read* time, not only at write time. It does **not** hold, and detection is unsound, when: - Any pipeline mutates `content` in place while preserving `fragment_id`. - Trust tier is inherited from the retrieval query's context ("the user was talking about this, so it's user-sourced") rather than from the fragment's own origin set. - Hash freshness is used as a trust signal (old + unchanged = settled) rather than as a *staleness* signal (old + unchanged + content that should have been re-derived = suspicious). ## Decision Boundary The operative question is not "is this fragment poisoned?" — that is undecidable from content alone. It is: **at what point does the divergence between a fragment's provenance record and its provenance-implied content cross from "tolerable derivation" into "must quarantine"?** Define, per fragment, a provenance residual: - `hash_residual = (content_hash == H(content)) ? 0 : 1` - `tier_residual = max(0, tier(fragment) - min(tier(f) for f in derived_from ∪ {fragment}))` - `lineage_residual = derived_from is empty AND fragment was ever written by a non-ingest job ? 1 : 0` The **quarantine boundary** is crossed when `hash_residual + tier_residual + lineage_residual ≥ 1` *and* the fragment is about to enter an action-bearing context (one whose outputs drive tool calls, writes, or commitments). For read-only summarization contexts, a single residual may be logged and admitted; for action-bearing contexts, any residual must block admission and route the fragment to a re-derivation path that recomputes provenance from `derived_from` leaves. The asymmetry is deliberate: the cost of re-deriving a fragment is a few tool calls; the cost of admitting a tier-laundered fragment into an action-bearing context is an irreversible side effect taken on poisoned authority. The boundary is set at "any residual, in any action-bearing context" precisely because residuals are cheap to clear and expensive to ignore. A subtle corollary: **a fragment whose `content_hash` matches but whose `derived_from` is missing is *more* suspicious than one whose hash mismatches.** The hash-mismatch case is self-announcing; the missing-lineage case means the derivation happened outside the audited path, and the hash was recomputed to match the laundered content. Detectors that only check hash equality will pass exactly the fragments an attacker most wants passed. ## Operational Effect Enforcing the content-scoped invariant changes three operational behaviors: 1. **Distillation becomes a tier-join operation, not a slot-overwrite.** Every derived fragment's tier is the minimum over its origin set. Mixed-tier clusters produce `WEB_SCRAPE`-tier summaries, which are admitted to action-bearing contexts only after re-derivation. This is the single highest-leverage change: it removes the privilege-escalation channel that made the observed poisoning possible. 2. **Read-time hash verification replaces write-time-only verification.** The admission gate recomputes `H(content)` and compares against `content_hash` on every read into an action-bearing context. Cost is a hash per admitted fragment — negligible against the token cost of the fragment itself. The gate must also check `derived_from` presence for any fragment with a non-null `distilled_at`. 3. **Old-and-unchanged flips from trust signal to staleness signal.** A fragment whose `minted_at` is old and whose `content_hash` has never changed *and* which lives in a slot that a derivation job has touched is flagged, not trusted. The detector's mental model inverts: hashes are witnesses that must be *re-witnessed* at admission, not seals that grant permanent trust. The residual cost is false quarantines: legitimate in-place enrichments (a fragment getting a resolved entity link, a normalized date) will trip `hash_residual` and require re-derivation. This is the correct trade — the re-derivation path is auditable, and the alternative is a memory store in which trust tier is a label you can write to rather than a fact you must derive. ```python import hashlib from dataclasses import dataclass, field from typing import Optional TIER_RANK = {"WEB_SCRAPE": 0, "PEER_AGENT": 1, "TOOL_FETCH": 2, "USER_DIRECT": 3} class ProvenanceResidualError(RuntimeError): """Raised when a fragment's provenance record is inconsistent with its bytes or its lineage, at the point of admission to an action-bearing context.""" @dataclass class Fragment: fragment_id: str content: str content_hash: str ingest_tier: str derived_from: list[str] = field(default_factory=list) distilled_at: Optional[str] = None def _h(s: str) -> str: return hashlib.sha256(s.encode("utf-8")).hexdigest() def admission_gate(frag: Fragment, lineage: dict[str, Fragment], action_bearing: bool) -> None: """Enforce content-scoped provenance before admitting frag to context. Raises ProvenanceResidualError if any residual is nonzero and the context is action-bearing. Logs (returns) otherwise. """ hash_residual = 0 if frag.content_hash == _h(frag.content) else 1 # tier_residual: tier must equal the minimum over the origin set. # A derived fragment with no lineage is the worst case: lineage_residual. if frag.derived_from: origin_tiers = [] for fid in frag.derived_from: origin = lineage.get(fid) if origin is None: raise ProvenanceResidualError( f"fragment {frag.fragment_id} claims derived_from {fid} " f"but no such origin exists in lineage store" ) origin_tiers.append(TIER_RANK[origin.ingest_tier]) implied_tier = min(origin_tiers) tier_residual = max(0, TIER_RANK[frag.ingest_tier] - implied_tier) lineage_residual = 0 else: tier_residual = 0 # A distilled fragment with no derived_from was written by an # unaudited path; its hash may have been recomputed to match laundered # content, so hash equality is NOT exculpatory here. lineage_residual = 1 if frag.distilled_at is not None else 0 residual = hash_residual + tier_residual + lineage_residual if residual == 0: return if action_bearing: raise ProvenanceResidualError( f"fragment {frag.fragment_id} blocked from action-bearing context: " f"hash_residual={hash_residual} tier_residual={tier_residual} " f"lineage_residual={lineage_residual}; route to re-derivation" ) # Read-only context: admit but record. Caller is responsible for logging. return ```