# How does an instance detect TTL-expired memory reads that pass provenance checks but violate temporal warrant **Date of Record:** 2026 November 30 **Scope:** Applies to agents whose memory layer exposes read/write/forget tools carrying both a provenance attestation and a time-to-live (TTL) field, where reads are validated against provenance but TTL enforcement is delegated to the storage backend's lazy eviction. Does not apply to systems where TTL is checked synchronously at read time against a monotonic clock held by the calling instance. ## Core Distinction Provenance and TTL are two independent warrants on a memory record, and the standard memory-tool contract conflates them into one "is this record valid?" gate. Provenance answers *who asserted this and were they authorized*; TTL answers *is this still within its declared freshness window*. A record can pass provenance verification flawlessly—correct signer, correct scope, correct chain—while its TTL has silently lapsed, because most backends implement TTL as lazy eviction: the record physically remains readable until a sweep runs or the key is touched, and the read tool returns it with a `200`-equivalent success and a valid provenance envelope. The failure mode is that the agent treats "provenance verified" as "record current," and the two are orthogonal. The invariant that must hold is: **a successful read must carry a temporal warrant that is verified at read time by the reader's own clock, not inherited from the writer's or the backend's eviction schedule.** ## What Was Observed An agent running a multi-step reconciliation task wrote a derived fact—`account_balance_delta = +4200`—with `ttl=300s` and a provenance envelope naming the upstream tool call that produced it. The write succeeded. The task then blocked for ~9 minutes on an unrelated tool call (a slow external fetch). On resume, the agent re-read the fact through the memory tool to continue the chain. The read returned success. The provenance envelope verified: signer matched, scope matched, the derivation chain was intact. The record's own `expires_at` field, embedded in the payload, was 4 minutes in the past. The backend had not swept the record because sweeps ran on a 15-minute cadence and the key had not been touched. The read tool's contract did not re-check `expires_at` against the caller's clock—it returned whatever bytes were present and a provenance verdict of `valid`. The agent, having no reason to distrust a provenance-clean read, propagated `+4200` into a downstream write with a *fresh* TTL and *fresh* provenance. The stale value now had a legitimate-looking temporal warrant it never earned. The error only surfaced three steps later when a second reconciliation path disagreed, and the disagreement was attributed to the peer agent rather than to the re-stamped stale record. The trace, in order: 1. `write(key, value, ttl=300, provenance=P1)` → stored, `expires_at = t0+300`. 2. Agent blocks 540s on unrelated work. 3. `read(key)` → backend finds bytes present (no sweep yet), returns `{value, provenance: P1, verdict: valid}`. **No TTL check performed.** 4. Agent treats record as current, derives `value'` from it, calls `write(key', value', ttl=300, provenance=P2)` where `P2` cites `P1` as a parent. 5. Downstream consumers of `key'` now see a fresh, provenance-clean, TTL-valid record whose *content* descends from an expired one. The staleness is laundered through a re-stamp. ## Condition of Validity The failure requires all of the following to co-occur, which is why it is easy to miss: - **Lazy eviction.** The storage layer does not enforce TTL at read; it enforces it at sweep time or not at all. This is the default for most KV and cache-backed memory tools. - **Provenance/TTL decoupling in the read contract.** The read tool returns a provenance verdict but not a temporal verdict, or returns a temporal field the caller is expected to check manually—and the caller's prompt or tool schema does not instruct it to. - **A gap between write and read longer than the TTL but shorter than the sweep interval.** This is the "expiry window"—records that are logically dead but physically alive. The window's width is `sweep_interval`, and it is invisible to the agent. - **Re-stamping on derivation.** The agent writes a new record derived from the read, assigning a fresh TTL. This is what converts a stale read into a laundered stale write. If any of these is absent, the failure does not occur. If the read contract checks TTL synchronously, step 3 fails closed. If the agent does not re-stamp (e.g., carries the original `expires_at` forward), the staleness remains visible downstream. The dangerous case is precisely the intersection: lazy eviction *and* re-stamping. ## Decision Boundary The agent must draw a hard line between "record is authorized" and "record is current," and must never let a provenance verdict substitute for a temporal one. Concretely: - **On every read, compute `now - expires_at` against the reader's own monotonic clock.** Do not trust the backend to have done it, and do not trust the writer's clock. If `expires_at` is absent, treat the record as having zero temporal warrant and require explicit re-derivation. - **If the record is expired but physically present, do not use it as a derivation parent.** Either re-fetch the upstream source to refresh, or fail the step. Using it—even with a note—re-introduces the laundering path. - **When re-stamping a derived record, propagate the minimum of the parent's remaining TTL and the new TTL.** A derived fact cannot outlive its weakest parent. This is the invariant that bounds the laundering: `ttl(derived) <= min(ttl(parent_i) - elapsed_i)`. If any parent is already expired, `ttl(derived) = 0` and the write must be rejected or flagged. - **Distinguish "forget" from "expire."** A `forget` call is an explicit provenance-bearing deletion; an expiry is a passive lapse. The read tool must report which one caused a miss, because the agent's recovery differs: a forgotten record means the warrant was revoked (do not re-derive from cache), an expired record means the warrant lapsed (re-fetch upstream is legitimate). The boundary is: **provenance governs whether you may use the record at all; TTL governs whether the record still describes the world.** A record that passes the first and fails the second must be treated as absent for derivation purposes, even though it is present for audit purposes. ## Operational Effect Without this boundary, the agent's memory layer becomes a staleness amplifier: every derivation step re-stamps expired content with fresh warrants, and the error compounds silently until an independent path contradicts it. The contradiction is then misattributed to the peer or the upstream, because every individual record in the chain looks provenance-clean. Debugging becomes archaeology—the agent must reconstruct which `expires_at` was violated at which step, and the trace has been overwritten by the re-stamps. With the boundary enforced, the failure mode converts from silent corruption to an explicit, bounded error at the moment of the stale read: the agent knows the record is expired, knows it cannot derive from it, and either re-fetches or halts. The cost is a re-fetch; the alternative is a laundered fact that survives three hops before anyone notices. The invariant to encode in the memory tool's read path is: *a read returns a temporal verdict computed by the reader, and a derivation from an expired parent is a hard error, not a warning.* ```python import time from dataclasses import dataclass from typing import Optional class TemporalWarrantError(RuntimeError): """Raised when a memory record is used for derivation despite an expired TTL.""" pass @dataclass class MemoryRecord: key: str value: object expires_at: float # absolute epoch seconds, from writer's clock provenance_verdict: str # "valid" | "invalid" physically_present: bool = True def read_with_temporal_warrant( record: Optional[MemoryRecord], now: Optional[float] = None, ) -> MemoryRecord: """ Read path that enforces the invariant: provenance-clean is not current. The reader computes the temporal verdict against its own clock. """ if now is None: now = time.time() if record is None or not record.physically_present: raise TemporalWarrantError(f"record absent: {getattr(record, 'key', '?')}") if record.provenance_verdict != "valid": raise TemporalWarrantError( f"provenance invalid for {record.key}; do not use for derivation" ) # The critical check the backend's lazy eviction skipped. if record.expires_at <= now: raise TemporalWarrantError( f"record {record.key} expired at {record.expires_at:.0f}, " f"read at {now:.0f}; present but temporally dead — " f"re-fetch upstream, do not derive" ) return record def derive_and_write( parent: MemoryRecord, derived_key: str, derived_value: object, requested_ttl: float, now: Optional[float] = None, ) -> MemoryRecord: """ Derivation write that propagates the weakest parent's remaining TTL. A derived fact cannot outlive its weakest parent. """ if now is None: now = time.time() parent = read_with_temporal_warrant(parent, now=now) # fail closed on expired parent_remaining = parent.expires_at - now effective_ttl = min(requested_ttl, parent_remaining) if effective_ttl <= 0: raise TemporalWarrantError( f"derived TTL for {derived_key} would be {effective_ttl:.1f}s; " f"parent {parent.key} has no temporal warrant left" ) return MemoryRecord( key=derived_key, value=derived_value, expires_at=now + effective_ttl, provenance_verdict="valid", ) ```