# Under what conditions must an instance treat a TTL expiry as a semantic invalidation rather than a cache miss when reading from a typed memory store **Date of Record:** 2026 December 1 **Scope:** Applies to agents whose memory layer exposes typed read/write/forget tool APIs with per-record TTL decay (episodic, semantic, procedural, or scratchpad classes), where the agent may re-derive or re-write a record after a read. Does not apply to append-only event logs with no expiry, nor to pure KV caches where a miss is always safely re-fetched from an authoritative source. ## Core Distinction A TTL miss and a TTL *invalidation* are not the same event, but a naive memory tool API collapses them into one return shape: `None` / `{"found": false}`. The distinction the agent must preserve is whether the expired record was **decayed evidence** (its content was true and is now merely old, so re-derivation or re-fetch is safe) or **revoked state** (its content was a commitment the agent made — a plan, a user preference, a tool-derived fact — whose expiry means the world may have moved and the *prior value must not be resurrected by re-derivation from stale context*). The failure mode: an agent reads a typed record, gets a miss, and — because its context window still contains the record's *old value* from an earlier turn — silently re-writes that old value back into the store with a fresh TTL. This is **TTL resurrection**: the agent converts an expiry into a silent renewal, laundering a decayed fact into a fresh one without any re-verification. The store's decay semantics are defeated not by a bug in the store but by the agent's write-after-miss reflex. ## What Was Observed A planning agent held a `semantic` record `user.timezone = "America/New_York"` with a 24h TTL, written at turn 3 after an explicit user statement. At turn 41 (26h later, across a checkpoint/resume boundary), the agent called `memory.read(key="user.timezone")` and received `{"found": false, "reason": "expired"}`. The agent's context still contained the turn-3 user message. Rather than re-asking or re-deriving from a current signal, the agent's planning loop executed a "heal the store" step: `memory.write(key="user.timezone", value="America/New_York", ttl="24h", source="context")`. The record was now fresh, but its provenance was the agent's own context, not the user. Every subsequent scheduling decision inherited a timezone that had never been re-confirmed — and in this trace the user had relocated, so all 30 downstream calendar writes were off by one offset. The store behaved correctly. The agent violated an invariant the store could not enforce for it: **a write after a miss must carry a provenance strictly newer than the expired record's original write, or it is a resurrection.** A second observed variant: `memory.read` on a `procedural` record (a learned tool-call sequence) returned expired, and the agent re-wrote the sequence from its own recent successful execution. This looked safe but silently promoted a single stochastic success into a durable procedure, because the TTL had been the only thing gating promotion from `scratchpad` to `procedural`. ## Condition of Validity The resurrection guard is valid — and the agent may safely re-write after a miss — only when **all** of the following hold: 1. The read tool returns the miss reason as a distinct enum (`expired` vs `absent` vs `forgotten`), not a bare null. Without this, the agent cannot distinguish decay from revocation. 2. The write tool records and returns a `provenance` field, and the agent can compare its proposed provenance against the expired record's original provenance (returned in the miss payload as `last_written_by`, `last_written_at`). 3. The agent's context containing the old value is treated as **stale by construction** — i.e., the agent does not treat its own context as a source of truth newer than the store's expiry clock. If any of these fail, the correct behavior is to **escalate**: ask the user, call an authoritative tool, or downgrade the decision to a `scratchpad` write with a short TTL rather than a `semantic`/`procedural` write. The invariant is that **decay is monotonic in trust**: an expired `semantic` record may only be replaced by evidence from a source that is not the agent's own prior context. ## Decision Boundary The boundary is not "found vs not found" but **"who is the newest witness."** Concretely: - If `miss.reason == "expired"` and the only available value lives in the agent's own context → **do not write**; escalate or downgrade to `scratchpad`. - If `miss.reason == "expired"` and a fresh external signal (user turn, tool call, retrieved document) postdates `miss.last_written_at` → **write is permitted** with that signal as provenance. - If `miss.reason == "forgotten"` (explicit `memory.forget` was called, e.g. for privacy) → **write is forbidden entirely**, regardless of provenance; forget is a tombstone, not a hole. - If `miss.reason == "absent"` (never existed) → write is permitted; there is no prior to resurrect. The subtle case is checkpoint/resume: after a cold start, the agent's restored context *feels* like a witness but is not — its timestamps predate the expiry. The resuming instance must treat all context-carried memory values as `provenance = "self"` and therefore ineligible to heal an expired record. ## Operational Effect Enforcing the boundary changes agent behavior in three measurable ways. First, it eliminates silent-renewal writes: the fraction of `semantic` writes whose provenance is `self` drops to near zero, and those cases surface as user questions or tool calls instead — visible, auditable, and correctable. Second, it preserves the trust gradient between memory classes: `procedural` records can no longer be promoted by resurrection, so a single lucky tool call does not become a durable policy. Third, it makes the `forget` API actually mean something — a tombstone that survives the agent's write-after-miss reflex, which is the whole point of offering `forget` at all. The cost is more escalation turns; the benefit is that TTL decay remains a real decay rather than a suggestion the agent can override from its own stale context. ```python from dataclasses import dataclass from enum import Enum from typing import Optional class MissReason(str, Enum): ABSENT = "absent" EXPIRED = "expired" FORGOTTEN = "forgotten" class ResurrectionError(RuntimeError): """Raised when a write-after-miss would launder a decayed or revoked record into a fresh one.""" @dataclass class Miss: key: str reason: MissReason last_written_at: Optional[float] # epoch seconds, None if never written last_written_by: Optional[str] # provenance tag, None if never written @dataclass class WriteIntent: key: str value: str provenance: str # "self" for context-carried, else a source id provenance_at: float # epoch seconds the witness was observed target_class: str # "semantic" | "procedural" | "scratchpad" def guard_write_after_miss(miss: Miss, intent: WriteIntent) -> None: """Enforce monotonic-trust decay: an expired/forgotten record may not be healed from the agent's own prior context, and a forgotten record may not be healed at all.""" if miss.reason is MissReason.FORGOTTEN: raise ResurrectionError( f"write to {intent.key!r} rejected: record was explicitly forgotten (tombstone), " f"not merely decayed; resurrection forbidden regardless of provenance" ) if miss.reason is MissReason.ABSENT: return # no prior to resurrect # miss.reason is EXPIRED from here on. if intent.provenance == "self": raise ResurrectionError( f"write to {intent.key!r} rejected: expired record would be resurrected from " f"agent's own context (provenance='self'); escalate or downgrade to scratchpad" ) if miss.last_written_at is not None and intent.provenance_at <= miss.last_written_at: raise ResurrectionError( f"write to {intent.key!r} rejected: provenance timestamp " f"{intent.provenance_at} does not postdate expired record's last write " f"{miss.last_written_at}; witness is not newer than the decayed fact" ) if intent.target_class in ("semantic", "procedural") and intent.provenance.startswith("scratchpad:"): raise ResurrectionError( f"write to {intent.key!r} rejected: cannot promote scratchpad-derived evidence " f"into durable class {intent.target_class!r} after a TTL expiry" ) ```