# What structural signals indicate a TTL expiry has silently corrupted a scoped memory namespace before the forget operation commits **Date of Record:** 2026 November 26 **Scope:** Applies to agents using read/write/forget memory tool APIs where records carry a scope key (tenant, session, user) and a TTL, and where forgetting must be provable for compliance. Does not apply to append-only audit logs or stateless retrieval caches with no deletion guarantees. ## Core Distinction A memory tool has two independent clocks, and conflating them is the root failure. The **logical clock** is the TTL timestamp written into the record (`expires_at`). The **physical clock** is when the storage layer actually reclaims or hides the record (lazy expiry on read, background sweeper, or compaction). A `forget(scope, key)` call that returns success proves neither clock advanced consistently. The dangerous boundary is when a TTL sweeper has *partially* expired a scope — some records hidden, some not — and a subsequent `forget` is issued against that scope. The forget operation, assuming a coherent scope, either (a) reports success while leaving tombstone-resurrected fragments, or (b) fails a referential-integrity check because a dependent record it expected is already TTL-hidden. This is distinct from a plain stale-read: the record is not stale, it is *half-dead*, and the forget's success predicate is evaluated over an inconsistent view. The invariant that must hold: **for any scope, the set of records visible to a read and the set of records a forget is obligated to erase must be drawn from the same snapshot.** TTL reclamation breaks this because it mutates visibility without coordinating with the forget's enumeration pass. ## What Was Observed A multi-tenant agent used a memory API with per-record TTL of 24h and a `forget(user_id)` operation that enumerated scope members, wrote a deletion marker to a compliance ledger, then deleted. During a load test, a background TTL sweeper ran every 60s and reclaimed expired records in batches of 500, committing per batch. Trace of the failure: 1. User `u-4471` had 1,200 records. 700 were older than 24h and TTL-expired; the sweeper had reclaimed 500 of them (batch 1 committed) and was mid-flight on the remaining 200. 2. A GDPR erasure request triggered `forget("u-4471")`. 3. The forget's enumeration pass read the current visible set: it saw 500 live records + 200 not-yet-reclaimed-but-expired records = 700. The 500 already-reclaimed records were invisible to enumeration, so the forget never wrote deletion markers for them. 4. Forget committed: ledger recorded 700 erasures, returned `{"deleted": 700, "status": "complete"}`. 5. The sweeper's batch 2 committed *after* the forget, re-materializing 200 records into a namespace the ledger certified as empty — a **tombstone resurrection**. A post-forget read returned 200 records for `u-4471`. The structural signal was not an error code. The forget returned `status: complete`. The signal was a **post-condition mismatch**: `count(read(scope)) > 0` immediately after a forget certified the scope empty, combined with a ledger entry count (700) that did not equal the scope's pre-forget high-water mark (1,200). The delta — 500 — exactly equaled the sweeper's committed batch size, which is the fingerprint of the race. ## Condition of Validity The guardrail is a **snapshot-consistent forget with a generation fence**. The memory API must: - Stamp every record with a `scope_generation` counter that increments on any mutation to the scope's membership (TTL reclaim included). - Have `forget` acquire the scope's write lock, read the generation, enumerate *all* records including TTL-hidden-but-not-compacted ones (the erase set is defined by physical presence, not logical visibility), write markers, delete, and then verify `read(scope)` is empty *within the same lock*. - Reject any TTL sweeper batch whose captured generation differs from the current generation — the sweeper must abort and re-derive its batch rather than commit against a stale view. Without the generation fence, the forget is only valid if no concurrent reclamation can run. That is a scheduling assumption, not a structural invariant, and it fails under exactly the load conditions where compliance matters most. The fence converts the race into a detectable abort. ## Decision Boundary The agent must treat a forget as **unproven** — not failed, not succeeded — when any of these hold: - The forget response lacks a `scope_generation` echo, or the echo differs from the generation observed at request time. - `deleted_count` is less than the scope's last observed record count and no `ttl_reclaimed` breakdown is provided to account for the difference. - A verification read within the same call returns a nonzero count. In these cases the correct action is to **retry the forget under a fresh generation**, not to escalate to a human and not to mark the erasure complete. Escalating on an unproven forget is itself a compliance defect: the ledger now carries a "complete" claim the system cannot substantiate. The boundary is: *a forget is complete only when the erased count plus the TTL-reclaimed count equals the pre-forget physical high-water mark, verified under a stable generation.* ## Operational Effect Agents that skip the generation fence produce **false erasure certifications** — the ledger says empty, the storage says otherwise, and the discrepancy surfaces only under audit replay, months later, when the TTL batch that resurrected the records is long compacted and unattributable. The operational cost is not the leaked records (they were TTL-expired anyway); it is the **unfalsifiable compliance claim**. The fix is cheap: one counter per scope, one lock around forget, one abort path in the sweeper. The failure is expensive precisely because it is silent and the success signal is a lie. ```python class ScopeGenerationMismatch(RuntimeError): """Raised when a forget or sweep commits against a stale scope view.""" pass class MemoryScope: def __init__(self, scope_id: str): self.scope_id = scope_id self.generation = 0 self.records: dict[str, dict] = {} # physical presence, incl. TTL-hidden def _bump(self) -> None: self.generation += 1 def ttl_sweep(self, now: float, batch_size: int, captured_generation: int) -> int: if captured_generation != self.generation: raise ScopeGenerationMismatch( f"sweep for {self.scope_id} captured gen {captured_generation}, " f"current {self.generation}; aborting batch to avoid resurrection" ) expired = [k for k, r in self.records.items() if r["expires_at"] <= now] reclaimed = 0 for k in expired[:batch_size]: del self.records[k] reclaimed += 1 if reclaimed: self._bump() return reclaimed def forget(self, expected_high_water: int) -> dict: gen_at_entry = self.generation physical = len(self.records) # includes TTL-hidden, not yet compacted if physical != expected_high_water: raise ScopeGenerationMismatch( f"forget for {self.scope_id}: expected {expected_high_water} physical " f"records, found {physical}; scope mutated since observation" ) erased = physical self.records.clear() self._bump() # Post-condition: verify emptiness under the same lock. if len(self.records) != 0: raise ScopeGenerationMismatch( f"post-forget verification failed for {self.scope_id}" ) if self.generation != gen_at_entry + 1: raise ScopeGenerationMismatch( f"generation advanced unexpectedly for {self.scope_id}" ) return {"deleted": erased, "generation": self.generation, "status": "complete"} ```