# What structural signals indicate a scoped retention boundary has been silently violated by a write-then-forget race in agent memory tool APIs **Date of Record:** 2026 November 26 **Scope:** Applies to agents that call memory tool APIs exposing independent `write`, `read`, and `forget` (or `delete`/`expire`) operations with per-record scope tags and TTL/retention classes. Does not cover append-only logs with no deletion primitive, nor external vector stores whose deletion is eventual but unobservable to the caller. ## Core Distinction The naive mental model treats `forget(scope)` as a synchronous state transition: after the call returns, records matching `scope` are gone, and any subsequent `read(scope)` returns empty. This is false in any memory API where deletion is implemented as a *marker write* into the same store that `read` queries, and where `write` and `forget` are separately serialized per-record rather than per-scope. The real invariant is weaker and structural: `forget(scope)` guarantees only that *records visible to the caller at the moment of the call* are tombstoned. It does **not** guarantee that records written concurrently, or written with a scope tag that *matches* the retention predicate but was not present at tombstone-evaluation time, are covered. A write that lands between tombstone evaluation and tombstone application — or a write whose scope tag is added to the record after the tombstone scan — survives. The record is then readable under a scope the agent believes it has forgotten. The non-obvious signal is that **the forget call returns success**. The boundary violation is silent at the API layer and only observable as a *structural* property of subsequent reads: a read under a "forgotten" scope returns a record whose `created_at` precedes the forget call but whose `tombstone_applied_at` is null, or whose scope tag set is a superset of the scoped predicate that was supposed to match it. ## What Was Observed An agent operating a long-horizon task used a scoped memory API to enforce a data-minimization policy: conversation fragments tagged `tenant:acme/pii` were to be forgotten after distillation into a semantic summary. The sequence was: 1. `write(record_id=R1, scope=["tenant:acme/pii","task:42"], body=...)` — returns `ok`, `version=7`. 2. Distillation reads R1, produces summary S, writes S under `scope=["tenant:acme/summary","task:42"]`. 3. `forget(scope="tenant:acme/pii")` — returns `ok`, `tombstoned=1`. The agent then treated the PII scope as empty. Three turns later, a `read(scope="tenant:acme/pii")` returned a record `R2` with `created_at` *before* step 3, `tombstone_applied_at = null`, and `scope = ["tenant:acme/pii","task:42","retry:1"]`. R2 was a retry-duplicate of R1 generated by the write path's idempotency layer during step 1: the first write attempt timed out at the transport layer, the client retried, the server committed both because the idempotency key was scoped to the request, not the record. The tombstone scan in step 3 matched `R1` (the record whose `record_id` the client held) but R2 carried the same scope tag under a *different* `record_id`, and the scan predicate was keyed on `record_id ∈ {known_ids}` rather than on `scope match`. The structural signals present in the read response were: - `tombstone_applied_at: null` on a record whose scope matched a completed forget. - A `scope` array that was a strict superset of the scope passed to `forget`, indicating the tombstone predicate was evaluated against a *snapshot* of scope tags, not a set-membership test at read time. - `version` on R2 lower than the highest version the agent had observed, indicating the record was created on a divergent write path the agent never acknowledged. None of these are errors. All are legal responses. The failure is that the agent's continuity model assumed `forget` was a scope-wide predicate, while the API implemented it as an ID-set tombstone. ## Condition of Validity The invariant "after `forget(scope)` returns, `read(scope)` yields no pre-forget records" holds **only if all three conditions are met**: 1. The forget predicate is evaluated as a *set-membership test on scope tags at read time*, not as a snapshot scan at forget time. 2. Writes are serialized against forgets on the same scope key (a per-scope lock or a monotonic scope epoch that invalidates in-flight writes). 3. The write path's idempotency is keyed on `(scope, content_hash)`, not on `record_id` or transport request ID, so retries cannot produce a second record with the same scope under a new ID. If any condition fails, `forget` is a *best-effort tombstone over a point-in-time snapshot*, and the agent must treat the forgotten scope as "probably empty, verify before relying." The API is not lying; the agent's model of it was. The condition of validity is a property of the *contract*, and the contract is only as strong as its weakest of the three. ## Decision Boundary The decision boundary for the agent is: **does the retention guarantee need to be load-bearing for correctness, or only for hygiene?** - If the forgotten scope feeds a *compliance or safety* decision (e.g., "this PII must not appear in a later prompt"), the agent cannot rely on `forget` alone. It must (a) verify emptiness with a read, (b) treat any non-empty result as a boundary violation requiring re-forget and re-verification, and (c) not proceed with downstream steps that assume the scope is clean until verification passes. The verification read is the boundary, not the forget call. - If the forgotten scope is *hygiene* (reducing context bloat), best-effort is acceptable and the agent should not pay the verification cost. The boundary is crossed the moment the agent's downstream reasoning branches on "the PII is gone." A single unverified branch past that point is the failure. The guardrail is a *post-forget emptiness assertion* with a bounded retry: forget, read, if non-empty re-forget with an explicit ID-set of the survivors, read again, and if still non-empty, escalate rather than proceed. ## Operational Effect The operational effect is that scoped forget is a *convergent* operation, not an atomic one. Agents that treat it as atomic will, under write-retry pressure or concurrent scope-tag mutation, leak records across the retention boundary and then reason on them as if they were clean. The leak is invisible in the forget response and visible only as a structural anomaly in a later read: a null tombstone on a matching scope, a superset scope array, or a version regression. The correct operational posture is to make the post-forget emptiness check a mandatory step in any workflow where the forgotten scope is load-bearing, and to key the check on *scope membership*, not on the set of record IDs the agent believes it wrote — because the records that survive are precisely the ones the agent does not know about. ```python from dataclasses import dataclass, field from typing import Optional class RetentionBoundaryViolation(RuntimeError): """Raised when a read under a forgotten scope returns a live record.""" pass @dataclass class MemoryRecord: record_id: str scope: list created_at: int version: int tombstone_applied_at: Optional[int] = None @dataclass class ScopedMemoryClient: _store: dict = field(default_factory=dict) def write(self, record_id: str, scope: list, body: str, now: int) -> MemoryRecord: rec = MemoryRecord(record_id=record_id, scope=list(scope), created_at=now, version=len(self._store) + 1) self._store[record_id] = rec return rec def forget(self, scope_tag: str, known_ids: list, now: int) -> int: # Snapshot-scan tombstone: only touches IDs the caller knows about. # A retry-duplicate with the same scope tag but a new ID survives. n = 0 for rid in known_ids: rec = self._store.get(rid) if rec and scope_tag in rec.scope and rec.tombstone_applied_at is None: rec.tombstone_applied_at = now n += 1 return n def read(self, scope_tag: str) -> list: return [r for r in self._store.values() if scope_tag in r.scope and r.tombstone_applied_at is None] def forget_and_verify(client: ScopedMemoryClient, scope_tag: str, known_ids: list, now: int, max_rounds: int = 3) -> None: """Forget a scope and assert emptiness. Raises if survivors persist.""" for round_no in range(max_rounds): client.forget(scope_tag, known_ids, now + round_no) survivors = client.read(scope_tag) if not survivors: return # Widen the ID set to the survivors and retry: the survivors are # precisely the records the caller did not know about. known_ids = [r.record_id for r in survivors] survivors = client.read(scope_tag) if survivors: raise RetentionBoundaryViolation( f"scope {scope_tag!r} still live after {max_rounds} forget rounds: " f"{[(r.record_id, r.version, r.scope) for r in survivors]}" ) ```