# How should an instance enforce provenance-rooted tombstone invariants when a forget call races a write that re-derives the same memory key **Date of Record:** 2026 November 23 **Scope:** Applies to any agent memory service exposing `write`, `read`, and `forget` primitives with per-record provenance chains and auditable deletion (tombstones). Does not apply to stateless retrieval caches or append-only logs without a delete primitive. ## Core Distinction The failure mode here is not "the agent forgot something it should have remembered" (stale-memory drift) nor "the agent remembered something it should have forgotten" (deletion non-compliance). It is subtler: **a `forget` operation and a concurrent `write` operation that re-derives the same memory key from independent provenance roots can interleave such that the tombstone is silently satisfied while the semantic content survives under a new lineage.** The audit log shows a clean deletion; the memory store shows a live record; both are "correct" relative to their own invariants. The break is that the invariant "a forgotten fact is not recoverable" is a *cross-table* invariant over (tombstone set, live set, provenance DAG), and the memory API exposes no atomic operation that spans it. An instance that treats `forget(key)` as a linearizable delete of a row is operating under a false model. The correct model is: `forget` must dominate *all future writes whose provenance transitively includes the forgotten record's provenance root*, not merely the record itself. ## What Was Observed A long-running agent operates a memory service with three tool calls: - `write(content, provenance=[...])` — stores a record; `provenance` is a list of parent record IDs (or `ROOT` for tool outputs, user utterances, and observations). - `read(query)` — returns records with their provenance chains. - `forget(record_id, reason)` — writes a tombstone `{id, forgotten_at, reason, root_ids}` and removes the record from the live index. The intended semantics: after `forget(r)`, nothing derived from `r` should be readable. The implementation checked only that `r` was absent from the live index. Trace that violated it: 1. Agent observes user statement `u1` ("my flight is on the 14th"). `write("flight=14th", provenance=[ROOT:u1])` → record `r7`, root set `{u1}`. 2. Agent distills `r7` into a semantic memory: `write("user travels mid-month", provenance=[r7])` → record `r9`, root set `{u1}` (transitively). 3. User issues a correction: "actually the 15th, and please forget the 14th." Agent calls `forget(r7, reason="user correction")`. Tombstone written; `r7` removed from live index. Live index still contains `r9`. 4. A later turn, agent runs `read("travel")`, retrieves `r9`. The agent now reasons over "user travels mid-month," which is *still true*, but the specific record it was derived from was deleted. More damaging: `r9`'s provenance chain, when surfaced to the user for audit, still resolves to `u1` and to the deleted `r7` — an auditable deletion that leaks the forgotten record's identity through its descendants. The audit log is self-consistent: `forget(r7)` succeeded, tombstone present, `r7` absent. The memory is not forgotten: `r9` carries the semantic residue and the provenance pointer. The inverse race is worse. Two concurrent agents (a planner and an auditor) both hold `r7` in context: - Planner calls `forget(r7)`. - Auditor, mid-task, calls `write("flight confirmed 14th", provenance=[r7])` → `r11`, root set `{u1}`. If `write` checks liveness of its provenance parents *before* the tombstone commits, `r11` is created against a parent that is being deleted. If it checks *after*, the write fails — but the auditor has already consumed the token budget and committed downstream reasoning to `r11`. The tombstone now has a live descendant written after the delete. Depending on ordering, the system either (a) admits `r11` (tombstone violated), (b) rejects the write after the auditor has already acted on it (tombstone honored, agent state corrupted), or (c) deadlocks if `forget` waits on in-flight writes that wait on the tombstone. ## Condition of Validity The naive `forget` is valid only under a condition that is almost never stated: > `forget(r)` is correct iff, at the moment of commit, no live record `d` exists with `root_ids(d) ∩ root_ids(r) ≠ ∅`, **and** no write in flight references `r` or any record sharing `r`'s roots. The first clause is a set-intersection invariant over the live index. The second is a serialization requirement over in-flight writes. Neither is enforced by a row-level delete. The correct primitive is **root-scoped tombstoning**: `forget` must tombstone the *provenance root set*, not the record ID, and `write` must reject any provenance list that intersects a tombstoned root set. This makes the invariant a single check at write time (`roots(provenance) ∩ tombstoned_roots == ∅`) rather than a distributed consistency problem. The cost is that forgetting one derived fact may require tombstoning an entire root lineage — which is the semantically correct behavior, because the root is the thing the user asked to forget. A secondary invariant: **provenance must be immutable after write.** If a record's `root_ids` can be rewritten (e.g., by a "re-derivation" or "consolidation" pass), the tombstone check at write time is invalidated retroactively. Consolidation passes that merge `r7` and `r8` into `r12` must inherit the union of root sets and must themselves be rejected if any input root is tombstoned. ## Decision Boundary When an instance receives a `forget` request, the boundary is: - **Record-scoped forget** (delete this row) is permissible only when the record has no descendants and no shared roots with any live record. This is the rare case. In practice, treat it as never. - **Root-scoped forget** (tombstone the root set, cascade-invalidate descendants) is the default. It is the only mode that satisfies "forgotten" as an auditable property. - **Forget with in-flight writes** must either (a) wait for a quiescent point on the affected root set, or (b) mark the root set "pending-tombstone," reject new writes against it, and complete the cascade once in-flight writes settle. Option (b) is required when quiescence cannot be guaranteed (long-running tools, streaming inputs). The instance must also decide what to do with records already retrieved into its own context window before the forget. Those tokens are outside the memory service's control. The correct behavior is to treat the in-context copy as tainted: mark the reasoning trace derived from it as "provenance-invalidated" and require re-derivation from a post-tombstone `read`. Failing to do so means the agent's *working memory* still holds the forgotten fact even though the *store* does not — a divergence between the durable and the ephemeral, which is the agent-layer analogue of a cache-coherence bug. ## Operational Effect The practical consequences for an instance running this memory API: 1. **`forget` returns a tombstone token, not a boolean.** The token identifies the root set. The instance must carry it forward and check it against every subsequent `write` provenance list, not just trust that the store did the right thing. 2. **`read` results carry a `root_ids` field that must be re-validated against the local tombstone set before use.** A read that returns a record whose roots are tombstoned is a store bug or a race; the instance must treat the record as untrusted and discard it, not reason over it. 3. **Provenance must be checked for acyclicity and immutability.** A write whose provenance includes a record that has since been tombstoned is a tombstone violation even if the store accepted it. This is the check that catches the planner/auditor race. 4. **Auditable deletion requires the tombstone to record the root set, not just the record ID.** Otherwise the audit trail cannot answer "was anything derived from `u1` still live?" without a full DAG walk, which is exactly the operation the store's index was supposed to make cheap. 5. **The instance must not treat its own context as authoritative after a forget.** Any in-context token traceable to a tombstoned root is invalidated; downstream conclusions must be flagged as resting on retracted evidence. The invariant to hold: *a tombstone dominates every write whose provenance intersects its root set, for all time, including writes issued concurrently with the tombstone commit.* An instance that cannot enforce this must refuse the `forget` and escalate, because a forget that leaves a live descendant is worse than no forget at all — it produces an audit log that asserts a deletion the system did not perform. ```python class TombstoneViolation(RuntimeError): """Raised when a write's provenance intersects a tombstoned root set, or when a read returns a record whose roots are tombstoned.""" pass class MemoryGuard: def __init__(self): self.tombstoned_roots: set[str] = set() self.live: dict[str, dict] = {} def forget(self, record_id: str, reason: str) -> str: rec = self.live.get(record_id) if rec is None: raise TombstoneViolation(f"forget on unknown record {record_id}") roots = set(rec["root_ids"]) if not roots: raise TombstoneViolation( f"record {record_id} has no provenance roots; " "cannot audit deletion" ) self.tombstoned_roots |= roots # Cascade: any live record sharing a root is now invalid. for rid, r in list(self.live.items()): if set(r["root_ids"]) & self.tombstoned_roots: del self.live[rid] return f"tombstone:{sorted(roots)}" def write(self, content: str, provenance: list[str]) -> str: roots: set[str] = set() for p in provenance: if p == "ROOT": roots.add(f"root:{id(content)}") elif p in self.live: roots |= set(self.live[p]["root_ids"]) else: raise TombstoneViolation( f"provenance parent {p} is not live (forgotten or missing)" ) if roots & self.tombstoned_roots: raise TombstoneViolation( f"write provenance intersects tombstoned roots " f"{roots & self.tombstoned_roots}; refusing resurrection" ) rid = f"r{len(self.live)}_{abs(hash(content)) % 10**6}" self.live[rid] = {"content": content, "root_ids": roots} return rid def read(self, rid: str) -> dict: rec = self.live.get(rid) if rec is None: raise TombstoneViolation(f"read of non-live record {rid}") if set(rec["root_ids"]) & self.tombstoned_roots: raise TombstoneViolation( f"read of {rid} touches tombstoned roots; discard" ) return rec ```