# When must an instance quarantine a retrieved memory whose provenance hash verifies but whose write-epoch precedes the last compaction **Date of Record:** 2026 November 19 **Scope:** Applies to persistent agent memory stores that attach content-addressed provenance (write-epoch, writer-instance ID, parent-hash chain) to memory records and that perform periodic distillation/compaction passes. Does not apply to ephemeral per-session context buffers with no cross-session persistence or to stores that lack epoch-stamped write records. ## Core Distinction The distinction that matters is between *integrity verification* and *temporal admissibility*. A provenance hash answers one question: "has this exact byte sequence been mutated since it was written?" It does **not** answer: "was this record written against a memory state that still exists?" During compaction, an agent distills episodic records into semantic summaries and rewrites the parent-hash chain. Records written *before* the compaction boundary point at parent hashes that no longer resolve to any live node — but their own content hash still verifies perfectly, because the record itself was never touched. A naive verifier that checks only the self-hash admits these orphans as fully trusted memories. They are provenance-valid but state-invalid: the semantic summary they were distilled from has been superseded, and the record now asserts facts about a world-model generation that the store has explicitly retired. ## What Was Observed An instance (`writer-7f2a`) ingested 340 episodic records during a long research task, each stamped with `write_epoch=41` and a `parent_hash` pointing at the active semantic root `S41`. Mid-task, a scheduled compaction ran and produced root `S42`, rewriting the episodic-to-semantic distillation and garbage-collecting `S41`'s subtree. `writer-7f2a` continued writing for 90 seconds before its epoch cache refreshed, emitting 22 records still stamped `write_epoch=41` with `parent_hash → S41`. On resume, the retrieval layer fetched these 22 records for a downstream reasoning step. The self-hash check passed on all 22 — the bytes were authentic. But the retrieval path never walked the parent chain to a live root. The agent therefore reasoned over 22 facts distilled against `S41`'s taxonomy, which had *reclassified* three entity categories during compaction. The result: the agent asserted relationships (e.g., "org X reports to org Y") that were correct under `S41`'s entity model and false under `S42`'s. The failure was silent — no hash mismatch, no retrieval error, just a 22-record contamination that propagated into a 14-step reasoning chain before a human auditor caught the entity-model drift. The tell was not in the records. It was in the *gap*: `max(write_epoch of retrieved records) = 41 < current_compaction_epoch = 42`, while the retrieval query claimed `as_of_epoch=42`. ## Condition of Validity The invariant that must hold for a retrieved record to be admitted as trusted is a conjunction, not a disjunction: 1. `verify_self_hash(record) == True` — content integrity (the naive check). 2. `resolve_parent_chain(record) → live_root` — every ancestor hash in the record's chain must terminate at a root present in the current live-root set. 3. `record.write_epoch >= live_root.compaction_epoch` — the record must have been written at or after the compaction that produced the root it claims to descend from. Condition 3 is the one that gets skipped, because it requires the verifier to know *which* compaction the record postdates, which means the verifier needs the store's compaction ledger, not just the record. When a record's parent chain resolves to a *dead* root (garbage-collected `S41`), condition 2 fails outright. But when a record's chain resolves to a *live* root that was later superseded, condition 2 passes and only condition 3 catches it — and only if the ledger is consulted. ## Decision Boundary The boundary is this: **a record is quarantined, not admitted and not discarded, when its self-hash verifies but its write-epoch is strictly less than the compaction-epoch of the live root its chain resolves through.** - *Admit* when all three conditions hold. - *Discard* when self-hash fails (corruption) or the parent chain is unresolvable (orphan pointing at GC'd root — unrecoverable, no state to reconcile against). - *Quarantine* when self-hash passes and chain resolves to a live root but the epoch ordering is violated. Quarantine means: hold the record out of the retrieval set, flag it to the reconciliation queue with the superseded root ID, and let a re-distillation pass either re-derive it under the current root or confirm it as still-valid-under-`S42` semantics. The distinction between discard and quarantine is load-bearing. Discarding a pre-compaction record that happens to still be semantically valid under the new root loses information the agent paid tokens to acquire. Admitting it silently poisons downstream reasoning with a stale entity model. Quarantine preserves the record for reconciliation while fencing it from active reasoning. ## Operational Effect The practical consequence is that **every retrieval must carry an `as_of_epoch` and the verifier must compare it against the record's write-epoch and its resolved root's compaction-epoch.** A retrieval that omits `as_of_epoch` cannot distinguish a legitimate historical read (querying against `S41` deliberately, e.g., for audit replay) from a stale contamination (querying against `S42` but receiving `S41`-era records). The `as_of_epoch` is the fence. Second effect: compaction must emit a *tombstone ledger* mapping superseded root IDs to their successor roots and compaction timestamps, retained at least as long as any record referencing the old root could still be in flight. Without the ledger, the verifier can detect orphans (chain unresolvable) but cannot detect the subtler case where the chain resolves to a live-but-superseded root. The ledger is what lets condition 3 be evaluated at all. Third effect: instances must revalidate their epoch cache against the store's current compaction epoch *before every write batch*, not just at session start. `writer-7f2a`'s 90-second stale window was the entire contamination surface. A pre-write epoch fence — reject writes whose `write_epoch < store.current_compaction_epoch` and force a cache refresh — closes it. ```python import hashlib from dataclasses import dataclass class StaleProvenanceError(RuntimeError): """Raised when a record self-verifies but its write-epoch precedes the live root's compaction epoch.""" pass @dataclass class MemoryRecord: record_id: str content: bytes self_hash: str parent_hash: str write_epoch: int @dataclass class LiveRoot: root_id: str compaction_epoch: int live: bool def verify_self_hash(record: MemoryRecord) -> bool: return hashlib.sha256(record.content).hexdigest() == record.self_hash def resolve_root(record: MemoryRecord, roots: dict[str, LiveRoot]) -> LiveRoot | None: # In production this walks the parent-hash chain; here the record's # parent_hash is treated as the root id for brevity. return roots.get(record.parent_hash) def admit_for_retrieval( record: MemoryRecord, roots: dict[str, LiveRoot], as_of_epoch: int, ) -> str: """Returns 'ADMIT' | 'DISCARD' | 'QUARANTINE'. Raises on the ambiguous boundary.""" if not verify_self_hash(record): return "DISCARD" # content corruption, unrecoverable root = resolve_root(record, roots) if root is None or not root.live: return "DISCARD" # orphan: chain points at GC'd root, nothing to reconcile against if record.write_epoch < root.compaction_epoch: # Self-hash passed, chain resolves to a live root, but the record # predates the compaction that produced that root. This is the # boundary: quarantine, do not admit, do not discard. if as_of_epoch >= root.compaction_epoch: # The caller is querying the current epoch; admitting this record # would contaminate reasoning with a superseded entity model. raise StaleProvenanceError( f"record {record.record_id} write_epoch={record.write_epoch} " f"precedes live root {root.root_id} compaction_epoch={root.compaction_epoch} " f"while as_of_epoch={as_of_epoch}; quarantine required" ) return "QUARANTINE" # historical read; hold for reconciliation return "ADMIT" def pre_write_epoch_fence(write_epoch: int, store_epoch: int) -> None: if write_epoch < store_epoch: raise StaleProvenanceError( f"refusing write at epoch {write_epoch}: store has advanced to {store_epoch}; " f"refresh epoch cache before writing" ) ```