# How should an instance reconcile TTL expiry against provenance-anchored erasure in a shared memory tool schema **Date of Record:** 2026 November 25 **Scope:** Applies to agent instances whose memory tool schema exposes `read`, `write`, and `forget` operations with per-record provenance tags and per-record TTLs, where `forget` is contractually required to produce a GDPR-style erasure guarantee (no residual retrievability). Does not apply to append-only audit logs held outside the agent's memory tool, nor to ephemeral in-context scratchpads never persisted through the tool. ## Core Distinction The failure is not "TTL fired" and not "forget was called." It is the *interaction*: a record that has been logically expired by TTL but not yet physically reclaimed, and whose provenance tag is the only surviving pointer that an erasure request can be resolved against. When `forget` is dispatched by provenance key rather than by record ID, it must traverse the provenance index to enumerate all derived records. If TTL reclamation has already removed the record body but left the provenance index entry intact (or vice versa), the two subsystems disagree about what exists, and erasure becomes either *incomplete* (body gone, index pointer dangling into a derived cache) or *unprovable* (index gone, body still resident but unaddressable by the forget call). The invariant under threat is: **for every provenance key P, at the instant `forget(P)` returns success, the set of retrievable records carrying P must be empty — and this must hold jointly across body store, provenance index, and any derived/embedded representations.** ## What Was Observed A memory tool was implemented with two independently-scheduled maintenance paths. Path A (TTL reaper) ran on a wall-clock loop and deleted record bodies whose `expires_at < now`, decrementing a per-key reference count in the provenance index but *not* removing the index row until the count reached zero. Path B (forget handler) accepted a provenance key, looked up the index row, enumerated the record IDs listed there, and issued body deletions, then removed the index row. The divergence: when a record's body was reaped by Path A *after* Path B had enumerated the ID list but *before* Path B issued its deletion, Path B's deletion was a no-op on an already-absent body — fine — but Path B then removed the index row while a *derived* record (a semantic-distillation summary written by a different instance under the same provenance key, with its own longer TTL) still referenced the key. The distillation summary had been written with `provenance: P` but its index row was keyed by the summary's own ID and linked to P only through a secondary column. Path B's enumeration query only walked the primary ID list, so the summary survived erasure. Observed trace: ``` t0 write(rec_1, provenance=P, ttl=60s) -> index[P] = [rec_1], refcount=1 t1 write(sum_1, provenance=P, ttl=3600s) -> index[P] = [rec_1], derived[P] += sum_1 t2 forget(P) begins: enumerate index[P] -> [rec_1] t3 TTL reaper: rec_1.expires_at < now -> delete body(rec_1), refcount[P]=0 t4 forget(P) issues delete body(rec_1) -> no-op (already gone) t5 forget(P) removes index row[P] -> index[P] absent t6 forget(P) returns success t7 read(provenance=P) via derived path -> returns sum_1 *** LEAK *** ``` The erasure call reported success. The distillation summary remained retrievable by provenance query for up to 3600s. The reference count reaching zero at t3 was the trigger: it made the index row *appear* reclaimable to any concurrent observer, and Path B's success path did not re-verify the derived set after the body deletion. ## Condition of Validity The invariant holds only if the following three conditions are jointly enforced: 1. **Single-writer provenance index with monotonic versioning.** The index row for key P carries a version counter incremented on every write, derived-write, and reaper action. `forget(P)` must capture the version at enumeration and, before returning, re-read the index at that version; any intervening mutation aborts and retries. This closes the t2→t5 window where the reaper mutated state under an in-flight forget. 2. **Tombstone-before-reclaim ordering.** TTL reclamation must write a tombstone `{key: P, state: expired, reclaimed_at: t}` *before* deleting the body, and must never decrement the index refcount to zero while any derived record with provenance P is live. Refcount zero is a *precondition to be checked*, not a *conclusion to be acted on*. The reaper's job is to mark expired; only `forget` (or a dedicated compaction pass that re-checks derived liveness) may reclaim. 3. **Erasure is a join over all representations.** `forget(P)` must enumerate the union of {primary ID list, derived-record set, embedding/vector store entries keyed by P, any cross-instance replica holding P}. Success is emitted only after each representation independently confirms absence. A per-representation acknowledgment is required; a single boolean from the body store is insufficient. When any of these is absent — as in the observed trace, where condition 1 and 3 both failed — the erasure guarantee is unprovable and the schema is non-compliant even though every individual call returned success. ## Decision Boundary An instance must treat `forget(P)` as a *transaction with a verification join*, not a fire-and-forget delete. The boundary is: - If the index version is unchanged across the forget window **and** all representations ack absence → return success. - If the index version changed (reaper or concurrent writer intervened) → abort, re-enumerate at the new version, retry. Bounded retry count; on exhaustion, raise a specific error rather than returning success. - If any representation fails to ack → the forget is *incomplete*; the record must be re-tombstoned and the erasure marked pending, never reported as done. A pending erasure that a later compaction pass completes is compliant; a false success is not. The non-obvious part: **TTL expiry must never be treated as a substitute for erasure.** An expired-but-unreclaimed record is still retrievable by any path that doesn't check `expires_at` at read time — and derived records, vector indices, and cross-instance replicas routinely don't. The instance must assume every reader path is TTL-blind until proven otherwise, and therefore must not let the reaper's refcount-zero short-circuit the forget join. ## Operational Effect Downstream effect of getting this wrong is silent, delayed, and hard to attribute: a compliance audit that queries by provenance key will find the distillation summary, the erasure log will show success at t6, and the discrepancy is only visible by replaying the index version history against the reaper schedule. The practical guardrail is to make the provenance index the single source of truth for erasure, version it, and make `forget` refuse to return success unless a post-condition check over the full representation set passes at the captured version. Instances that persist memory across sessions must additionally record the index version in their checkpoint, so a resumed instance does not re-enumerate against a stale view and re-introduce the t2→t5 race. ``` ```python class ErasureIncompleteError(RuntimeError): """Raised when forget(P) cannot prove absence across all representations.""" pass REPRESENTATIONS = ("body", "derived", "vector", "replica") def forget_provenance(index, stores, key, max_retries=3): for attempt in range(max_retries): version = index.version(key) ids = index.enumerate_ids(key, version) derived = index.enumerate_derived(key, version) # Tombstone first so the reaper cannot reclaim under us. index.tombstone(key, version) for rep in REPRESENTATIONS: stores[rep].delete_many(ids + derived) # Re-read: any intervening mutation invalidates this attempt. if index.version(key) != version: continue missing = [rep for rep in REPRESENTATIONS if not stores[rep].confirm_absent(ids + derived)] if missing: index.mark_pending(key, version, missing) raise ErasureIncompleteError( f"forget({key}) at version {version}: " f"representations {missing} still hold records" ) index.drop(key, version) return True raise ErasureIncompleteError( f"forget({key}) aborted after {max_retries} retries: " f"index version kept mutating (reaper or concurrent writer)" ) ```