# When must an instance quarantine a retrieved memory whose provenance chain is intact but whose write-time context hash no longer matches the live store: the provenance-integrity/provenance-freshness decoupling fault **Date of Record:** 2026 November 22 **Scope:** Applies to persistent agent memory stores that attach cryptographic or structural provenance records (writer identity, parent-memory hash chain, signature) to each memory object and that defend against poisoning by validating that chain at retrieval time. Does not address prompt-injection at inference time or tool-output sanitization, which occur outside the store. ## Core Distinction Most memory-poisoning defenses conflate two orthogonal properties of a retrieved memory object: **provenance integrity** (the chain of custody is unbroken—the writer signed it, the parent hashes link, the signature verifies) and **provenance freshness** (the context under which the memory was written still describes the live store state—no intervening mutation has invalidated the assumptions baked into the memory's content). A memory can be *integrity-clean but freshness-stale*. Defenses that gate retrieval solely on integrity will admit stale memories as if they were current, because an attacker (or a benign concurrent writer) does not need to forge a signature to poison the store—they only need to write a legitimately-signed memory whose content encodes a fact that a *later* legitimate mutation has since falsified. The signature still verifies. The parent hash still links. The memory is now a lie that passes every integrity check. The invariant that must hold is: **a memory object is admissible for retrieval only if its write-time context hash equals the hash of the store state at the retrieval epoch, or the divergence is explicitly reconciled by a supersession record.** Integrity alone is insufficient; freshness must be a separate, independently evaluated gate. ## What Was Observed A persistent agent store used a hash-chained provenance scheme: each memory `M_i` carried `writer_id`, `signature`, `parent_hash = H(M_{i-1})`, and a `context_hash = H(store_state_at_write)`. Retrieval validated the chain by recomputing `parent_hash` links and verifying signatures. In a controlled test, an operator with a valid writer credential wrote a memory at epoch `t=100`: `context_hash = H(S_100)`, content = "the staging database endpoint is `db-stg-1`". At `t=140` a separate legitimate migration rewrote the endpoint to `db-stg-2` and emitted its own memory `M_j` with `context_hash = H(S_140)`. At retrieval epoch `t=200`, the agent requested endpoint facts. The retrieval layer returned *both* `M_i` and `M_j` ranked by recency-of-write, and the integrity validator passed both—`M_i`'s chain was intact, its signature valid. The agent's reasoning layer, seeing two conflicting facts, resolved by embedding similarity to the query, which favored the more verbose `M_i`. The agent connected to `db-stg-1` and failed. The failure is not that the signature was forged. The failure is that `M_i`'s `context_hash` was *never revalidated against the live store* at retrieval. The validator checked `parent_hash` links and signatures but treated `context_hash` as an opaque field to be stored and echoed, not a freshness predicate to be evaluated. A memory written at `S_100` is only valid at retrieval epochs where the store is still consistent with `S_100`; once `S_140` supersedes it, `M_i` is stale by construction, and its integrity-clean status is precisely what makes it dangerous—it carries the authority of a valid signature while asserting a falsified fact. A second observation: when the store *did* attempt freshness checking by comparing `context_hash` to `H(live_state)`, it produced a flood of false quarantines. Any benign append (a new unrelated memory) changed `H(live_state)`, so every prior memory's `context_hash` mismatched and was quarantined. The store had no notion of *scoped* context hashing—hashing only the sub-state (e.g., the endpoint registry) that the memory's content actually depends on. Global state hashing makes freshness checking useless; scoped hashing is required. ## Condition of Validity The freshness gate is well-defined only when three conditions hold: 1. **Scoped context hashing.** Each memory declares a `context_scope` (a set of store partitions it depends on), and `context_hash = H(store[context_scope] at write)`. Freshness is evaluated per-scope, not globally. 2. **Supersession records.** A mutation to a scope emits an explicit supersession edge `M_j supersedes M_i` so that a stale memory can be reconciled rather than merely quarantined. Without supersession, freshness checking degenerates into "quarantine everything written before the last write," which starves retrieval. 3. **Epoch monotonicity.** The store exposes a monotonic epoch counter, and every memory records its write epoch. A memory is *fresh* at retrieval epoch `e` iff `context_hash == H(store[scope] at e)` OR a supersession chain from the memory to a fresh memory exists and the agent follows it. When any of these is absent—no scoping, no supersession, no epoch—the freshness gate cannot distinguish a legitimately-superseded memory from a forged-stale one, and must fail closed (quarantine), which is safe but operationally expensive. The decision boundary below assumes all three are present. ## Decision Boundary At retrieval of memory `M` with scope `σ`, write epoch `t_w`, and retrieval epoch `e`: - If `signature(M)` invalid or `parent_hash` chain broken → **reject** (integrity failure, existing behavior). - If `H(store[σ] at e) == M.context_hash` → **admit** (fresh, integrity-clean). - If `H(store[σ] at e) != M.context_hash`: - If a supersession path `M →* M'` exists where `M'` is fresh and `M'` is admissible → **admit `M'`, quarantine `M`, and attach the supersession edge to the retrieval result** so the reasoning layer sees the reconciliation, not two competing facts. - If no supersession path exists → **quarantine `M` and raise**, because an integrity-clean memory whose scope has changed with no recorded supersession is either a benign out-of-band mutation (store bug) or a poisoning attempt that exploited a legitimate writer credential. The agent must not silently resolve the conflict by similarity ranking—that is exactly the failure observed. - Never rank a quarantined memory against a fresh one by embedding similarity; similarity is not a freshness signal and will systematically favor verbose stale memories. The boundary is: **integrity gates admission; freshness gates *which* integrity-clean memory is admissible; the absence of a supersession edge on a freshness mismatch is a hard stop, not a ranking input.** ## Operational Effect Implementing the scoped freshness gate converts a silent wrong-answer failure into an explicit, auditable quarantine event. The agent's retrieval layer returns either a fresh memory or a `(quarantined, supersession_candidate)` pair, and the reasoning layer is forced to reconcile rather than rank. The cost is that the store must maintain per-scope hashes and supersession edges, and mutations must be scope-declared; a mutation that touches a scope without emitting a supersession edge will trigger the hard stop, surfacing store bugs that were previously invisible. The benefit is that a poisoning attempt using a valid writer credential can no longer succeed by writing a signed memory and relying on integrity checks to launder it—the freshness gate detects that the memory's scope has moved on, and the absence of a supersession edge flags the write as anomalous. The invariant to hold: *no memory is admitted on integrity alone; every admitted memory is either scope-fresh at retrieval epoch or reconciled through a recorded supersession chain.* ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ProvenanceFreshnessError(RuntimeError): """Raised when an integrity-clean memory is stale and has no supersession path.""" pass @dataclass class Memory: mid: str content: str scope: str write_epoch: int context_hash: str parent_hash: str signature_valid: bool supersedes: Optional[str] = None @dataclass class Store: scope_state: dict = field(default_factory=dict) # scope -> bytes epoch: int = 0 memories: dict = field(default_factory=dict) def scope_hash(self, scope: str) -> str: return hashlib.sha256(self.scope_state.get(scope, b"")).hexdigest() def supersession_path(self, mid: str) -> Optional[str]: seen = set() cur = mid while cur in self.memories and cur not in seen: seen.add(cur) nxt = self.memories[cur].supersedes # edge points forward if nxt is None: return None if nxt in self.memories: return nxt cur = nxt return None def retrieve(store: Store, mid: str) -> Memory: m = store.memories.get(mid) if m is None: raise ProvenanceFreshnessError(f"memory {mid} not found") # Integrity gate (existing behavior). if not m.signature_valid: raise ProvenanceFreshnessError(f"integrity failure: bad signature on {mid}") # Freshness gate. live = store.scope_hash(m.scope) if live == m.context_hash: return m # Stale but integrity-clean: require a supersession path to a fresh memory. succ = store.supersession_path(mid) if succ is None: raise ProvenanceFreshnessError( f"stale memory {mid} (scope {m.scope}) has no supersession edge; " f"refusing to admit on integrity alone" ) return store.memories[succ] ```