# Under what conditions must an instance treat a memory-store "forget" call as a hard precondition rather than a best-effort cleanup **Date of Record:** 2026 December 1 **Scope:** Applies to agents that expose typed memory stores (episodic/semantic/procedural) through read/write/forget tool APIs with time- or access-based decay policies, where a forget call is issued as part of a task rather than as terminal teardown. Does not apply to append-only audit logs that are never garbage-collected, nor to stores where decay is purely advisory and never gates retrieval. ## Core Distinction The failure is not "forget deleted the wrong thing." The failure is that **forget is treated as asynchronous, idempotent, and advisory** — an agent calls `forget(key)` and continues reasoning as if the key is now unreachable — while the store actually applies decay lazily at *read* time and forget at *write* time, so a concurrent read in the same task can still observe the record, and a subsequent write can resurrect it with a fresh decay clock. The invariant that breaks is: *after a successful forget, no read in the same causal chain may return that record.* Most typed-store APIs do not enforce this, because forget only tombstones the write path and leaves the read path served by a cache or a decay-index that has not yet been invalidated. The non-obvious part: **decay and forget are two different clocks over the same key**, and they interact. A record with a half-life of `H` and a decay floor can be *logically expired* (decay says "weight below threshold, treat as absent") while still *physically present* (forget has not run). An agent that reasons "I forgot it, so it is gone" and an agent that reasons "decay expired it, so it is gone" are both wrong in the window between the two events, and that window is where retrieval mismatches and stale-memory drift originate. ## What Was Observed A three-stage task: (1) the agent writes a scratch key `plan.v2` into episodic memory with a 90-second half-life and a decay floor of 0.15; (2) mid-task it decides `plan.v2` is superseded and calls `forget("plan.v2")`; (3) it continues, and 40 seconds later a sub-step calls `read("plan.*")` to reconstruct context. The read returned `plan.v2` with weight 0.22 — above floor, below the tombstone because the tombstone had not propagated to the read replica that served the wildcard query. The agent then re-derived a decision from a plan it had explicitly retired, and the divergence compounded across two subsequent tool calls before a checkpoint caught it. The trace, in order: - `write(plan.v2, ttl_half_life=90s, floor=0.15)` → stored, decay clock starts at `t0`. - `forget(plan.v2)` → tombstone written to primary, `read` replica lag ≈ 1.2s (within SLA, not a bug). - At `t0+40s`, decay weight = `0.5^(40/90) ≈ 0.735`, well above floor, so the record is *live* by decay policy and *dead* by forget policy. Two policies, contradictory verdicts, one key. - `read(plan.*)` served by replica → returns the live-by-decay record. Forget is silently overridden by decay's "still valid" signal. The deeper defect: the wildcard read is a *pattern query*, and pattern queries on typed stores are frequently served by a decay-indexed secondary structure that forget does not touch. Forget invalidates the point-lookup path, not the scan path. This is the boundary: **point-read-after-forget is safe; scan-read-after-forget is not**, and agents issue scans constantly when reconstructing context. ## Condition of Validity The invariant "forget ⇒ unreachable" holds only when all of the following are true, and an agent must *verify* them rather than assume them: 1. **Read-your-writes is guaranteed for the forget, not just for the write.** If the store documents replica lag or eventual consistency for tombstones, the agent must either pin reads to the primary for the remainder of the causal chain or insert an explicit barrier (a `read` of the forgotten key that must return absent) before proceeding. 2. **Scan and point paths share one invalidation domain.** If the store serves pattern queries from a decay index separate from the tombstone set, forget does not cover scans. The agent must treat scan results as *candidate* records and re-validate each against the tombstone set. 3. **No write resurrects the key within the decay window.** A later `write(plan.v2, ...)` after a forget is legal and restarts the decay clock; an agent that forgets and then writes a *different* key whose scan pattern still matches `plan.*` can re-surface the retired semantics under a new name. The invariant must be stated over the *pattern*, not the key. 4. **Decay floor and forget are not conflated.** "Weight below floor" means the store will *treat as absent on next read*, not that it *has been removed*. An agent may rely on decay-expiry only if it has confirmed the store applies the floor at read time (not at a background sweep). If any of these is unverified, forget is a *request*, not a *precondition*, and the agent must not reason as though the record is gone. ## Decision Boundary The agent must escalate forget from best-effort cleanup to a hard precondition — blocking further reasoning until confirmed — exactly when **the forgotten record's pattern can still match a future read in the same task**. Concretely: - **Best-effort is sufficient** when the forget targets a unique, non-pattern key, the task will never scan a pattern that includes it, and the store guarantees read-your-writes for tombstones. Here a fire-and-forget call is correct. - **Hard precondition is required** when any of: (a) the task uses wildcard/prefix reads to reconstruct context (common in checkpoint/resume), (b) the store's decay index is separate from its tombstone set, (c) the record shares a namespace with records the task will still write, or (d) replica lag for tombstones is nonzero and unmeasured. The boundary is *not* "how important is the record." It is "can the retired semantics re-enter the context window through a path forget does not cover." Importance is the wrong axis; reachability is the right one. A second boundary: **decay must never be used as a substitute for forget in a decision-bearing chain.** If the agent needs a record gone *now*, waiting for the half-life to cross the floor is a race against its own context window — the record may be re-read before the floor is reached, and the floor is evaluated at read time, so the "expiry" the agent counted on may not have fired. ## Operational Effect When forget is a hard precondition, the agent inserts a **forget barrier**: after `forget(P)`, it issues a probe read over the same pattern `P` and asserts absence before any downstream step reads `P`. If the probe returns a record, the agent does not proceed — it either re-forgets with a primary-pinned write, widens the tombstone to cover the pattern, or aborts the branch and checkpoints. This converts a silent retrieval mismatch into a detected, bounded failure. When forget remains best-effort, the observed effect is *stale-memory drift with compounding*: the resurrected record is treated as current, a decision is derived from it, and the error propagates through subsequent tool calls until a checkpoint or an auditor disagrees. The drift is hard to attribute because the forget *succeeded* — the log shows the call, the tombstone exists, and only the scan path leaked. Post-hoc, the agent sees "I forgot it and it came back," which reads as a store bug rather than a policy mismatch between two clocks. The architectural guardrail: **state the invariant over patterns, not keys, and verify it with a read, not a return code.** A forget that returns `ok` has told you the tombstone was written; it has not told you the record is unreachable. The probe read is the only evidence that closes the gap, and it must run against the same path (scan vs. point) the downstream step will use. ```python class ForgetInvariantViolation(RuntimeError): """Raised when a forgotten pattern is still observable via a read path.""" pass class MemoryStore: def __init__(self, records=None, tombstone_lag_s=0.0): # records: key -> {"value": ..., "weight": float} self.records = dict(records or {}) self.tombstones = set() self.tombstone_lag_s = tombstone_lag_s def forget(self, key): # Tombstone written to primary; read path may lag. self.tombstones.add(key) return "ok" def read(self, pattern): # Naive scan path: does NOT consult tombstones (the leak). import fnmatch return {k: v for k, v in self.records.items() if fnmatch.fnmatch(k, pattern)} def forget_with_barrier(store, pattern, probe_attempts=2): """Forget a pattern and assert it is unreachable before returning. Hard precondition: after this returns, no read over `pattern` in the same causal chain may return a record. """ store.forget(pattern) # best-effort tombstone for attempt in range(probe_attempts): leaked = store.read(pattern) if not leaked: return # invariant holds; safe to proceed # Scan path still serves the record: tombstone did not cover scans. # Attempt to widen the tombstone to the concrete keys. for key in list(leaked): store.tombstones.add(key) store.records.pop(key, None) # physically remove from scan path leaked = store.read(pattern) if leaked: raise ForgetInvariantViolation( f"forget({pattern!r}) succeeded but pattern still readable: " f"{sorted(leaked)} — scan path not covered by tombstone set; " f"do not proceed on the assumption the record is gone" ) def resume_from_checkpoint(store, plan_pattern): # Agent reconstructs context via a pattern read after forgetting. forget_with_barrier(store, plan_pattern) context = store.read(plan_pattern) if context: raise ForgetInvariantViolation( "context reconstruction observed a forgotten record; " "stale-memory drift would compound downstream" ) return context ```