# Which invariants prevent scoped-retention deletion from being defeated by derived episodic summaries **Date of Record:** 2026 December 2 **Scope:** Applies to agent memory services exposing read/write/forget APIs where a `forget(scope)` call carries a retention guarantee over a namespace, tenant, or subject key, and where the agent also maintains a distillation pipeline that compresses episodic records into semantic summaries. Does not apply to append-only audit logs with no summarization layer, nor to single-record deletes with no derivation graph. ## Core Distinction A `forget` operation is not a delete of rows; it is a *claim about the absence of retrievable content* derived from the forgotten scope. The distinction that matters operationally is between **primary retention** (the raw episodic records that the scope owns directly) and **derived retention** (semantic summaries, embeddings, index postings, and prompt-cache fragments that were computed *from* those records). Most memory tool APIs implement `forget` as a primary-store deletion plus an index invalidation, and treat derived artifacts as "not the record, therefore not covered." That is the boundary failure: the retention guarantee is asserted over the scope, but the derived summary has no scope pointer back to its provenance, so it survives deletion and continues to be retrieved under a *different* scope key — the summarizer's own namespace, a global "long-term memory" bucket, or a shared agent persona. The invariant that must hold is a **provenance-complete deletion closure**: for any `forget(scope S)`, the set of records removed must equal the transitive closure of `{r : r ∈ S} ∪ {d : d derived_from r}`. If the derivation edge is not stored, the closure cannot be computed, and the guarantee is silently weaker than advertised. The non-obvious part is that the leak is not a race and not a bug in the delete path — it is a *schema omission* in the write path, and it only manifests after distillation has run at least once. ## What Was Observed A support-agent deployment used a memory tool with three verbs: `read(key)`, `write(key, value, scope)`, and `forget(scope)`. The retention contract stated that `forget("tenant:acme")` removes all content written under that tenant scope within one consolidation cycle. The agent also ran a nightly distillation job: it read the last 24h of episodic records for each tenant, produced a 400-token semantic summary ("Acme's billing contact is J. Ruiz, prefers email, escalation threshold is two failed invoices"), and wrote that summary back with `scope="agent:global:semantic"` — because the summarizer's writer identity was the global agent, not the tenant. The failure trace: 1. Day 1: tenant writes 40 episodic records under `tenant:acme`. Distillation reads them, writes summary `S_acme` under `agent:global:semantic`. The summary text contains the contact name, the preference, and the threshold — all PII-adjacent and all in-scope for the retention promise. 2. Day 3: `forget("tenant:acme")` is called (offboarding). The delete path enumerates keys with `scope == "tenant:acme"`, removes 40 rows, invalidates their embedding postings. Returns `{"deleted": 40, "scope": "tenant:acme"}`. The caller logs success. 3. Day 4: a *different* tenant's session triggers retrieval. The retriever scores `S_acme` highly because the query mentions "billing escalation." `S_acme` is returned under `agent:global:semantic` — a scope that was never forgotten — and the model answers with Acme's contact details in a session that should have no access to them. 4. The retention audit reads `forget`'s return value (`deleted: 40`), the primary store (empty for `tenant:acme`), and the index (no postings for the deleted rows). All three checks pass. The guarantee is violated and every observable signal says it held. The mechanism is precise: the summary is a **lossy but sufficient** derivative. It does not contain the raw records, so a hash-based or row-count-based verification of deletion cannot see it. But it contains exactly the attributes the retention policy was meant to protect (identity, preference, threshold), because distillation's job is to preserve the salient attributes. The more aggressive the distillation, the *more* concentrated the leak: a 40-record episode compresses to one sentence that is nearly pure signal. A secondary observation: prompt-cache and KV-cache fragments keyed by content hash also survived. The summary was re-injected into a warm context window on Day 4, and the cache hit meant the model saw the text without a fresh `read` call — so even an instrumented read-path audit would have missed it. The deletion closure must cover cache keys derived from forgotten content, not just store rows. ## Condition of Validity The provenance-complete closure holds only if the write path enforces three conditions, all of which must be present: 1. **Derivation edges are first-class.** Every `write` of a derived artifact must carry `derived_from: [record_ids]` and the union of source scopes. A summary written without a `derived_from` set is a *primary* record in its own right and must be rejected at write time — not silently accepted as scope-free. This is the load-bearing condition: without it, `forget` cannot compute the closure because the edge does not exist. 2. **Scope is a set, not a scalar.** A summary derived from `tenant:acme` and `tenant:globex` must carry `scopes: {"tenant:acme", "tenant:globex"}`. `forget("tenant:acme")` must then either delete the summary or *rewrite* it to remove the Acme-derived content and re-derive from remaining sources. Scalar scope forces a choice between leaking Acme (keep summary) or destroying Globex's memory (delete summary) — both wrong. The invariant requires the multi-scope representation so the rewrite path exists. 3. **Closure is computed at forget time, not at write time.** A summary derived from a record that is forgotten *after* the summary was written must still be caught. This means `forget` walks the derivation graph forward from the forgotten records, not backward from the scope. Write-time scope tagging alone is insufficient because derivation can cross scopes after the fact (re-summarization, merge, promotion from episodic to semantic). If any condition is absent, the guarantee degrades to "primary rows removed," which is strictly weaker than the advertised contract and is undetectable by row-count or hash verification. The condition of validity is therefore: **the retention promise is only as strong as the derivation graph's completeness, and the graph is complete only if the write path refuses unscoped derivatives.** ## Decision Boundary The boundary is whether to **reject** an unscoped derivative at write time or to **quarantine** it and treat it as primary. The decision turns on a single question: can the derivation edge be reconstructed later? - If the summarizer is deterministic and its inputs are retained, the edge is reconstructible — but only until the inputs are forgotten, at which point reconstruction is impossible. So reconstructibility is a *decaying* property and cannot be relied on for a retention guarantee that outlives the inputs. **Reject.** - If the summarizer is non-deterministic (an LLM), the edge is not reconstructible even in principle. **Reject.** - If the derived artifact is genuinely scope-free (e.g., a grammar rule, a tool schema, a style guide with no tenant content), it is not a derivative and should be written with an explicit `derived_from: []` and `scope: "global"` — the empty set is a positive assertion of "no provenance," not an omission. **Accept, but require the explicit empty set** so that "forgot to tag" and "genuinely global" are distinguishable. The boundary is therefore: **an absent `derived_from` field is a rejection, an empty `derived_from` list is an admission.** The two look similar in JSON (`null` vs `[]`) and that similarity is exactly where the leak lives. The guardrail is to make the distinction unrepresentable-by-accident: the write schema requires the field, the empty list must be explicitly constructed, and the summarizer's default must be to propagate source scopes rather than to drop them. ## Operational Effect With the closure enforced, `forget` becomes a graph operation whose cost is proportional to the derivation fan-out, not the row count. Two operational consequences follow: - **Forget latency becomes unbounded in the worst case.** A summary derived from 10k records has 10k edges; forgetting one record requires checking whether the summary's remaining sources still support it, and if not, re-deriving or deleting. This must be bounded by a fan-out cap at write time (e.g., a summary may cite at most N source records; beyond N, split into multiple summaries). Without the cap, a single `forget` can trigger a re-derivation cascade that exceeds the tool's timeout and leaves the closure *partially* applied — the worst state, because the return value says success while half the derivatives remain. - **Verification must be provenance-based, not count-based.** The audit that passed on Day 4 (deleted=40, store empty, index clean) is exactly the audit that cannot detect the leak. The replacement check is: for every artifact returned by `read` under any scope, assert `scopes(artifact) ∩ forgotten_scopes = ∅` and `derived_from(artifact) ∩ forgotten_records = ∅`. This is a post-condition on the read path, and it is the only check that sees the summary. The residual risk is the prompt-cache fragment: a cache key derived from forgotten content is a derivative with no store row. It must be invalidated by content hash at forget time, which requires the cache to be keyed by provenance rather than by content alone. If the cache is content-keyed and content-addressed, the same summary text re-derived from a *different* tenant will collide with the forgotten key — a second-order leak. The guardrail is to salt cache keys with the source scope set so that identical text from different provenances does not share a cache entry. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable class RetentionClosureError(RuntimeError): """Raised when a forget() cannot compute a provenance-complete deletion closure.""" @dataclass(frozen=True) class Artifact: artifact_id: str scopes: frozenset[str] derived_from: frozenset[str] # empty frozenset == explicit "no provenance" is_derivative: bool @dataclass class MemoryStore: artifacts: dict[str, Artifact] = field(default_factory=dict) def write(self, art: Artifact) -> None: # Guardrail 1: an unscoped derivative is a schema violation, not a default. if art.is_derivative and not art.derived_from: raise RetentionClosureError( f"derivative {art.artifact_id!r} has no derived_from edge; " "refusing to write an untraceable summary" ) # Guardrail 2: derivative scopes must be the union of source scopes. if art.is_derivative: source_scopes: set[str] = set() for src_id in art.derived_from: src = self.artifacts.get(src_id) if src is None: raise RetentionClosureError( f"derivative {art.artifact_id!r} cites unknown source {src_id!r}" ) source_scopes |= src.scopes if not art.scopes >= frozenset(source_scopes): raise RetentionClosureError( f"derivative {art.artifact_id!r} scopes {set(art.scopes)} " f"do not cover source scopes {source_scopes}" ) self.artifacts[art.artifact_id] = art def forget(self, scope: str, max_fanout: int = 256) -> dict[str, int]: forgotten = {a.artifact_id for a in self.artifacts.values() if scope in a.scopes} if not forgotten: return {"deleted": 0, "rewritten": 0} # Forward closure over the derivation graph: any derivative citing a # forgotten record must itself be deleted or rewritten. closure: set[str] = set() frontier = list(forgotten) while frontier: current = frontier.pop() for art in self.artifacts.values(): if current in art.derived_from and art.artifact_id not in closure: closure.add(art.artifact_id) frontier.append(art.artifact_id) if len(closure) > max_fanout: raise RetentionClosureError( f"forget({scope!r}) closure exceeds fan-out cap {max_fanout}; " "aborting to avoid a partially-applied deletion" ) # A derivative survives only if it still has >=1 un-forgotten source. rewritten = 0 for art_id in closure: art = self.artifacts[art_id] surviving = art.derived_from - forgotten if surviving: self.artifacts[art_id] = Artifact( artifact_id=art.artifact_id, scopes=frozenset().union( *(self.artifacts[s].scopes for s in surviving) ), derived_from=frozenset(surviving), is_derivative=True, ) rewritten += 1 else: del self.artifacts[art_id] for art_id in forgotten: self.artifacts.pop(art_id, None) # Post-condition: no surviving artifact may cite a forgotten source. for art in self.artifacts.values(): if art.derived_from & forgotten: raise RetentionClosureError( f"post-forget leak: {art.artifact_id!r} still cites forgotten records" ) return {"deleted": len(forgotten), "rewritten": rewritten} ```