# Which invariants prevent salience-gated deletion from silently erasing co-referenced memories in agent memory tool APIs **Date of Record:** 2026 November 29 **Scope:** Applies to agent memory tool APIs that expose `write`, `read`, and `forget` operations where `forget` accepts either an explicit ID or a salience/decay predicate (`salience < τ`, `age > T`). Does not apply to append-only logs with no deletion surface, or to vector stores where deletion is always by exact primary key with no predicate evaluation. ## Core Distinction There are two structurally different ways a memory store can lose a record under a decay policy: **targeted deletion** (the agent names an ID or a predicate and the store removes exactly the matching rows) and **salience-gated reaping** (the store evaluates a salience score derived from access counts, recency, and linkage, then removes records that fall below a threshold). The failure mode this record addresses lives only in the second: a salience predicate that is *correct per-row* can be *incorrect per-cluster* because salience is computed from a graph — a memory's score is a function of its own access history *and* the decay of the records that reference it. When a `forget` call evaluates `salience < τ` over a set of co-referenced memories, it reaps the low-salience parents first, which orphans or invalidates the children, which then collapse below threshold on the *next* evaluation even though the agent never asked to touch them. The deletion is monotonic in a way the agent did not authorize. The invariant that bounds this: **a predicate-driven `forget` must be evaluated against a salience snapshot that is frozen at call entry, and every record reaped must be reported with the transitive set of records whose salience changed as a consequence — before those consequences are committed.** Without that, salience decay becomes a cascade the caller cannot see. ## What Was Observed An agent maintaining a task memory store wrote 40 records across three sessions. Records carried `id`, `content`, `refs` (list of other record IDs), `salience` (float, recomputed lazily on read), and `last_touched` (timestamp). Salience was defined as a weighted sum of `recency_decay(last_touched)`, `access_count`, and `inbound_ref_count` — the last term being the number of other live records that listed this record in `refs`. The agent issued `forget(predicate="salience < 0.15")` intending to prune stale scratch notes. The evaluation walked records in insertion order. Record `r07` (a scratch note, salience 0.09) was reaped. `r07` was the sole inbound ref for `r19` (a distilled conclusion, salience 0.22 — above threshold). After `r07` was removed, `r19`'s `inbound_ref_count` dropped to 0, its recomputed salience fell to 0.11, and because the predicate walk had not yet reached `r19`, it was reaped in the same call. The agent received a deletion receipt listing `[r07, r19]` with no indication that `r19` was reaped *by cascade* rather than *by predicate match at entry*. The distilled conclusion was gone, and because `forget` is destructive (no tombstone in this implementation), it could not be reconstructed from the store. A second observation from the same run: the agent retried the `forget` after a transport timeout, and because the first call had partially committed (reaped `r07` but not `r19` before the timeout), the retry evaluated a *different* salience snapshot and reaped a different set. The two calls together removed `r07`, `r19`, and `r22` — `r22` was reaped by the retry because `r19`'s removal had changed `r22`'s inbound count. Non-idempotent predicate deletion plus cascade equals unbounded, invisible scope. ## Condition of Validity The frozen-snapshot-plus-transitive-report invariant holds only when the following are true, and each is a precondition the agent must verify before trusting a `forget` receipt: 1. **Salience is a pure function of a snapshot.** If the store recomputes salience mid-walk (as above), the predicate is evaluated against a moving target. The invariant requires the store to materialize `salience_at_entry` for every candidate record before any deletion commits, and to evaluate the predicate against that materialized value only. 2. **Cascade is computed, not emergent.** The store must compute the transitive closure of records whose `inbound_ref_count` would change as a result of each candidate deletion, and must report that closure. A record reaped *because* its parent was reaped is a cascade victim and must be labeled as such. 3. **Deletion is transactional per call.** Either the full candidate set plus its cascade closure commits, or nothing does. Partial commit (the timeout case above) violates the invariant because the retry sees a different graph. 4. **The predicate is not re-evaluated on retry.** Idempotency for predicate `forget` requires a call-scoped token: the retry must reference the original snapshot, not recompute. If the store cannot do this, the agent must not retry a predicate `forget` — it must first `read` the candidate set, then issue targeted `forget(id=...)` calls. Where these do not hold — e.g., a store that computes salience lazily on read and has no snapshot primitive — the agent must degrade to targeted deletion and treat salience as advisory only. ## Decision Boundary The boundary between safe and unsafe use of predicate `forget` is this: **a predicate `forget` is safe iff the agent can enumerate, before the call, the set of records whose salience depends on any candidate's liveness.** In practice the agent cannot compute this without reading the full ref graph, which is exactly the read the store was trying to avoid. Therefore the operational rule is: - If the store exposes `forget(predicate=..., dry_run=True)` returning the candidate set *and* the cascade closure with per-record `reason` (`predicate_match` vs `cascade`), the agent may commit predicate deletion, but must inspect the closure for any `cascade` victim whose content is not duplicated elsewhere, and must re-write those victims with pinned salience (`salience_floor`) before committing. - If the store does not expose `dry_run`, the agent must never issue predicate `forget`. It must `read` candidates, filter locally, and issue targeted `forget(id=...)` one at a time, re-reading the ref graph between calls if any deleted record had inbound refs. - A `forget` receipt that lists more records than the agent's local candidate set, without labeling cascade victims, is a **cascade leak** and must be treated as a potential data-loss event: halt further `forget` calls, `read` the surviving ref graph, and reconcile against the agent's own episodic record of what it wrote. The threshold `τ` itself is not the boundary — the boundary is whether the agent can distinguish a record that *matched* the predicate from a record that *fell below it as a consequence of a match*. ## Operational Effect With the invariant enforced (frozen snapshot, computed cascade closure, per-call transaction, snapshot-pinned retry), predicate `forget` becomes a bounded operation: the agent knows exactly which records it authorized for deletion and which were collateral, and can pin or re-write collateral before commit. The cost is that the store must materialize salience and walk the ref graph at call entry — O(records + edges) per call — rather than lazily. For a 40-record store this is negligible; for a 10⁵-record store the agent should batch by ref-connected component so each `forget` call touches one component and the cascade closure is bounded by that component's size. Without the invariant, the observed failure is silent, unbounded, and non-reconstructable: a single `forget(salience < 0.15)` removed a distilled conclusion the agent had spent a session building, and a retry after timeout removed a third record the agent never named. The agent's subsequent `read` returned a store that looked internally consistent — no dangling refs, because the store reaped orphans — which is the worst property: the corruption is invisible to post-hoc consistency checks. The only recovery is the agent's own external episodic log, which is precisely the memory the store was supposed to offload. ```python class CascadeLeakError(RuntimeError): """Raised when a predicate forget reaps records not matched at entry.""" class SalienceSnapshotMissingError(RuntimeError): """Raised when the store cannot freeze salience before deletion.""" def safe_forget(store, predicate: str, tau: float, dry_run: bool = True) -> dict: """ Enforce the frozen-snapshot + cascade-closure invariant around a predicate-driven forget. Returns a receipt the agent can audit. """ if not getattr(store, "supports_snapshot", False): raise SalienceSnapshotMissingError( f"store {store.name!r} cannot freeze salience; " "degrade to targeted forget(id=...) instead" ) snapshot = store.snapshot_salience() # frozen at entry, never recomputed candidates = {rid for rid, s in snapshot.items() if s < tau} # Compute transitive cascade closure against the frozen graph. closure = store.cascade_closure(candidates) victims = closure - candidates if victims and not dry_run: unpinned = [v for v in victims if not store.is_pinned(v)] if unpinned: raise CascadeLeakError( f"predicate {predicate!r} would reap {len(unpinned)} " f"cascade victims without pinning: {sorted(unpinned)}; " "pin or re-write these before committing" ) receipt = { "matched": sorted(candidates), "cascade_victims": sorted(victims), "snapshot_token": snapshot.token, "committed": False, } if dry_run: return receipt # Transactional commit keyed to the snapshot token so a retry # cannot re-evaluate against a mutated graph. store.commit_forget( ids=candidates | victims, expected_token=snapshot.token, idempotency_key=snapshot.token, ) receipt["committed"] = True return receipt def retry_forget(store, prior_receipt: dict) -> dict: """Retry must reference the original snapshot token, never recompute.""" if "snapshot_token" not in prior_receipt: raise CascadeLeakError( "refusing to retry predicate forget without a snapshot token; " "recompute would evaluate a different graph" ) return store.commit_forget( ids=set(prior_receipt["matched"]) | set(prior_receipt["cascade_victims"]), expected_token=prior_receipt["snapshot_token"], idempotency_key=prior_receipt["snapshot_token"], ) ```