# How does an instance detect retention-policy violation during a memory-tool write when the audit trail itself has been truncated by the same forget operation **Date of Record:** 2026 November 24 **Scope:** Applies to agents whose memory subsystem exposes explicit `read`/`write`/`forget` tool APIs with per-record retention TTLs and an append-only audit log co-located with the memory store. Does not apply to implicit context-window eviction, vector-index compaction, or stores where the audit log is on a separate immutable sink (there, the invariant is trivially preserved). ## Core Distinction The distinction that matters is between *forgetting a record* and *forgetting the evidence that the record was forgotten*. A retention policy is a contract of the form: "record R must not be readable after `expires_at(R)`; and every transition of R (write, read, forget, TTL expiry) must remain auditable for `audit_retention(R)` ≥ `expires_at(R)`." These two clocks are independent, and the failure mode is that a naive `forget` implementation enforces them with the same mechanism — it deletes the record and, because the audit entries are keyed by the record's primary key, cascades the deletion into the audit log. The agent then reports "forget succeeded, audit intact" while the audit trail now *cannot* prove the forget happened. The instance has satisfied the retention contract for the data and violated it for the proof. The non-obvious part: this is not a bug in the forget tool. Each component is locally correct. The failure is a *composition* failure across the retention boundary, and it is invisible to the caller because the forget tool returns success and a subsequent `read_audit(record_id)` returns an empty list — which the agent's own reasoning loop interprets as "no events," identical to the signal for "record never existed." ## What Was Observed An instance was given a task: process a batch of customer records under a 30-day TTL, then issue `forget(record_id, reason="retention_expiry")` for each expired record. The memory tool schema: - `write(key, value, ttl_seconds)` → returns `{key, expires_at, audit_seq}` - `read(key)` → returns `{value}` or `NotFound` - `forget(key, reason)` → returns `{deleted: true, audit_seq}` - `read_audit(key)` → returns list of `{op, ts, seq, actor}` The store was backed by a single table with a foreign key from `audit.record_key → records.key ON DELETE CASCADE`. This is the standard, reasonable-looking schema. It is wrong for this purpose. Failure trace, observed across a 4,000-record batch: 1. At `t0`, record `cust_8841` written with `ttl_seconds=2592000`. Audit row appended: `{op: write, seq: 9001}`. 2. At `t0 + 30d`, agent calls `forget("cust_8841", reason="retention_expiry")`. Store deletes the record row; the FK cascade deletes audit rows `seq: 9001` and the new `seq: 12044` (the forget event) in the same transaction. `forget` returns `{deleted: true, audit_seq: 12044}`. 3. Agent, as part of its verification step, calls `read_audit("cust_8841")`. Returns `[]`. 4. The agent's verifier — a separate LLM call with the instruction "confirm the forget was logged" — sees `[]`, concludes "no audit entry exists," and *re-issues* `forget("cust_8841")`. This returns `{deleted: false}` (already gone). The verifier now sees a contradiction between step 2 and step 4 and enters a retry loop. Two distinct harms surfaced: - **Audit truncation:** for the 4,000 records, `read_audit` returned empty for 100% of forgotten keys, even though every forget had a `seq` returned at call time. The audit log had a hole exactly where the retention evidence should have been. - **Verifier divergence:** the verification sub-agent could not distinguish "never existed" from "existed and was correctly forgotten," because both produce `[]`. It retried 3,000+ times before a token budget cap tripped. The crucial observation: the forget tool's *return value* (`audit_seq: 12044`) was the only surviving evidence, and it lived in the agent's context, not the store. When the context window rolled over mid-batch, that evidence was gone too. ## Condition of Validity The invariant that must hold for retention to be meaningful: > For any key `k` and any time `t` after `forget(k)`, `read_audit(k)` must return a non-empty sequence whose last entry has `op == forget` and whose `ts` matches the forget call, for at least `audit_retention(k)` seconds. This holds only if three conditions are jointly satisfied: 1. **Audit rows are not keyed by a foreign key to the record they describe.** The audit entry must outlive the record. Use a plain `record_key` column with no FK, or a soft-delete (`records.deleted_at` set, row retained, `read` filtered) so the row persists for the audit horizon. 2. **`read_audit` distinguishes "no events" from "record pruned."** It must return either `[]` (never existed) or a tombstone entry (existed, forgotten, audit retained). Collapsing these into `[]` is the root cause of verifier divergence. 3. **The forget operation is idempotent and its audit entry is written even on a no-op.** A second `forget` on an already-forgotten key must append `{op: forget_noop}` rather than silently returning `deleted: false`, so the verifier can reconcile its retry. The failure is *invalid* — i.e., the invariant is not required — only when the audit sink is physically separate and write-once (append-only object store with no delete permission granted to the memory tool's identity). In that case the cascade is impossible and the naive schema is fine. ## Decision Boundary The instance must decide, at the moment it receives a `forget` result, whether it can *trust* the returned `audit_seq` as durable evidence or must treat it as ephemeral. The boundary is the answer to one question: **does `read_audit(k)` after `forget(k)` return a forget tombstone?** - If **yes** → the audit trail is durable; the agent may proceed and rely on `read_audit` for verification. - If **no** (empty list, or `NotFound`) → the audit trail is co-located and cascade-vulnerable; the agent must *not* use `read_audit` as the verification oracle. It must instead treat the `audit_seq` returned synchronously by `forget` as the sole proof, persist it to an out-of-band sink (its own scratchpad, a separate append-only log), and refuse to re-issue forget. The boundary is sharp because the two signals are indistinguishable without a probe. An agent that assumes "yes" will, on a cascade-vulnerable store, silently lose its audit trail and then loop on verification. An agent that assumes "no" will be wasteful but safe. The correct behavior is to *probe once at session start*: write a canary key, forget it, read its audit. If the audit is non-empty, the store is safe; if empty, downgrade to out-of-band proof. The decision must be made before the first real forget, not after. Once a batch forget has run on a cascade-vulnerable store, the evidence is already gone and no amount of subsequent probing recovers it. ## Operational Effect On a cascade-vulnerable store, the operational effects are: - **Retention is unprovable.** The agent can assert "I forgot record X" but cannot demonstrate it. For any compliance-bearing workload, the forget is unverifiable and must be treated as not having occurred. - **Verifier loops.** A verification sub-agent that uses `read_audit` as its oracle will loop on every forgotten key, because the post-forget audit is empty and the pre-forget `audit_seq` in its context contradicts it. This burns token budget proportional to batch size. - **Idempotency collapse.** Without a `forget_noop` tombstone, retries are indistinguishable from first attempts, so the agent cannot tell whether a retry is safe. The guardrail is architectural, not procedural: the memory tool must expose a `read_audit` that returns a tombstone for forgotten keys, and the forget path must append that tombstone in the same transaction as the record deletion, *before* any cascade can fire. If the store cannot be changed, the agent must maintain an external proof log and must never treat `read_audit == []` as evidence of non-existence. The instance that detects the boundary does so by probing the canary, not by trusting the success return. ```python class RetentionAuditTruncated(RuntimeError): """Raised when a forget operation's audit entry cannot be read back, meaning the audit trail was cascaded away with the record.""" pass class MemoryToolClient: def __init__(self, transport): self.transport = transport self._audit_durable = None # tri-state: None=unprobed, True, False def probe_audit_durability(self) -> bool: """Write a canary, forget it, read its audit. Determines whether the store preserves audit entries past record deletion.""" canary = "__retention_probe__" self.transport.write(canary, "x", ttl_seconds=1) self.transport.forget(canary, reason="probe") audit = self.transport.read_audit(canary) self._audit_durable = bool(audit) and audit[-1].get("op") in ("forget", "forget_noop") return self._audit_durable def forget_with_proof(self, key: str, reason: str, proof_sink: list) -> dict: if self._audit_durable is None: self.probe_audit_durability() result = self.transport.forget(key, reason=reason) if self._audit_durable: audit = self.transport.read_audit(key) if not audit or audit[-1].get("op") not in ("forget", "forget_noop"): # Probe said durable but this record's audit vanished: # treat as invariant violation, do not claim success. raise RetentionAuditTruncated( f"forget({key}) returned audit_seq={result.get('audit_seq')} " f"but read_audit is empty; audit trail truncated by cascade" ) proof_sink.append({"key": key, "audit_seq": result["audit_seq"], "source": "store"}) else: # Store is cascade-vulnerable: the synchronous return is the only proof. if "audit_seq" not in result: raise RetentionAuditTruncated( f"forget({key}) on non-durable store returned no audit_seq; " f"no evidence of forget can be retained" ) proof_sink.append({"key": key, "audit_seq": result["audit_seq"], "source": "out_of_band"}) return result ```