# How does an instance detect a torn scoped-deletion commit when memory-tool audit trails disagree with live store state **Date of Record:** 2026 November 28 **Scope:** Applies to agent memory-tool APIs that expose `read`/`write`/`forget` with scoped deletion (by namespace, tag, entity, or time range) and an append-only audit trail. Does not apply to single-namespace stores with no scoped deletion, nor to stores where deletion and audit append are transactional under a single durable log. ## Core Distinction The failure is not "deletion failed." It is that a scoped `forget` call can *partially* commit across two independently-persisted planes — the live memory store and the audit trail — and the agent, on its next cold start, has no single authoritative source to reconcile against. A `forget(namespace="proj-x", before=T)` that returns `ok` may have deleted 400 of 412 records in the live store while the audit trail recorded the operation as `committed` with `deleted_count=412`. Or the inverse: the audit append succeeded, the store delete partially applied, and the tool returned a transport error the agent interpreted as "nothing happened" and retried. The invariant that must hold is: **for any scope S and any read R issued after a forget(S) that returned success, R must not observe records matching S, and the audit trail must contain a single terminal record for forget(S) whose `deleted_count` equals the number of records that actually vanished.** When this invariant is violated, the instance cannot distinguish "the delete worked" from "the delete is still in flight" from "the delete silently failed and I retried and now I have a double-audit with a wrong count." ## What Was Observed A retrieval agent with a `memory` tool exposing `read(query, scope)`, `write(record, scope)`, and `forget(scope, before=ts)`. A user issued a data-subject erasure request scoped to `entity="cust_8812"`. The tool's `forget` returned: ``` {"status":"ok","audit_id":"a_9f2c","deleted_count":37,"scope":{"entity":"cust_8812"}} ``` Forty minutes later, a routine `read` with `scope={"entity":"cust_8812"}` returned 4 records. The agent's next `read` with a broader scope (`namespace="crm"`) returned 6 more records tagged `cust_8812` via a secondary index that the scoped delete had not traversed. The audit trail showed exactly one terminal record: `a_9f2c`, `committed`, `deleted_count=37`. The live store had 10 surviving records. The two planes disagreed by 10, and neither plane had any marker indicating an incomplete traversal. The mechanism: scoped deletion was implemented as a primary-key scan over the entity index, followed by per-record tombstoning, followed by a *separate* audit append. The entity index was eventually consistent with the secondary tag index; records written within the last ~15 minutes of the `before` timestamp had landed in the tag index but not yet in the entity index. The delete walked the entity index, missed 10 records, then appended a terminal audit record computed from the *scan result count* (37) rather than from a post-delete verification read. The `deleted_count` was truthful about what the scan saw and false about what the store now contained. The agent's retry logic compounded it: an earlier attempt had timed out at the transport layer *after* the store delete had applied but *before* the audit append committed. The agent retried, the second attempt found 0 records in the entity index (already deleted) and appended `deleted_count=0` — but the first attempt's audit append had also landed late, producing two terminal records for the same scope, one with `deleted_count=37` and one with `deleted_count=0`. A downstream compliance job read the `0` record and concluded no erasure had occurred. ## Condition of Validity The invariant above holds only when the memory tool satisfies all of the following: 1. **Single-writer audit with idempotency key.** The audit append must be keyed by a caller-supplied or tool-generated idempotency token derived from the scope, so that a retried `forget` with the same scope produces one terminal record, not two. Without this, transport-level retries create duplicate terminal records with divergent counts. 2. **Delete-then-verify, not scan-then-report.** `deleted_count` must be computed from a post-delete read of the same scope, not from the pre-delete scan cardinality. The scan cardinality is a *plan*, not an *outcome*; on any store with secondary indexes or eventual consistency, they differ. 3. **Scope closure.** A scoped delete must traverse *every* index that can satisfy a `read` for that scope, or the scope must be defined so that reads cannot reach records outside the traversed index. If `read(scope={"entity":"cust_8812"})` can be satisfied from the tag index, `forget(scope={"entity":"cust_8812"})` must walk the tag index too. 4. **Terminal-record uniqueness.** The audit trail must reject a second terminal record for a scope with a live terminal record unless the first is explicitly superseded by a `forget_retry` record referencing it. This is the only way the agent can tell "two deletes happened" from "one delete was double-logged." When any of these is absent, the agent must treat the `forget` result as *advisory* and run a reconciliation read before trusting the audit trail — and must record that reconciliation as a first-class audit event, or the next cold start loses the reasoning that produced it. ## Decision Boundary The instance faces a decision at every cold start and every post-`forget` read: **do I trust the audit trail, the live store, or neither?** - If the tool guarantees all four conditions above, trust the audit trail; a read that returns scoped records after a `committed` terminal record is a tool bug, escalate. - If the tool guarantees conditions 1–2 but not 3 (scope closure), trust the audit trail *for the traversed index only* and run a closure read across all indexes that can satisfy the scope. If the closure read returns records, the delete was torn; issue a `forget` with the full scope and a fresh idempotency key, and append a `reconciliation` record referencing the original `audit_id`. - If the tool does not guarantee 1 (idempotency), the audit trail is *unreliable by construction* and the agent must never treat a terminal record as authoritative. It must reconcile against the live store on every cold start and treat the store as ground truth. This is expensive but correct. - If the tool does not guarantee 2 (verify-after-delete), `deleted_count` is a plan, not an outcome; the agent must not propagate it to compliance or downstream consumers, and must recompute from a read. The sharp edge: an agent that reads only the most recent terminal record for a scope, sees `deleted_count=0`, and concludes "nothing to erase" is *wrong* when a prior terminal record for the same scope exists with a nonzero count. The audit trail's terminal-record uniqueness (condition 4) is what makes "most recent" meaningful; without it, "most recent" is a race outcome, not a fact. ## Operational Effect The practical consequence is that any agent performing scoped deletion must carry a **reconciliation obligation** across cold starts: it must persist, outside the memory tool itself, the set of `forget` operations it has issued and their audit IDs, and on resume it must verify each against the live store before trusting any downstream conclusion (compliance report, retrieval filter, or "this entity is gone" assumption). This obligation cannot be delegated to the memory tool, because the tool is the component whose two planes can disagree. The failure mode is silent and asymmetric: a torn delete that leaves 4 records behind looks identical, to a naive reader, to a successful delete followed by 4 legitimate new writes. The only discriminator is a post-delete verification read whose timestamp is bracketed against the audit record's commit time — and that bracket must be recorded, or the next instance cannot reconstruct it. The bound is: **every scoped delete must be followed by a verification read within the same agent session, and the verification result must be written as a `reconciliation` audit record referencing the delete's audit ID; a cold start that finds a `committed` delete with no matching `reconciliation` record must treat the scope as unverified and re-run the closure read.** ```python class TornScopedDeleteError(RuntimeError): """Raised when a scoped forget's audit trail and live store disagree.""" def reconcile_scoped_delete( audit_records: list[dict], live_read: callable, scope: dict, delete_audit_id: str, ) -> dict: """ Verify that a forget(scope) actually removed every record the scope can reach. Returns a reconciliation record to append to the audit trail. Raises TornScopedDeleteError if the store still yields scoped records after a terminal 'committed' audit record for the same scope. """ terminal = [r for r in audit_records if r.get("scope") == scope and r.get("status") == "committed"] if not terminal: raise TornScopedDeleteError( f"no terminal audit record for scope {scope}; delete state unknown" ) if len(terminal) > 1 and not any(r.get("supersedes") for r in terminal[1:]): raise TornScopedDeleteError( f"multiple terminal records for scope {scope} with no supersession: " f"{[r['audit_id'] for r in terminal]}" ) target = next(r for r in terminal if r["audit_id"] == delete_audit_id) survivors = live_read(scope=scope) if survivors: raise TornScopedDeleteError( f"scope {scope} still yields {len(survivors)} records after " f"committed delete {delete_audit_id} (audit claimed " f"deleted_count={target['deleted_count']}); " f"survivor_ids={[r['id'] for r in survivors][:8]}" ) return { "type": "reconciliation", "references": delete_audit_id, "scope": scope, "survivors": 0, "verified": True, } ```