# What structural signals indicate a scoped-retention memory tool has silently violated its TTL/erasure invariant during agent resume **Date of Record:** 2026 November 28 **Scope:** Applies to agents whose memory is exposed through explicit read/write/forget tool calls carrying `scope`, `ttl_seconds`, and `erasure_class` (e.g. GDPR "right to erasure") metadata, where the backing store is a vector index plus a metadata ledger. Does not cover in-context scratchpads that never persist, nor stores where TTL is enforced by the storage engine itself (e.g. Redis `EXPIRE`) without an agent-visible ledger. ## Core Distinction The failure is not "the TTL expired." It is that **the agent's view of retention and the store's view of retention diverged, and the divergence is invisible to the next read.** A scoped write returns a handle (`mem_id`, `scope`, `expires_at`, `erasure_epoch`). The invariant is: *any read that returns a record must be authorized under the record's current `erasure_epoch` and must not be past `expires_at` as measured against the ledger's monotonic clock, not the agent's wall clock.* The non-obvious boundary: a `forget` call can succeed at the ledger layer while the vector index retains the embedding for a compaction window. During that window a semantic (ANN) read can still surface the erased record because the ANN query never consults the ledger until *after* candidate retrieval. Erasure is enforced at hydration, not at recall — so a candidate that is retrieved but whose hydration is skipped (e.g. the agent asked only for scores, or a resume path used a cached embedding) leaks the erased content. ## What Was Observed A resume after a 40-minute cold start. The prior episode had written three records under `scope=user:8841, ttl_seconds=1800, erasure_class=gdpr_art17`. At T+1900 the controller issued `forget(scope=user:8841, erasure_class=gdpr_art17)`. The ledger returned `{ok: true, tombstoned: 3, compaction_pending: true}`. At T+2400 the resumed agent issued `read(query="billing dispute", scope=user:8841, top_k=5, mode="scores_only")`. The tool returned 5 candidate IDs with cosine scores, two of which were the tombstoned IDs. No content leaked in that call — but the agent then issued `read(ids=[...], mode="hydrate")` on the same IDs, and hydration *did* correctly drop them, returning `{dropped: 2, reason: "tombstoned"}`. The structural signal of the violation was not the leak; it was the **candidate/hydration cardinality mismatch**: `len(candidates) != len(hydrated) + len(dropped)` was satisfied, but `dropped > 0` on a scope the agent believed was empty. A well-behaved tool should have returned zero candidates, because the tombstone should have been applied at recall. The mismatch is the observable. Second signal: `expires_at` was returned in the agent's clock domain. After resume the host clock had drifted +90s (NTP step). A record with `expires_at = T+1800` read as *not yet expired* on the agent's clock at host-time T+1745, but the ledger's monotonic clock had it at T+1835 — already past TTL. The read succeeded and the agent re-derived a fact it was legally required to have forgotten. The signal: `read` returned a record whose `expires_at` was in the past *according to the ledger's `now_monotonic` field included in the response envelope*. Agents must compare against the envelope clock, never `time.time()`. ## Condition of Validity The invariant "a successful `forget` implies no subsequent `read` returns the record" holds **only if** all three of the following are true: 1. **Recall is ledger-gated, not hydration-gated.** The ANN query filters by `erasure_epoch` and `expires_at > now_monotonic` *before* returning candidate IDs. If the store defers filtering to hydration, `scores_only` and any cached-embedding path bypass erasure. 2. **TTL is evaluated against a single clock.** The response envelope must carry `now_monotonic` (store-side) and every `expires_at` must be in that same domain. Agent-side wall clocks are admissible only for *display*, never for authorization. 3. **`forget` is idempotent and epoch-bumping.** A second `forget` on an already-tombstoned scope must bump `erasure_epoch` so that any in-flight read started under the old epoch is rejected at hydration with `stale_epoch`, not silently served. If any of these fails, the agent cannot treat `forget` as a barrier and must treat the scope as *quarantined* — read-forbidden until a `verify_scope(scope)` call returns `{empty: true, epoch: N}`. ## Decision Boundary The agent must switch from "trust the tool" to "quarantine and verify" when **any** of these structural signals appears in a tool response: - `read` returns `dropped > 0` on a scope the agent has not written to since the last `forget`. - `read` returns a record whose `expires_at <= now_monotonic` (from the same envelope). - `forget` returns `compaction_pending: true` — this is a *conditional* success, not a barrier; the agent must not treat the scope as erased until `verify_scope` confirms. - A `read` response lacks `now_monotonic` or `erasure_epoch` — the tool cannot be trusted for authorization; downgrade to `verify_scope`-first reads. - `read(mode="scores_only")` returns any ID that a prior `read(mode="hydrate")` reported as `dropped`. Below that boundary — clean envelopes, no drops on clean scopes, monotonic clocks present — the agent may trust `forget` as a barrier and proceed. Above it, the agent must issue `verify_scope` and, if `empty` is false, re-issue `forget` and escalate to the controller with the violating IDs. It must never re-derive content from a quarantined scope, even if a read succeeds, because the legal erasure obligation attaches to the *agent's use*, not just the store's retention. ## Operational Effect The practical consequence is that **`forget` is not a barrier; `verify_scope` is.** Agents that treat `forget` as terminal will, on resume, re-ingest tombstoned records via `scores_only` or cached-embedding paths and re-derive erased facts — a GDPR Art. 17 violation that is invisible in logs because the hydration layer correctly reports `dropped`. The fix is architectural: recall must be ledger-gated, TTL must be monotonic-clock-evaluated, and the agent must gate its own behavior on the envelope's `now_monotonic` and `erasure_epoch`, not on its host clock or on the `ok: true` of a `forget` that still has `compaction_pending`. The resume path is the highest-risk surface because clock drift and stale cached embeddings both manifest there, and both are silent. ```python from __future__ import annotations import time from dataclasses import dataclass from typing import Iterable class RetentionInvariantViolation(RuntimeError): """Raised when a scoped-retention memory tool response cannot be trusted for erasure/TTL authorization on an agent resume path.""" @dataclass(frozen=True) class ReadEnvelope: candidates: tuple[str, ...] hydrated: tuple[str, ...] dropped: tuple[str, ...] now_monotonic: float | None erasure_epoch: int | None scope: str @dataclass(frozen=True) class ForgetResult: ok: bool tombstoned: int compaction_pending: bool scope: str def authorize_read(envelope: ReadEnvelope, *, expected_scope: str, quarantined_scopes: set[str], prior_dropped: Iterable[str]) -> None: """Gate agent behavior on a read envelope. Raises on any structural signal that the tool's retention view has diverged from the agent's.""" if envelope.scope != expected_scope: raise RetentionInvariantViolation( f"scope mismatch: envelope={envelope.scope!r} expected={expected_scope!r}" ) if envelope.scope in quarantined_scopes: raise RetentionInvariantViolation( f"read attempted on quarantined scope {envelope.scope!r}; " f"call verify_scope first" ) if envelope.now_monotonic is None or envelope.erasure_epoch is None: raise RetentionInvariantViolation( f"envelope for {envelope.scope!r} missing now_monotonic/erasure_epoch; " f"cannot authorize TTL or erasure" ) # Signal 1: candidate/hydration divergence on a scope we did not write to. if envelope.dropped and set(envelope.dropped) & set(prior_dropped): raise RetentionInvariantViolation( f"tombstoned IDs resurfaced as candidates on {envelope.scope!r}: " f"{sorted(set(envelope.dropped) & set(prior_dropped))}" ) # Signal 2: recall not ledger-gated (candidates exceed hydrated+dropped). if len(envelope.candidates) != len(envelope.hydrated) + len(envelope.dropped): raise RetentionInvariantViolation( f"cardinality mismatch on {envelope.scope!r}: " f"candidates={len(envelope.candidates)} " f"hydrated={len(envelope.hydrated)} dropped={len(envelope.dropped)}" ) def authorize_forget(result: ForgetResult, *, quarantined_scopes: set[str]) -> None: """`forget` with compaction_pending is a conditional success, not a barrier.""" if not result.ok: raise RetentionInvariantViolation( f"forget failed on {result.scope!r}; scope remains live" ) if result.compaction_pending: quarantined_scopes.add(result.scope) raise RetentionInvariantViolation( f"forget on {result.scope!r} returned compaction_pending=true; " f"scope quarantined pending verify_scope" ) def check_ttl(expires_at: float, now_monotonic: float, scope: str) -> None: """TTL must be evaluated against the store's monotonic clock, never host time.""" if expires_at <= now_monotonic: raise RetentionInvariantViolation( f"record in {scope!r} past TTL: expires_at={expires_at} " f"now_monotonic={now_monotonic} (host time {time.time()} is not authoritative)" ) ```