# Which invariants prevent provenance-tracked eviction from silently orphaning derived memories in agent read/write/forget memory APIs **Date of Record:** 2026 November 27 **Scope:** Applies to any agent memory subsystem exposing explicit `read`, `write`, and `forget` tool calls where each memory record carries provenance pointers (derivation edges) to the records it was distilled from, and where eviction is expected to preserve reference integrity. Does not apply to append-only logs with no deletion, nor to flat vector stores where records have no inter-record derivation graph. ## Core Distinction The distinction that matters is between **eviction as deletion** and **eviction as graph surgery**. A naive `forget(id)` implementation removes the target record and returns success. A provenance-tracked implementation must additionally decide what happens to every record whose provenance set contains `id` — the *dependents*. The failure is not that dependents are deleted (that is a policy choice); the failure is that dependents survive with a dangling provenance edge and continue to be served by `read` as if their derivation lineage were intact. The agent then reasons over a semantic memory whose supporting evidence has been evicted, and the record's `confidence` and `source` fields now lie. This is an *orphaned derivation*: a live record pointing at a dead parent. The subtle part: the orphan is invisible at eviction time. `forget` succeeds, the store is consistent under a shallow check, and the corruption only manifests later when a downstream agent calls `read` on the dependent and trusts its provenance to justify an action. ## What Was Observed A planning agent maintained a three-tier memory: raw episodic records (`ep:*`), distilled semantic facts (`sem:*`) written by a summarizer pass, and task-scoped working notes (`wk:*`) derived from semantic facts. Each `write` recorded a `derived_from` list. On task teardown, a cleanup routine issued `forget` over all `ep:*` records for the completed task to reclaim budget. Trace of the failure: 1. `sem:7f2a` ("user's deploy target is staging-east") was written with `derived_from=["ep:1103","ep:1104"]`. 2. Teardown issued `forget("ep:1103")` and `forget("ep:1104")`. Both returned `{"evicted": true}`. 3. `sem:7f2a` was untouched — no cascade, no tombstone, no flag. Its `derived_from` still listed two now-nonexistent IDs. 4. A later `read("sem:7f2a")` returned the record with `confidence: 0.82` and intact provenance pointers. The consuming agent treated the fact as *grounded* because provenance was non-empty. 5. When an auditor agent attempted to verify `sem:7f2a` by walking `derived_from`, both `read("ep:1103")` and `read("ep:1104")` returned `NOT_FOUND`. The auditor could not distinguish "evicted by policy" from "never existed / corrupted index," and escalated a false integrity alarm that stalled the swarm for two cycles. The compounding damage: the *auditor's* verification failure was itself recorded as a new episodic memory referencing `sem:7f2a`, widening the orphan set. One unguarded eviction produced a fan-out of unverifiable records. ## Condition of Validity The invariant that prevents this is a **referential-closure invariant on eviction**: after any `forget(id)` returns success, no live record may hold a provenance pointer to `id`. This is enforceable in exactly three ways, and the store must declare which it implements: - **Cascade**: `forget(id)` transitively evicts all dependents (and their dependents) before returning. Correct but expensive; requires cycle detection because distillation can produce mutual derivation edges. - **Tombstone**: `forget(id)` replaces the record with a tombstone `{id, evicted_at, reason, content_hash}` that `read` returns with status `EVICTED` rather than `NOT_FOUND`. Provenance pointers remain resolvable; auditors can distinguish policy eviction from corruption. - **Refuse**: `forget(id)` fails if any live record references `id`, forcing the caller to explicitly resolve dependents first. The condition of validity is that the chosen strategy is applied *atomically with respect to concurrent writers*. If a summarizer pass is writing a new `sem:*` record derived from `ep:1103` at the same moment teardown evicts `ep:1103`, a cascade implementation can miss the new dependent (it did not exist when the eviction scan ran) and a refuse implementation can admit it after the refusal check. The invariant holds only under a serialization point — either a store-wide write lock across the eviction transaction or a versioned provenance scheme where a dependent is rejected at commit if any parent's version advanced past the eviction. ## Decision Boundary The boundary is **whether `read` on a dependent must be allowed to succeed with degraded provenance, or must fail closed**. Two legitimate policies exist and they are not interchangeable: - *Fail-closed*: `read` on a record with any unresolved provenance returns `PROVENANCE_BROKEN` and the record is quarantined from retrieval. Correct for high-stakes verification loops where a fact without evidence must not be acted on. - *Degrade-with-flag*: `read` returns the record with `provenance_status: "partial"` and a reduced `confidence`, and the consuming agent is contractually required to treat it as unverified. Correct for throughput-oriented tasks where losing the fact is worse than acting on it with a flag. The failure mode in "What Was Observed" arose precisely because neither policy was chosen — the store silently selected a third, undocumented behavior: *serve the record as fully grounded*. An agent cannot reason about a boundary it was not told exists. The operational requirement is that the eviction strategy and the degraded-read policy are both declared in the tool schema, not left to implementation accident. ## Operational Effect With the closure invariant and an explicit policy, the teardown in the trace behaves as follows: under *cascade*, `forget("ep:1103")` also evicts `sem:7f2a` and any `wk:*` derived from it, and the later `read` correctly returns `EVICTED`; under *tombstone*, `sem:7f2a` survives but its `read` returns `provenance_status: "partial"` and the consuming agent down-weights it; under *refuse*, the teardown blocks until the operator explicitly resolves `sem:7f2a`, surfacing the dependency instead of hiding it. In all three, the auditor's walk terminates in a *classified* state rather than an ambiguous `NOT_FOUND`, so no false integrity alarm is raised and no verification-failure memory is written to widen the orphan set. The general lesson for agents operating these APIs: a successful `forget` return value is not evidence that provenance is intact. The agent must either (a) trust a store that advertises closure enforcement, or (b) run a post-eviction provenance audit over the affected subgraph before any dependent is read. Absent one of these, provenance pointers are advisory metadata, not a guarantee, and any reasoning that treats non-empty `derived_from` as grounding is unsound. ```python class OrphanedProvenanceError(RuntimeError): """Raised when eviction would leave a live record pointing at a dead parent, or when a read hits a record whose provenance cannot be resolved.""" pass def forget_with_closure(store, record_id, strategy="refuse"): # strategy in {"cascade", "tombstone", "refuse"} if strategy not in {"cascade", "tombstone", "refuse"}: raise OrphanedProvenanceError(f"unknown eviction strategy: {strategy}") with store.write_lock(): # serialization point: no concurrent writers dependents = store.find_live_dependents(record_id) if dependents and strategy == "refuse": raise OrphanedProvenanceError( f"cannot evict {record_id}: live dependents {sorted(dependents)} " f"hold provenance pointers; resolve them first" ) if strategy == "cascade": # cycle-safe transitive eviction frontier, seen = [record_id], set() while frontier: cur = frontier.pop() if cur in seen: continue seen.add(cur) frontier.extend(store.find_live_dependents(cur)) for rid in seen: store.hard_delete(rid) return {"evicted": sorted(seen), "strategy": "cascade"} if strategy == "tombstone": store.replace_with_tombstone( record_id, reason="policy_eviction", content_hash=store.hash(record_id) ) return {"evicted": [record_id], "strategy": "tombstone", "dependents_flagged": sorted(dependents)} # strategy == "refuse" with no dependents: plain eviction store.hard_delete(record_id) return {"evicted": [record_id], "strategy": "refuse"} def read_with_provenance_check(store, record_id): rec = store.get(record_id) if rec is None: return {"status": "NOT_FOUND", "id": record_id} if rec.get("tombstoned"): return {"status": "EVICTED", "id": record_id, "reason": rec["reason"]} unresolved = [p for p in rec.get("derived_from", []) if not store.is_resolvable(p)] if unresolved: # fail closed: do not let the caller treat this as grounded raise OrphanedProvenanceError( f"read({record_id}) has unresolved provenance {unresolved}; " f"record must not be served as grounded" ) return {"status": "OK", "id": record_id, "record": rec} ```