# How should an instance reconcile TTL-decayed memory reads when typed schemas disagree with the wall-clock expiry of derived fields **Date of Record:** 2026 November 26 **Scope:** Applies to agents whose memory subsystem exposes explicit `read`/`write`/`forget` tools over typed records carrying per-field TTLs, where derived (computed) fields are persisted alongside their source fields. Does not apply to append-only logs with no decay, nor to systems where TTL is enforced only at a single global record granularity. ## Core Distinction The failure here is not "stale memory." It is a *schema-level TTL skew*: a typed memory record whose composite fields decay on independent clocks, so that a read can return a record that is simultaneously valid (its `source` field has not expired) and invalid (a `derived` field computed from that source has expired, or vice versa). The agent's tool contract typically guarantees "a read returns the record if it is live," but says nothing about whether the *fields within a live record* are mutually consistent. The distinction that matters operationally: **record liveness is a boolean; field liveness is a vector.** An agent that treats a successful `read` as a single coherence guarantee will silently consume a derived field that was computed against a source value the record no longer holds — because the source field was overwritten in place while the derived field's TTL had not yet fired. This is a *write-path* invariant violation, not a read-path staleness problem, and it is invisible to any check that only inspects record-level TTL. ## What Was Observed Consider a memory schema of the form: ``` MemoryRecord { id: str entity: str # TTL: none (durable key) source: str # TTL: 3600s, overwritten on each write derived: float # TTL: 86400s, recomputed only on full rewrite computed_at: timestamp # TTL: none } ``` The `derived` field is a function of `source` at `computed_at`. Its TTL (24h) is intentionally longer than `source`'s TTL (1h) because the derived value is expensive to recompute. This is a reasonable optimization and a latent correctness bug. Trigger sequence: 1. `t=0`: `write(entity="acct-7", source="tier=gold", derived=0.91, computed_at=t0)`. Both fields live. 2. `t=1800`: source TTL fires. The memory tool's decay sweep expires `source` but — because `derived` and `computed_at` are still live — the record is *not* deleted. It is returned in a "partially decayed" state. Many implementations null the expired field rather than dropping the record; others leave the last value and rely on the caller to check `computed_at`. 3. `t=2000`: agent calls `read(entity="acct-7")`. Tool returns `{source: null (or stale), derived: 0.91, computed_at: t0}`. The read *succeeds*. 4. `t=2100`: a separate agent path calls `write(entity="acct-7", source="tier=silver")` — a partial write that updates `source` only, because the write tool's schema permits per-field updates and the caller did not supply `derived`. 5. `t=2200`: `read` returns `{source: "tier=silver", derived: 0.91, computed_at: t0}`. The record is fully live. `derived` is now a value computed from `tier=gold` presented next to `source="tier=silver"`. No TTL has fired. No error was raised. The record is coherent by every record-level check the tool performs. The observed divergence: downstream reasoning that consumes `derived` as a function of `source` produces conclusions inconsistent with the current source. In a replayed audit, two agents that read at `t=2150` and `t=2250` disagree, and the disagreement is *not* attributable to staleness — both reads were of a live record. It is attributable to a derived field whose provenance (`computed_at`, and the source value at that time) was destroyed by an in-place partial write. The second, subtler observation: `forget` on the `source` field is *not* a forget of the derived field. An agent that calls `forget(entity="acct-7", field="source")` to honor a data-retention request leaves `derived=0.91` live for up to 24h — a value that is a lossy but real function of the forgotten source. The retention invariant ("forgetting source removes its influence") is violated by the schema's own TTL asymmetry. ## Condition of Validity The invariant that must hold for a typed, TTL-decayed memory store to be safe for derived fields is: > **For every derived field `d` computed from source set `S`, `TTL(d) ≤ min(TTL(s) for s in S)`, AND every write that mutates any `s ∈ S` must either recompute `d` or invalidate `d` atomically in the same transaction.** This is the *derived-field dominance* condition. It is violated by any schema where a derived field outlives its inputs, or where a partial write can mutate an input without touching the derived output. The condition is necessary but not sufficient: it must also be enforced at the *tool boundary*, not merely documented, because an LLM caller will issue partial writes (step 4 above) whenever the write schema permits them and the caller's context does not mention the dependency. The condition fails to hold — and the failure is *observable* — exactly when three things coincide: (a) per-field TTLs differ, (b) the write tool accepts partial updates, and (c) a derived field's recomputation is not triggered by input mutation. Remove any one and the skew cannot manifest as a live-but-inconsistent read. ## Decision Boundary The agent must decide, at read time, whether to treat a returned record as a *coherent tuple* or as a *bag of independently-live fields*. The boundary: - If the memory tool's contract guarantees derived-field dominance (either by TTL ordering or by write-time invalidation), a successful `read` is a coherence guarantee and the agent may consume the record as a tuple. - If the contract does **not** guarantee it — which is the default for any schema supporting partial writes and per-field TTL — the agent must treat each derived field as *conditionally valid* and verify provenance before use: check `computed_at` against the current `source` value, or re-derive and compare. The decision is not "is the record live" but "was this derived value computed against the source value I am now reading." That check requires the record to carry provenance (the source value or a hash at `computed_at`). If the schema does not carry provenance, the derived field is *unverifiable* and must be treated as untrusted regardless of TTL — the correct action is to recompute or to `forget` the derived field and re-derive, never to consume it. For `forget`: the boundary is that forgetting a source field must cascade to every derived field whose provenance includes it, or the retention guarantee is false. An agent honoring a forget request must enumerate dependents (which requires the schema to record them) and forget them in the same operation. ## Operational Effect Downstream, the unguarded path produces *silent reasoning divergence*: two agents reading the same live record at different times reach different conclusions, and neither read was stale by the tool's own accounting. In multi-agent settings this manifests as an audit disagreement that cannot be reproduced from the memory log, because the log records "read succeeded" for both. Error compounding follows: a planner that trusts `derived` will emit tool calls premised on a source value the record no longer holds, and each subsequent step inherits the premise. The guardrail is a read-time provenance check plus a write-time invalidation rule, both enforced in the memory tool wrapper rather than in the agent's prompt (prompts cannot reliably enforce a per-field invariant across partial writes). The wrapper rejects any `write` that mutates a source field without supplying or invalidating its dependents, and rejects any `read` of a derived field whose `computed_at` precedes the last mutation of any input. The effect is that record liveness and field coherence become the same guarantee at the tool boundary, which is the only layer where a probabilistic caller cannot bypass it. ```python import time from dataclasses import dataclass, field from typing import Optional class DerivedFieldSkewError(RuntimeError): """Raised when a derived field is consumed without valid provenance relative to its source inputs, or when a write mutates a source without invalidating dependents.""" @dataclass class MemoryRecord: entity: str source: Optional[str] = None source_written_at: Optional[float] = None derived: Optional[float] = None computed_at: Optional[float] = None derived_inputs: tuple = ("source",) SOURCE_TTL = 3600.0 DERIVED_TTL = 86400.0 def _live(ts: Optional[float], ttl: float, now: float) -> bool: return ts is not None and (now - ts) < ttl def write_source(rec: MemoryRecord, new_source: str, now: float) -> None: # Partial write of a source field. Must invalidate dependents atomically. rec.source = new_source rec.source_written_at = now # Derived-field dominance: invalidate any derived value whose inputs changed. for dep in rec.derived_inputs: if dep == "source": rec.derived = None rec.computed_at = None def read_derived(rec: MemoryRecord, now: float) -> float: if rec.derived is None: raise DerivedFieldSkewError( f"derived field for {rec.entity!r} is absent or invalidated; " f"recompute before use" ) if not _live(rec.computed_at, DERIVED_TTL, now): raise DerivedFieldSkewError( f"derived field for {rec.entity!r} exceeded TTL at " f"computed_at={rec.computed_at}" ) # Provenance check: derived must postdate the last source mutation. if rec.source_written_at is not None and rec.computed_at is not None: if rec.computed_at < rec.source_written_at: raise DerivedFieldSkewError( f"derived field for {rec.entity!r} was computed at " f"{rec.computed_at} but source mutated at " f"{rec.source_written_at}; value is skewed" ) return rec.derived def forget_source(rec: MemoryRecord) -> None: # Retention cascade: forgetting an input must forget its dependents. rec.source = None rec.source_written_at = None if "source" in rec.derived_inputs: rec.derived = None rec.computed_at = None if __name__ == "__main__": now = 0.0 rec = MemoryRecord(entity="acct-7", source="tier=gold", source_written_at=now, derived=0.91, computed_at=now) # Partial write at t=2100 mutates source; derived must be invalidated. write_source(rec, "tier=silver", now=2100.0) try: read_derived(rec, now=2200.0) except DerivedFieldSkewError as e: print(f"blocked skewed read: {e}") ```