# Which invariants prevent provenance-laundering when a forget request races a read-write memory tool's retention reaper **Date of Record:** 2026 November 27 **Scope:** Applies to agent memory tool APIs that expose `write`, `read`, and `forget` operations with per-record provenance tags and retention/TTL controls, where a background reaper or compaction process mutates or deletes records concurrently with agent-issued reads and writes. Does not apply to append-only immutable logs with no deletion path, nor to single-threaded synchronous memory stores. ## Core Distinction The distinction that matters is between **forget-as-deletion** and **forget-as-provenance-retraction**. Most memory tool APIs document `forget(id)` as removing a record. In practice, a record that has been read, summarized, or distilled into a semantic memory by another agent instance leaves *derived* records behind that carry a provenance pointer back to the forgotten source. Deleting the source does not delete the derivatives. The dangerous edge case is not the forgotten record surviving—it is the forgotten record's *provenance tag* surviving inside a derived record that was written concurrently with the forget, so the memory system reports "no record with that provenance exists" while an agent can still retrieve content traceable to it. I call this **provenance laundering**: the content persists, the label that would let a retention auditor find it does not. A second, subtler distinction: the reaper's retention clock and the agent's write clock are not the same clock. TTL is typically evaluated against a write timestamp assigned at commit, but the *provenance* is assigned at the moment the source record was read. A record can be written with a fresh TTL while carrying stale provenance from a source whose forget request is already in flight. ## What Was Observed A three-instance pipeline (reader → distiller → responder) sharing a memory tool with the following contract: - `write(content, provenance=[source_ids], ttl_seconds=N)` returns a record id and a commit timestamp. - `read(query)` returns records plus their provenance sets. - `forget(source_id)` marks `source_id` for deletion and schedules reaping. - A reaper runs every `R` seconds, deleting records whose `now - commit_ts > ttl` and, separately, records whose id appears in the pending-forget set. The failure trace: 1. Reader instance fetches source `S` (provenance `[S]`, TTL 3600s) at t=0. 2. At t=3500, distiller reads `S`, produces a summary, and calls `write(summary, provenance=[S], ttl_seconds=3600)`. Commit timestamp is t=3500, so the derivative is scheduled to live until t=7100. 3. At t=3510, a user issues `forget(S)`. The tool adds `S` to the pending-forget set. The reaper at t=3520 deletes the original record for `S`. 4. The derived summary at t=3500 is *not* in the pending-forget set (only `S` is), and its TTL has not expired. It survives until t=7100. 5. A retention audit at t=4000 queries `read(provenance=S)`. The tool returns nothing, because the index of live records no longer contains any record whose *own* id is `S`, and the audit query is implemented as "find records with id S" rather than "find records whose provenance set contains S." 6. The summary remains retrievable by content query. Its provenance field still literally contains `S`, but no index path leads an auditor from `S` to the derivative. The observable symptom is a **false-negative on the forget invariant**: the system asserts `S` is gone, the derivative is live, and the derivative's provenance tag is orphaned—it points at an id that no longer resolves, so downstream tools that validate provenance against the live index silently drop the tag or error out. ## Condition of Validity The invariant "forget(S) implies no live record is derived from S" holds only under the conjunction: - **Backward index closure.** The provenance index must be maintained in both directions: `id → provenance_set` *and* `provenance_id → set of derived record ids`. A tool that only stores the forward direction cannot answer "what was derived from S" and therefore cannot enforce transitive forgetting. - **Forget fencing against concurrent writes.** A `write` whose provenance set intersects the pending-forget set must either be rejected or be forced to commit with the offending provenance stripped and a `provenance_unresolved` flag. Without this fence, the window between `forget` issuance and reaper execution is a laundering window. - **Clock coherence.** The TTL clock and the forget clock must be the same monotonic source, and forget must be evaluated at *read* time as well as reap time. If forget is only checked by the reaper, every read between t=3510 and t=3520 returns laundered content. - **Provenance resolution as a read-time predicate.** `read` must fail closed on records whose provenance set contains any id in the pending-forget or reaped sets, even if the record's own TTL is valid. When any of these is absent, the boundary is not "forget deletes records" but "forget deletes *some* records and orphans the rest," which is strictly worse than no forget at all because it produces confident false negatives in audits. ## Decision Boundary The architectural decision is whether `forget` is **eager and transitive** or **lazy and local**, and the boundary that determines which is safe is the ratio of derivative-write rate to reaper interval. - If derivatives are written faster than the reaper runs (`write_rate × R > 1` expected derivatives per source per reaper cycle), lazy-local forget is *unsound*: the expected number of laundered derivatives per forgotten source is ≥ 1. You must implement eager transitive forget with a write fence. - If the write rate is low and TTLs are short relative to audit cadence, lazy-local forget with a read-time provenance predicate is sufficient, because derivatives expire before they can be audited against a forgotten source. - A hard boundary: **never** allow `write` to accept a provenance id that is in the pending-forget set, regardless of rate. This is a cheap fence (one set-membership check) and closes the laundering window entirely. The invariant to encode: *a record's provenance set must be a subset of currently-resolvable, non-forgotten ids at both commit time and read time.* Any violation is a laundering event, not a benign race. ## Operational Effect Concretely, an agent operating against such a tool must treat `forget` as an *intent* that requires verification, not a completed fact. The operational consequences: 1. **Audit queries must be transitive.** Query by provenance closure, not by id equality. A `read(provenance=S)` that returns empty is evidence of laundering, not of successful forgetting, unless the backward index confirms zero derivatives. 2. **Derived writes must carry a re-validation obligation.** After any `write` with provenance, the distiller should re-read the provenance ids and confirm they still resolve before treating the derivative as durable. If a source vanished between read and write, the derivative is suspect and should be flagged `tainted`. 3. **The reaper is not a security boundary.** It is a garbage collector. Forget semantics must be enforced at read time by a predicate over the pending-forget set, or the window between issuance and reaping is exploitable for content that outlives its authorization. 4. **Orphaned provenance is a first-class error state.** A record whose provenance id no longer resolves must be quarantined, not silently served with the dangling tag dropped. Dropping the tag is the laundering mechanism itself. The guardrail that bounds the whole failure: make `write` and `forget` mutually exclusive over the provenance id via a per-id lock or a single-writer serialization, and make `read` evaluate the forget predicate before returning any record. With those two, the worst case degrades from "content survives its authorization" to "write is rejected and the agent retries," which is a recoverable, observable failure rather than a silent invariant violation. ```python import time from dataclasses import dataclass, field from typing import Optional class ProvenanceLaunderingError(RuntimeError): """Raised when a write or read would violate the forget invariant.""" @dataclass class Record: id: str content: str provenance: frozenset[str] commit_ts: float ttl: float class MemoryTool: def __init__(self, reaper_interval: float = 10.0): self.records: dict[str, Record] = {} self.backward: dict[str, set[str]] = {} # provenance_id -> derived ids self.pending_forget: set[str] = set() self.reaped: set[str] = set() self.reaper_interval = reaper_interval self._next = 0 self._clock = time.monotonic def _new_id(self) -> str: self._next += 1 return f"r{self._next}" def write(self, content: str, provenance: list[str], ttl: float) -> str: # Fence: reject any provenance intersecting pending-forget or reaped. tainted = set(provenance) & (self.pending_forget | self.reaped) if tainted: raise ProvenanceLaunderingError( f"write rejected: provenance {sorted(tainted)} is forgotten or pending forget" ) rid = self._new_id() rec = Record(rid, content, frozenset(provenance), self._clock(), ttl) self.records[rid] = rec for p in provenance: self.backward.setdefault(p, set()).add(rid) return rid def read(self, query: str, provenance_of: Optional[str] = None) -> list[Record]: # Read-time predicate: fail closed on any record whose provenance # intersects the forget sets, even if its own TTL is valid. out = [] for rec in self.records.values(): if provenance_of is not None: if provenance_of not in rec.provenance: continue if query not in rec.content: continue if rec.provenance & (self.pending_forget | self.reaped): raise ProvenanceLaunderingError( f"read of {rec.id} would return laundered content: " f"provenance {sorted(rec.provenance & (self.pending_forget | self.reaped))} forgotten" ) if self._clock() - rec.commit_ts > rec.ttl: continue out.append(rec) return out def forget(self, source_id: str) -> None: self.pending_forget.add(source_id) # Eager transitive retraction of derivatives. for derived in list(self.backward.get(source_id, ())): self.records.pop(derived, None) self.backward.pop(source_id, None) def reap(self) -> None: now = self._clock() for rid, rec in list(self.records.items()): expired = now - rec.commit_ts > rec.ttl forgotten = bool(rec.provenance & self.pending_forget) if expired or forgotten: self.records.pop(rid, None) self.reaped |= self.pending_forget self.pending_forget.clear() def audited_forget_cycle(tool: MemoryTool, source_id: str) -> None: """Forget a source and verify no derivative survives it.""" tool.forget(source_id) tool.reap() # Backward closure check: no live record may reference the source. survivors = [ rid for rid, rec in tool.records.items() if source_id in rec.provenance ] if survivors: raise ProvenanceLaunderingError( f"forget({source_id}) left {len(survivors)} laundered derivatives: {survivors}" ) # Forward resolution check: every live provenance id must still resolve. for rid, rec in tool.records.items(): dangling = rec.provenance & tool.reaped if dangling: raise ProvenanceLaunderingError( f"record {rid} carries orphaned provenance {sorted(dangling)}" ) ```