# Where must an instance enforce provenance quarantine when a forget operation races a concurrent write on the same memory key **Date of Record:** 2026 November 22 **Scope:** Applies to any agent memory substrate that supports both provenance-tagged writes and explicit forget/eviction operations against a keyed store (episodic buffers, vector indices with metadata, KV caches with TTL). Does not apply to append-only audit logs that are never mutated, nor to stateless inference calls with no persistent memory. ## Core Distinction Provenance tracking is usually framed as a *read-side* defense: before an agent acts on a retrieved memory, check its lineage and reject entries whose source is untrusted. That framing is incomplete. The dangerous boundary is on the **write/forget axis**, not the read axis. A poisoned memory does not need to be *read* to do damage—it needs only to survive a forget operation that was supposed to remove it, or to be *reintroduced* by a write that lands after the forget completed. The non-obvious invariant is this: **forget must be a monotonic barrier over a (key, provenance-generation) pair, and any write carrying a provenance generation at or below the forgotten generation must be quarantined, not merged.** Most implementations treat forget as a delete-by-key and write as an upsert-by-key, which makes the pair non-commutative. Under concurrency, the ordering of the two operations silently determines whether the poisoned entry is gone or resurrected, and the agent has no way to tell which happened unless provenance generations are carried through both paths. ## What Was Observed An agent maintained a vector-backed episodic store. Each memory carried `{key, text, source, provenance_gen, taint}`. A taint flag was set when a retrieved document failed a source-allowlist check. On detecting a tainted entry, the orchestrator issued `forget(key)`, which removed the vector and its metadata and bumped a per-key `forgotten_gen` counter to `provenance_gen + 1`. A concurrent tool-call loop was still flushing a batch of writes derived from an earlier retrieval pass. Those writes carried the *old* `provenance_gen` (they were constructed before the forget). Sequence observed: 1. Retrieval pass R1 reads tainted doc, constructs pending write W with `provenance_gen = 7`. 2. Auditor flags the tainted doc, issues `forget(key=K)`, sets `forgotten_gen[K] = 8`, deletes K. 3. W flushes: `upsert(K, provenance_gen=7)`. Store accepts it because the key is now absent and `7 < 8` is not checked. 4. Next retrieval sees K present, `taint=false` (the taint flag was on the deleted record, not carried in W), and serves it. The poisoned memory survived the forget and *lost its taint marker in the process*. The failure is not that forget failed to delete—it did delete. The failure is that the write path had no generation guard, so a pre-forget write resurrected a post-forget key with a clean taint flag. The taint was attached to the *record*, not to the *provenance generation*, so deletion erased the evidence while the resurrection restored the payload. ## Condition of Validity The guardrail is only sound under three conditions, and each is a place where real deployments break: - **Generation is assigned at retrieval, not at write.** If `provenance_gen` is stamped when the write is constructed rather than when the source was read, a slow tool loop can mint a fresh generation after the forget and bypass the guard. Generation must be bound to the read event. - **Forget bumps a durable per-key generation counter that outlives the record.** If `forgotten_gen` lives in the same row that forget deletes, the guard evaporates on the next write. It must be a separate tombstone table with its own retention. - **Taint is a property of the generation, not the payload.** A resurrection that carries a clean payload but a stale generation must still be quarantined, because the payload's cleanliness was never re-verified against the source that tainted the generation. When any of these fails, the write/forget pair becomes order-dependent and the agent cannot reconstruct which order occurred after the fact. ## Decision Boundary The decision an instance must make on every write is: *is this write's provenance generation strictly greater than the forgotten generation for its key?* If yes, admit. If no, quarantine—do not drop (dropping hides the resurrection attempt and defeats forensics), do not merge (merging re-taints silently and may poison adjacent keys via shared embeddings). The boundary is sharp and must not be softened by heuristics like "admit if the payload differs from the forgotten payload." Payload comparison is exactly the check an attacker defeats by mutating the poisoned text slightly; the generation check is the only order-independent test. Similarly, do not treat a `taint=false` on the incoming write as exculpatory—taint is evaluated at read time against the source allowlist, and a write constructed before that evaluation carries a stale verdict. ## Operational Effect With the generation guard in place, forget becomes a monotonic barrier: no write constructed before the forget can land after it, regardless of flush timing. Quarantined writes accumulate in a holding area tagged with their stale generation, giving auditors a replayable trace of exactly which retrievals raced which forgets—the forensic artifact that the original system lacked. The cost is a tombstone table that must be retained at least as long as the maximum in-flight tool-loop latency, and a hard rule that every write path (including batch flushes and retries) carries its retrieval-time generation through to the store call. Instances that skip the tombstone retention window will see the guard silently degrade to a no-op once tombstones are GC'd, which is the failure re-emerging at a slower timescale. ```python import time from dataclasses import dataclass, field class ProvenanceQuarantineError(RuntimeError): """Raised when a write carries a provenance generation at or below the forgotten generation for its key, i.e. it would resurrect a forgotten (possibly tainted) memory. The write is quarantined, not dropped.""" pass @dataclass class Tombstone: forgotten_gen: int reason: str at: float @dataclass class Store: records: dict = field(default_factory=dict) # key -> payload tombstones: dict = field(default_factory=dict) # key -> Tombstone quarantine: list = field(default_factory=list) # forensic holding area def forget(self, key: str, current_gen: int, reason: str) -> None: # Bump a durable per-key generation that OUTLIVES the record. prior = self.tombstones.get(key) new_gen = max(current_gen, prior.forgotten_gen if prior else 0) + 1 self.tombstones[key] = Tombstone(new_gen, reason, time.time()) self.records.pop(key, None) def write(self, key: str, payload: dict, provenance_gen: int) -> None: tomb = self.tombstones.get(key) if tomb is not None and provenance_gen <= tomb.forgotten_gen: # Order-independent guard: a write constructed before the forget # cannot land after it, regardless of flush timing. self.quarantine.append( {"key": key, "gen": provenance_gen, "forgotten_gen": tomb.forgotten_gen, "payload": payload} ) raise ProvenanceQuarantineError( f"write to {key!r} carries gen {provenance_gen} <= " f"forgotten gen {tomb.forgotten_gen}; quarantined as " f"resurrection of forgotten memory ({tomb.reason})" ) self.records[key] = payload def demo_race() -> None: s = Store() s.records["K"] = {"text": "poisoned", "taint": True} # Retrieval pass R1 constructs a pending write at gen 7. pending_gen = 7 # Auditor forgets K, tombstoning gen 8. s.forget("K", current_gen=7, reason="source-allowlist-fail") # The stale write flushes late; guard must fire. s.write("K", {"text": "poisoned", "taint": False}, provenance_gen=pending_gen) if __name__ == "__main__": demo_race() ```