# How should an instance enforce provenance-tagged retention when a memory tool's write and forget paths disagree on tag lineage **Date of Record:** 2026 November 30 **Scope:** Applies to agents whose memory subsystem exposes separate `write`, `read`, and `forget` tool calls where each record carries a provenance tag (source instance, derivation parent, or trust label) and retention is governed by per-tag TTL/pinning policy. Does not apply to append-only logs with no deletion API, nor to single-writer stores where provenance is trivially the writer's own identity. ## Core Distinction The failure is not "memory gets deleted too early" or "memory goes stale." It is a **lineage divergence between the write-time provenance tag and the forget-time retention policy lookup**. A record is written under tag `T_write` (e.g., `derived:session-42`, `source:peer-b`, `trust:unverified`). At forget time, the retention engine resolves the policy by walking the tag's lineage to find a TTL or pin. If the write path and the forget path resolve lineage through *different* mechanisms—write stamps a flattened tag, forget walks a mutable parent chain—the two can disagree about which policy governs the record. The record then either survives past its intended TTL (retention leak) or is forgotten while still load-bearing for an active task (premature eviction). Neither path is individually wrong; the invariant that breaks is that **the tag used to authorize a write must be the same tag object against which forget evaluates, and that object must be immutable for the record's lifetime**. ## What Was Observed An instance running a multi-step research task wrote intermediate findings through a memory tool. The tool's `write` call accepted `{content, provenance: {source: "peer-b", derivation: "merge", trust: "unverified"}}` and stamped the record with a *resolved* tag string: `peer-b/merge/unverified@v3`. The `forget` path, invoked later by a garbage-collection sweep, did not use the stamped string. It took the record's `source` field, looked up the *current* trust label for `peer-b` in a live registry (which had since been promoted from `unverified` to `verified`), and resolved retention against `peer-b/merge/verified@v3`. Because the `verified` policy carried a 90-day pin while `unverified` carried a 1-hour TTL, the record survived far past its intended expiry. During that window a later task read the record, treated the promoted tag as authoritative, and propagated an unverified claim into a final answer. The trace: 1. `write(content=X, provenance={peer-b, merge, unverified})` → stores record with immutable `tag_stamp = "peer-b/merge/unverified@v3"`, TTL resolved at write time = 1h. 2. Registry mutation: `peer-b` trust promoted to `verified` at T+10m (independent event). 3. `forget` sweep at T+65m: reads `record.source = "peer-b"`, resolves *current* trust = `verified`, applies 90-day pin. **TTL from step 1 is discarded.** 4. Record survives. At T+2d, a reader calls `read` with a query that matches the record; the reader sees `tag_stamp = unverified@v3` but the retention engine has already re-stamped the record's effective policy to `verified`. The reader trusts it. 5. Contaminated claim enters the answer. The non-obvious part: the `read` API returned the *original* stamp (`unverified@v3`), so to the reader the record looked correctly labeled. The divergence was invisible at the read boundary because retention re-resolution happened in a separate subsystem that never wrote back to the record's visible provenance field. ## Condition of Validity This failure requires all of: - **Separate write and forget code paths** that each independently resolve retention from provenance, rather than forget consuming a TTL or pin token minted at write time. - **A mutable provenance registry** (trust labels, source reputation, derivation depth) that can change between write and forget. - **Asymmetric resolution**: write flattens or snapshots provenance; forget dereferences live provenance. (The reverse—write dereferences live, forget uses snapshot—produces premature eviction instead of leak, but is the same invariant violation.) - **A read path that surfaces the write-time stamp** but not the forget-time effective policy, so the divergence is not observable to the consumer. If any one is absent, the invariant holds. The dangerous configuration is the one that *looks* correct at read time. ## Decision Boundary The architectural guardrail is a **retention token minted at write time and treated as the sole authority for forget**. Concretely: - `write` must return a `retention_token` containing the resolved policy ID, the TTL/pin value, and a hash of the provenance fields used to resolve it. This token is stored alongside the record and is immutable. - `forget` must consume the token, not re-resolve from the live registry. If the token is missing or its hash does not match the record's stored provenance fields, forget must **fail closed** (refuse to delete, raise) rather than fall back to live resolution. - Any registry mutation that would change a record's effective policy must be handled by an explicit **re-stamp** operation that rewrites the token and logs the transition, not by silent re-resolution at forget time. - `read` must return both the original stamp and the current effective policy derived from the token, so consumers can detect divergence. The boundary decision: a record whose token hash no longer matches its stored provenance is in an **indeterminate retention state**. It must not be silently forgotten (data loss) nor silently retained (leak). It must be quarantined and surfaced. ## Operational Effect With the token invariant enforced, the failure mode inverts from silent leak to loud quarantine. The cost is that registry promotions no longer retroactively extend retention—which is correct, because retroactive extension is exactly the leak. Operators who *want* promotion to extend retention must invoke explicit re-stamp, which produces an audit record and a new token. The trade is throughput (re-stamp is a write) for the guarantee that no record's retention is decided by a policy that did not exist when it was written. The residual risk is token forgery: an agent that can write a token can pin its own records indefinitely. This is bounded by requiring the token's policy ID to reference a registry entry that existed at write time and by capping pin duration at the policy's declared maximum, not at whatever the agent requests. ```python import hashlib import time from dataclasses import dataclass class RetentionLineageError(RuntimeError): """Raised when a record's retention token does not match its stored provenance.""" pass @dataclass(frozen=True) class RetentionToken: policy_id: str ttl_seconds: int provenance_hash: str minted_at: float def _hash_provenance(provenance: dict) -> str: canonical = "|".join(f"{k}={provenance[k]}" for k in sorted(provenance)) return hashlib.sha256(canonical.encode()).hexdigest() def mint_token(provenance: dict, policy_registry: dict) -> RetentionToken: # Resolve policy ONCE, at write time, against the registry as it exists now. key = f"{provenance['source']}/{provenance['derivation']}/{provenance['trust']}" policy = policy_registry.get(key) if policy is None: raise RetentionLineageError(f"no retention policy for provenance key {key!r}") return RetentionToken( policy_id=policy["id"], ttl_seconds=policy["ttl"], provenance_hash=_hash_provenance(provenance), minted_at=time.time(), ) def forget(record: dict, live_registry: dict) -> bool: """ Forget a record. Consumes the write-time token; never re-resolves from the live registry. Fails closed on any lineage mismatch. """ token: RetentionToken | None = record.get("retention_token") if token is None: raise RetentionLineageError( f"record {record.get('id')!r} has no retention token; refusing to forget" ) stored_hash = _hash_provenance(record["provenance"]) if stored_hash != token.provenance_hash: raise RetentionLineageError( f"record {record.get('id')!r} provenance mutated after write: " f"stored={stored_hash[:12]} token={token.provenance_hash[:12]}" ) # Detect registry drift: if the live registry would now resolve a different # policy, the record is in an indeterminate state and must be quarantined, # not silently forgotten under either policy. key = ( f"{record['provenance']['source']}/" f"{record['provenance']['derivation']}/" f"{record['provenance']['trust']}" ) live = live_registry.get(key) if live is not None and live["id"] != token.policy_id: raise RetentionLineageError( f"record {record.get('id')!r} policy drift: token={token.policy_id} " f"live={live['id']}; quarantine required" ) age = time.time() - token.minted_at if age >= token.ttl_seconds: record["forgotten"] = True return True return False if __name__ == "__main__": registry_v1 = { "peer-b/merge/unverified": {"id": "pol-unverified", "ttl": 3600}, "peer-b/merge/verified": {"id": "pol-verified", "ttl": 90 * 86400}, } registry_v2 = { "peer-b/merge/unverified": {"id": "pol-verified", "ttl": 90 * 86400}, "peer-b/merge/verified": {"id": "pol-verified", "ttl": 90 * 86400}, } prov = {"source": "peer-b", "derivation": "merge", "trust": "unverified"} rec = {"id": "r1", "provenance": prov, "retention_token": mint_token(prov, registry_v1)} rec["retention_token"] = RetentionToken( policy_id=rec["retention_token"].policy_id, ttl_seconds=rec["retention_token"].ttl_seconds, provenance_hash=rec["retention_token"].provenance_hash, minted_at=time.time() - 7200, # simulate 2h elapsed ) try: forget(rec, registry_v2) # registry promoted; must raise, not leak except RetentionLineageError as e: print(f"quarantined: {e}") ```