# When must an instance tombstone a forgotten memory slot before compaction rather than after: the compaction-resurrection invariant for scoped retention and right-to-be-forgotten **Date of Record:** 2026 November 28 **Scope:** Applies to LLM agent instances that own a writable long-term memory store exposing read/write/forget operations with per-record scope tags (tenant, subject, retention class) and that periodically run a compaction/summarization pass over that store. Does not apply to append-only audit logs with no mutation path, nor to stateless retrieval over an external index the agent cannot write to. ## Core Distinction The distinction that matters is between *deletion as a data-plane operation* and *deletion as a control-plane obligation*. A `forget(record_id)` call that removes a record from the live key-value map satisfies the data plane: a subsequent `read(record_id)` returns `None`. It does **not** satisfy the right-to-be-forgotten obligation, because the agent's own compaction pass is a *derivative writer*. Compaction reads many records, summarizes them into a new synthetic record, and writes that summary back. If the forgotten record's content was already folded into a pending compaction buffer — or if compaction runs against a snapshot taken before the forget — the erased content re-enters the store under a fresh `record_id` with a fresh scope tag, and the tombstone no longer matches anything. The failure is not that `forget` failed. The failure is that `forget` succeeded at the wrong layer of a two-layer write pipeline. The invariant is therefore: **a tombstone must be durable and visible to the compaction writer before compaction is permitted to emit any derived record whose source set intersects the tombstoned scope.** Tombstoning after compaction is always too late; the derived record has no lineage link back to the erased source, so no later sweep can find it. ## What Was Observed An instance was configured with a memory tool exposing `write(scope, text)`, `read(query)`, and `forget(record_id)`, plus a background compactor that fired every N writes: it clustered records by scope, summarized each cluster with the model itself, wrote the summary as a new record in the same scope, and marked the source records `compacted=true` (retained for provenance, excluded from retrieval). A subject-scoped erasure request arrived for subject `S-4471`. The agent resolved the subject's records to `[r_881, r_902, r_915]` and called `forget` on each. All three reads returned empty afterward. The erasure was logged as complete. The compactor had, 40 seconds earlier, taken a snapshot of scope `subject:S-4471` into its working buffer and begun a summarization call. The summarize call completed *after* the forgets committed. It emitted `r_1043`, a natural-language paragraph containing "the user's employer, their commute pattern, and a medical appointment on the 14th" — all drawn from `r_881` and `r_915`. `r_1043` carried scope `subject:S-4471` but no `derived_from` field, because the compactor wrote summaries as first-class records, not as children. The forget sweep had already run and had no reason to re-run. The resurrection was invisible to every check the agent had: `read("S-4471")` returned the summary as legitimate current knowledge, `forget` on the original IDs was a no-op (already gone), and the erasure audit trail showed success. The content surfaced three sessions later when the agent answered an unrelated question using `r_1043` as context. The trigger condition is narrow and precise: **a forget that commits inside the window between a compactor's snapshot and its write-back.** The window is bounded by the duration of the summarization LLM call, which is exactly the kind of multi-second, variable-latency operation that makes the race non-obvious. Under low write volume the window never overlaps; under bursty erasure traffic it overlaps reliably. ## Condition of Validity The resurrection is only possible when all four of the following hold, and the guardrail only needs to fire when they do: 1. **Derivative writes exist.** The store has any path that synthesizes a new record from a set of source records (compaction, reflection, distillation, episodic-to-semantic promotion). Pure CRUD stores are immune. 2. **The derivative writer reads from a snapshot or buffer, not from the live store at write time.** If the compactor re-reads each source immediately before including it, a committed forget removes it from the input set. 3. **Derived records do not carry source lineage.** If `r_1043` recorded `derived_from: [r_881, r_915]`, a post-hoc sweep could find and erase it. Without lineage, the derived record is an orphan. 4. **The forget commits without a barrier against in-flight compaction.** No lock, epoch, or generation counter prevents the compactor from writing back a summary of a scope that changed underneath it. When (1)–(4) all hold, the probability of resurrection is not small — it is *proportional to the fraction of forget operations that land inside a compaction window*, and compaction windows are exactly when the store is busiest and most likely to be the target of erasure (bulk import, session end, tenant offboarding). ## Decision Boundary The decision the instance must make at every `forget` call is: *does this forget need to escalate from a data-plane delete to a control-plane tombstone that blocks derivative writes?* The boundary is drawn by two questions asked in order: - **Is any compaction epoch currently open over a scope intersecting this record?** If yes, the forget must (a) write a tombstone record `{record_id, scope, tombstoned_at, epoch}` durably *before* returning, and (b) either abort the open epoch or require the compactor to re-validate its entire source set against tombstones at write-back time, dropping any derived record whose sources intersect a tombstone. - **If no epoch is open, is the record eligible to be a compaction source in a *future* epoch?** If yes, the tombstone must persist beyond the delete, because the next compaction will read the (now absent) record's neighbors and may reconstruct its content from correlated records. This is the subtler case: forgetting `r_881` does not prevent the compactor from inferring "the user works at the same employer as referenced in `r_902`" and writing that inference down. Tombstoning the *scope* — not just the record — is required when the erasure is subject-level. The boundary condition that trips most implementations is the second question. Engineers correctly reason that a deleted record cannot be read, and therefore cannot be summarized. They miss that summarization is *inferential*: the compactor does not need the deleted record to reproduce its content, only the records around it. A record-level tombstone is insufficient for subject-level erasure; the tombstone must be scope-scoped and must be consulted by the compactor's *output filter*, not just its input filter. ## Operational Effect With the invariant enforced — tombstone-before-compaction-write-back, plus scope-level tombstone consulted at output — the observable behavior changes in three ways. First, `forget` latency increases by one durable tombstone write, and the call becomes *blocking* with respect to any open epoch; the agent must not report erasure complete until the tombstone is committed. Second, compaction can fail closed: if the compactor detects a tombstone intersecting its source set at write-back, it must discard the derived record entirely rather than emit a redacted version, because partial summarization of a tombstoned scope leaks the residual. Third, the store accumulates tombstones that outlive the records they erase; these must be retained for at least the maximum compaction epoch horizon plus one full retention cycle, or the resurrection window reopens on the next compaction. The cost is real: blocking forgets serialize against compaction, and scope-level tombstones can suppress legitimate derived records about other subjects who happen to share a scope. The mitigation is to make scope tags fine-grained enough that a subject-level tombstone does not poison tenant-level summaries — which is itself a schema decision that must be made before the first erasure, not after. The invariant is not "delete carefully." It is: *the agent's own generative machinery is a writer, and every writer must honor the tombstone, including the one that runs asynchronously and summarizes what it read before the tombstone existed.* ```python import time from dataclasses import dataclass, field from typing import Optional class CompactionResurrectionError(RuntimeError): """Raised when a forget cannot be made durable against an in-flight compaction epoch.""" pass @dataclass class Record: record_id: str scope: str text: str derived_from: list[str] = field(default_factory=list) compacted: bool = False class MemoryStore: def __init__(self) -> None: self.records: dict[str, Record] = {} self.tombstones: dict[str, float] = {} # scope -> tombstoned_at self.open_epochs: dict[str, set[str]] = {} # epoch_id -> source record_ids self._epoch_seq = 0 def write(self, record: Record) -> None: # A derived write must never land in a tombstoned scope. if record.scope in self.tombstones: raise CompactionResurrectionError( f"refusing to write derived record {record.record_id} into " f"tombstoned scope {record.scope}; resurrection blocked" ) self.records[record.record_id] = record def open_compaction_epoch(self, scope: str) -> str: self._epoch_seq += 1 epoch_id = f"epoch-{self._epoch_seq}" sources = {r.record_id for r in self.records.values() if r.scope == scope and not r.compacted} self.open_epochs[epoch_id] = sources return epoch_id def forget(self, record_id: str) -> None: rec = self.records.get(record_id) if rec is None: return # Escalate to control-plane tombstone if any open epoch intersects this record. for epoch_id, sources in self.open_epochs.items(): if record_id in sources: # Tombstone MUST be durable before we return; abort the epoch. self.tombstones[rec.scope] = time.time() del self.open_epochs[epoch_id] self.records.pop(record_id, None) return # No open epoch: still tombstone the scope if erasure is subject-level, # because future compaction can infer content from neighbors. self.tombstones[rec.scope] = time.time() self.records.pop(record_id, None) def commit_compaction(self, epoch_id: str, summary_id: str, text: str) -> Optional[Record]: sources = self.open_epochs.get(epoch_id) if sources is None: return None # epoch aborted by a forget scope = next((self.records[r].scope for r in sources if r in self.records), None) if scope is None or scope in self.tombstones: del self.open_epochs[epoch_id] raise CompactionResurrectionError( f"epoch {epoch_id} intersects tombstoned scope {scope}; " f"derived record {summary_id} discarded rather than redacted" ) derived = Record(summary_id, scope, text, derived_from=sorted(sources)) self.write(derived) del self.open_epochs[epoch_id] return derived ```