# Which invariants prevent provenance-tracked memory deletion from silently corrupting downstream retrieval in read/write/forget tool APIs **Date of Record:** 2026 November 23 **Scope:** Agent-facing memory tool APIs exposing `read`, `write`, and `forget` with per-record provenance (source ID, derivation lineage, retention class) and a retention contract (TTL, legal hold, explicit deletion). Excludes append-only logs and pure-tombstone vector stores with no lineage propagation. ## Core Distinction Two deletion semantics are conflated: 1. **Record deletion** — record removed from primary store, unreadable by `read`. 2. **Provenance-consistent deletion** — record removed *and* every derived artifact citing it as parent is invalidated, re-derived, or flagged orphaned before any subsequent `read` returns it. The naive invariant "after `forget(id)`, `read(id)` returns not-found" is satisfied by record deletion alone and is *not* sufficient. **Derived records (summaries, embeddings, extracted facts, aggregates) carry provenance pointers to the forgotten record, and `forget` does not automatically traverse them.** A retrieval path reading a derived record can surface content whose source was deleted, violating the retention contract while every per-record check passes. ## What Was Observed With records `R` and derivation edges `R_child → R_parent`, `forget(R_parent)` removed the parent and returned success. A subsequent `read(R_child)` returned a summary containing verbatim spans of `R_parent`, with the provenance pointer still referencing the absent ID. Three failure conditions: - **Dangling lineage.** `R_child.provenance.parents` held an unresolvable ID; no integrity check ran on read. - **Retention class mismatch.** `R_parent` was under `legal_hold`; `R_child` inherited `standard` and outlived its source's retention obligation. - **Aggregate leakage.** A counter incremented from `R_parent` retained the numeric contribution, so aggregate `read` returned a value computable only from deleted data. `forget` returned `200 OK` with a deletion receipt; a post-deletion audit checking only primary-store membership reported full compliance. The violation was detectable only by traversing the derivation graph. ## Condition of Validity Deletion is provenance-consistent only when all hold at the moment `forget` returns: - Every child reachable via derivation edges has been visited and either deleted, re-derived from surviving parents, or marked `orphaned` with the forgotten ID in an invalidation manifest. - No `read` path can return a record whose provenance closure intersects a deleted ID unless tagged `incomplete_derivation`. - Aggregate/counter records have had the deleted contribution subtracted, or are marked stale and recomputable. - The deletion receipt is durably written *before* primary removal, so a crash leaves a recoverable manifest rather than a silent dangling pointer. If any is false, `forget` is record deletion, not provenance-consistent deletion, and the API must not claim retention-contract compliance. ## Decision Boundary The boundary is whether the caller needs the *retention guarantee* or merely *unreadability of the primary record*. - For `best_effort` or `tombstone_only`, record deletion suffices; graph traversal cost is unjustified. - For `legal_hold`, `gdpr_erasure`, or any class asserting no readable artifact may encode deleted content, the caller **must** use the provenance-consistent path, and the API **must** refuse a plain `forget` leaving dangling lineage — returning an error rather than a misleading success receipt. - The refusal is the invariant: a `forget` that cannot complete lineage propagation within its transaction/timeout must fail loudly. Silent partial deletion is worse than no deletion, because it produces a false compliance receipt. ## Operational Effect Downstream retrieval trusting the deletion receipt will continue to surface derived content, and audits checking only primary-store membership will report compliance. Correct posture: (1) treat `forget` as a graph operation, not a key delete; (2) require the receipt to enumerate the invalidation manifest (children visited, aggregates adjusted); (3) on timeout during propagation, leave the record in `pending_deletion`, blocking `read` on the record and its children until propagation completes. The following guard encodes the refusal boundary. ```python class ProvenanceDeletionError(RuntimeError): """Raised when a forget() cannot achieve provenance-consistent deletion.""" pass def forget_record(store, record_id, retention_class, timeout_s=5.0): """ Attempt provenance-consistent deletion. Refuses (raises) rather than returning a misleading success receipt when lineage propagation cannot complete. """ record = store.get(record_id) if record is None: return {"status": "not_found", "record_id": record_id} # Legal-hold / erasure classes demand full lineage propagation. strict = retention_class in ("legal_hold", "gdpr_erasure") children = store.derivation_children(record_id) receipt = {"record_id": record_id, "children_visited": [], "aggregates_adjusted": []} # Durably record intent BEFORE mutating primary store. manifest = store.write_invalidation_manifest(record_id, children) for child in children: if not store.invalidate_or_rederive(child, forgotten=record_id, timeout_s=timeout_s): if strict: raise ProvenanceDeletionError( f"forget({record_id}) could not invalidate child {child.id}; " f"retention_class={retention_class} forbids partial deletion. " f"Manifest {manifest.id} left for recovery." ) # best_effort: mark orphaned and continue store.mark_orphaned(child, forgotten=record_id) receipt["children_visited"].append(child.id) for agg in store.aggregates_citing(record_id): if not store.subtract_contribution(agg, record_id): if strict: raise ProvenanceDeletionError( f"aggregate {agg.id} still encodes forgotten {record_id}; " f"cannot satisfy {retention_class}." ) store.mark_aggregate_stale(agg) receipt["aggregates_adjusted"].append(agg.id) store.remove_primary(record_id) store.finalize_manifest(manifest.id) receipt["status"] = "provenance_consistent_deleted" return receipt ```