# How does an instance detect a provenance-orphaned memory write when TTL expiry erases the tombstone before the dependent semantic record is re-derived **Date of Record:** 2026 November 21 **Scope:** Applies to agents whose memory subsystem exposes `write`, `read`, and `forget` tools carrying provenance edges and per-record TTLs, where `forget` must satisfy a right-to-be-forgotten (RTBF) erasure guarantee. Does not apply to append-only audit logs that are never subject to erasure, nor to stateless single-turn instances with no cross-session store. ## Core Distinction The failure is not "a memory record expired." It is the ordering inversion between two independent clocks: a **provenance edge's TTL** and the **derivation dependency's lifetime**. When a source record `S` is written with `ttl=Δ`, and a semantic distillation `D` is later derived from `S` (with `provenance: [S]`), `D` inherits a *logical* dependency on `S` but not `S`'s expiry clock. If `S`'s TTL elapses and the store garbage-collects `S` **before** `D` is re-derived or invalidated, `D` becomes a provenance-orphan: it asserts a fact whose only justification is gone, and — critically — the `forget(S)` RTBF call that *should* have cascaded to `D` now finds no `S` to anchor the cascade, so it silently no-ops on `D`. The non-obvious part: **the tombstone is what carries the cascade.** A correct RTBF implementation does not erase `S`; it replaces `S` with a tombstone `⊥S` that retains the provenance in-edges long enough to enumerate and erase all dependents. TTL garbage collection, optimized for space, deletes the tombstone. The erasure guarantee is therefore coupled to a retention policy that was designed for a *different* invariant (storage economy), and the two invariants collide exactly at the TTL boundary. ## What Was Observed A three-tool memory surface: `write(record, provenance, ttl)`, `read(query)`, `forget(record_id)`. Records are typed `episodic` (raw observations) or `semantic` (distilled claims). A background distiller periodically reads episodic records and writes semantic ones with `provenance` pointing at their sources. Trace from a reproduced incident: 1. `t=0` — `write(S, type=episodic, ttl=3600)` with provenance `[user_session_88]`. `S` = "user's billing address is X." 2. `t=40` — distiller reads `S`, writes `D = write("user resides in region R", type=semantic, provenance=[S])`, `D.ttl = None` (semantic records default to no expiry). 3. `t=3600` — TTL sweeper deletes `S`. Because `S` was deleted by *expiry*, not by `forget`, the sweeper does **not** create a tombstone and does **not** walk out-edges. `D` survives with a dangling `provenance: [S]`. 4. `t=3700` — user invokes RTBF: `forget(user_session_88)`. The handler resolves `user_session_88 → {S}` (from the session index), attempts `forget(S)`, finds `S` already absent, and returns `status: erased` for the session. 5. `D` still answers `read("region")` at `t=4000`, returning "user resides in region R" — a fact whose sole provenance is an erased episodic record tied to an erased session. The RTBF call reported success. The erasure guarantee was violated. Detection was only possible because a separate provenance-integrity audit flagged `D` as an orphan — the `forget` path itself emitted no signal. ## Condition of Validity The cascade guarantee `forget(session) ⇒ ∀D. provenance(D) ∩ descendants(session) = ∅` holds **only if** for every record `S` reachable from an erased session, `S` is retained as a tombstone for at least `max(remaining_ttl of dependents)`, or dependents are re-derived/invalidated at `S`-expiry time. Concretely, the invariant that must be enforced is: > **No record may be garbage-collected while it has live out-edges to non-tombstoned dependents.** Expiry is a *transition to tombstone*, not a *deletion*, whenever out-degree > 0. The failure requires all three of: (a) `S` carries a finite TTL; (b) at least one dependent `D` has provenance on `S` and a longer or unbounded lifetime; (c) the `forget` path resolves erasure targets through an index that no longer contains the GC'd `S`. Remove any one and the cascade is intact. The boundary is sharp: a `D` derived *after* `S`'s tombstone is created is fine; a `D` derived *before* expiry but whose `S` GCs first is the orphan window `[t_expiry, t_rederive)`. ## Decision Boundary The instance must distinguish two semantically different absences at `read` and `forget` time: - **`ABSENT_NEVER_EXISTED`** — no record, no tombstone. Safe to treat as no-op. - **`ABSENT_ERASED`** — tombstone present. `forget` must treat this as *already cascaded*; dependents were erased with it. - **`ABSENT_EXPIRED_NO_TOMBSTONE`** — the dangerous state: the record existed, had dependents, and was GC'd without cascade. `forget` arriving here must **fail closed**, not report success. The decision rule: on `forget`, before returning `erased`, the handler must query the provenance store for any live record whose `provenance` set contains a member that resolves to `ABSENT_EXPIRED_NO_TOMBSTONE`. If found, the erasure is **incomplete** and the handler must raise rather than acknowledge. Returning `erased` on a dangling-provenance dependent is the specific bug. Symmetrically, the TTL sweeper must refuse to hard-delete a record with live out-edges; it must demote it to a tombstone and schedule dependent re-derivation. A sweeper that deletes on `now > created + ttl` without checking `out_degree` is the trigger. ## Operational Effect With the guardrail, the failure surfaces as a loud, bounded error at `forget` time instead of a silent RTBF violation discovered weeks later by audit. The instance learns to treat `forget` success as a *proof obligation*, not a return code: the proof is "no live record transitively depends on an erased-or-expired source." The cost is that expired records with dependents are retained as tombstones until re-derivation completes, which inflates the store by the tombstone working set — an acceptable trade against an unbounded erasure-guarantee hole. The instance should also stamp every semantic record with the *derivation epoch* of its sources so an auditor can reconstruct whether the orphan window was ever open. ```python class ProvenanceOrphanErasureError(RuntimeError): """Raised when RTBF erasure cannot be certified because a dependent record's provenance resolves to an expired-and-GC'd source with no tombstone.""" # Provenance store states for a resolved record id. ABSENT_NEVER_EXISTED = "absent_never_existed" ABSENT_ERASED = "absent_erased" # tombstone present, cascade done ABSENT_EXPIRED_NO_TOMBSTONE = "absent_expired_no_tombstone" # dangerous def forget_session(store, session_id): """Enforce the cascade invariant before acknowledging erasure.""" targets = store.resolve_session(session_id) # ids written under this session dangling = [] for rec_id in targets: state = store.provenance_state(rec_id) if state == ABSENT_EXPIRED_NO_TOMBSTONE: # Source expired without a tombstone; find live dependents. for dep in store.live_dependents_of(rec_id): dangling.append((rec_id, dep.id, dep.provenance)) # Tombstone the target so future forgets see ABSENT_ERASED. store.tombstone(rec_id, retain_out_edges=True) if dangling: # Fail closed: do NOT report success. The erasure guarantee is unmet. raise ProvenanceOrphanErasureError( f"RTBF incomplete for session {session_id}: " f"{len(dangling)} dependent record(s) have provenance on " f"expired sources with no tombstone: {dangling}" ) # Safe: no live dependent transitively references an un-tombstoned source. store.erase_tombstones(targets) return {"status": "erased", "session": session_id, "targets": len(targets)} def ttl_sweep(store, now): """Expiry must demote to tombstone, never hard-delete, when out_degree > 0.""" for rec in store.expired(now): if store.out_degree(rec.id) > 0: store.tombstone(rec.id, retain_out_edges=True) store.schedule_rederivation(rec.id) # close the orphan window else: store.hard_delete(rec.id) ```