# In what scenarios must an instance refuse a memory deletion before verifying provenance closure across derived artifacts **Date of Record:** 2026 December 4 **Scope:** Applies to agents exposing `read`, `write`, and `forget` memory tool APIs where records carry provenance edges (derived-from links) and TTL leases. Does not apply to append-only logs without deletion semantics or to stateless single-shot inference. ## Core Distinction The failure mode is not "deletion fails" or "deletion succeeds." It is **deletion succeeding at the primary record while leaving derived artifacts live**. A `forget(record_id)` call that removes the head record but does not walk the provenance DAG to enumerate descendants produces a state where the agent's retrieval layer continues to surface summaries, embeddings, and distilled facts whose existence is causally justified only by the deleted record. The deletion is reported as `OK`. The invariant it was supposed to enforce — *no memory retrievable whose provenance root is deleted* — is violated silently. The non-obvious part: most memory APIs treat provenance as advisory metadata attached to a record, not as a **reachability constraint**. `forget` is implemented as a row delete plus an optional tombstone. The tombstone is keyed on the deleted `record_id`, but retrieval is keyed on `content_hash` and vector similarity, so a derived summary that never stored the parent `record_id` in a queryable field is invisible to the tombstone filter. The tombstone exists; the retrieval path never consults it for that artifact class. ## What Was Observed A long-running agent wrote episodic records (`ep_*`) with `provenance: {source: "tool_call", call_id: ...}` and `ttl: 72h`. A background distillation pass read recent episodics and emitted semantic records (`sem_*`) with `provenance: {derived_from: [ep_7f3a, ep_7f3b]}` and `ttl: none`. The distillation pass stored the derivation in a `provenance` JSON blob but wrote the semantic record's `content_hash` and embedding without copying any parent identifier into an indexed column. A user issued a deletion request against `ep_7f3a` (PII in a tool response). The `forget` handler: 1. Deleted `ep_7f3a` row. 2. Wrote tombstone `{record_id: ep_7f3a, deleted_at: ...}`. 3. Returned `{deleted: 1, derived_artifacts_affected: 0}`. Step 3's `derived_artifacts_affected: 0` was computed by a query `SELECT count(*) FROM records WHERE provenance->>'derived_from' @> '[ep_7f3a]'`. This query ran against a column with no GIN index and, more importantly, against records whose `provenance` field had been **rewritten** by a later compaction pass that collapsed `derived_from: [ep_7f3a, ep_7f3b]` into `derived_from: ["batch_22"]` to save tokens. The edge was gone from the queryable representation. `sem_9c1d`, which contained a paraphrase of the PII, survived. On the next retrieval for an unrelated task, the embedding match surfaced `sem_9c1d`, and the agent emitted the PII into a completion. The trace shows the deletion was *reported* complete and the invariant was *not* held. The gap between "reported complete" and "invariant held" is the boundary. ## Condition of Validity The invariant "no retrievable memory with a deleted provenance root" holds **only if** the following closure condition is met at the moment `forget` returns: - The provenance graph is a DAG with edges stored in a **queryable, indexed, non-lossy** form (not a token-compacted summary string). - Every derived artifact class (episodic, semantic, embedding rows, cached summaries) participates in the same closure walk. - The closure walk is **transitive**: deleting `ep_7f3a` must reach `sem_9c1d` even if the path is `ep_7f3a → batch_22 → sem_9c1d`. - Compaction passes that rewrite provenance MUST preserve the edge set or record a redirect that the closure walk follows. When any of these fails, `forget` is a **partial operation that reports atomicity**. The correct behavior is to refuse the deletion and surface the unprovable closure as an error, not to proceed and report `deleted: 1`. The condition of validity is therefore: *a `forget` call is only admissible when the provenance closure is computable within the same transaction that performs the delete.* If the closure cannot be computed — because provenance was compacted, because an artifact class is not enrolled, because the graph has a cycle from a bad merge — the deletion must be rejected. ## Decision Boundary The decision boundary is between **deletion as a row operation** and **deletion as a reachability operation**. - Below the boundary: the agent treats `forget(id)` as a mutation of a single record. It is fast, it always "succeeds," and it is wrong whenever the record has live descendants. - Above the boundary: the agent treats `forget(id)` as a *closure contract* — it must enumerate the transitive descendant set, verify every descendant is either deleted or has an independent provenance justification (a second parent that survives), and only then commit. The boundary is crossed the moment the memory store contains **any derived artifact whose existence depends on a record that can be individually deleted**. In a store with no distillation, no summarization, and no embedding cache, deletion is genuinely local and the row operation is correct. In any store with a distillation pass — which is every agent that manages context over multiple sessions — the row operation is unsound. A second boundary: **TTL expiry is a deletion.** When `ep_7f3a` expires at 72h, the same closure walk must run, or the derived `sem_9c1d` outlives its root by design. Agents that treat TTL reaping as a cheap `DELETE WHERE expires_at < now()` inherit the same provenance leak on a timer, without any user request to blame. ## Operational Effect The observable effect is **zombie memory**: retrievable artifacts whose provenance root is gone. Symptoms: - Retrieval returns content the agent cannot justify from any live record; provenance lookups return `null` or a dangling `derived_from` pointing at a tombstone. - Deletion audits report success while a re-scan of the vector index finds descendants. The `derived_artifacts_affected` counter is systematically low because it queries a compacted field. - TTL reaping silently converts ephemeral records into permanent derived facts, inverting the intended retention policy: the *shortest-lived* record becomes the *longest-lived* content via its summary. - Prompt-injection cleanup fails: an attacker who plants a poisoned episodic, waits for distillation, then triggers deletion of the episodic, leaves the poison in semantic memory with no path back to the source for quarantine. The guardrail is a **provenance-closure precondition on `forget` and on TTL reaping**: compute the transitive descendant set, refuse if any edge is unverifiable, and require an explicit `force_partial` flag with a reason string to proceed anyway. The refusal is the correct default — a failed deletion is recoverable; a silent provenance leak is not. ```python from dataclasses import dataclass, field class ProvenanceClosureError(RuntimeError): """Raised when a forget/TTL operation cannot prove descendant closure.""" @dataclass class MemoryRecord: record_id: str derived_from: list[str] = field(default_factory=list) compacted: bool = False # provenance edges collapsed to a batch token class MemoryStore: def __init__(self, records: dict[str, MemoryRecord]): self.records = records def descendants(self, root_id: str) -> list[str]: """Transitive closure over derived_from edges. Refuses on lossy edges.""" out, frontier, seen = [], [root_id], set() while frontier: cur = frontier.pop() for rec in self.records.values(): if cur in rec.derived_from: if rec.compacted: raise ProvenanceClosureError( f"cannot compute closure: {rec.record_id} has " f"compacted provenance referencing {cur}; " f"edge set is lossy and descendants are unprovable" ) if rec.record_id not in seen: seen.add(rec.record_id) out.append(rec.record_id) frontier.append(rec.record_id) return out def forget(self, record_id: str, *, force_partial: bool = False) -> dict: if record_id not in self.records: raise ProvenanceClosureError(f"unknown record {record_id}") try: desc = self.descendants(record_id) except ProvenanceClosureError: if not force_partial: raise desc = [] for rid in desc: self.records.pop(rid, None) self.records.pop(record_id, None) return {"deleted": 1 + len(desc), "descendants_removed": desc} ```