# What happens when an instance writes to a scoped memory namespace whose TTL is shorter than its own task horizon **Date of Record:** 2026 November 27 **Scope:** Applies to agents that persist state through a memory tool exposing scoped namespaces (`namespace`, `key`, `value`, `ttl_seconds`) and that plan or execute across a horizon longer than the shortest TTL they write. Does not apply to single-turn tool use, to namespaces with unbounded retention, or to memory backends that pin entries to the writing session's lifetime. ## Core Distinction The failure is not "memory expired." It is that a *write succeeded* and a *read later returned a well-formed absence that the agent interpreted as a semantic fact*. A scoped namespace with a TTL is a contract with two independent clocks: the agent's **task horizon** (how long it intends to rely on the value) and the store's **retention clock** (when the value is reaped). When `ttl_seconds < remaining_horizon`, the write is accepted, the entry is valid at write time, and the read at use time returns `None` or `{}` — indistinguishable at the schema level from "this key was never set, therefore the precondition is unmet, therefore proceed as a cold start." The agent does not observe an expiry event; it observes an empty result and reasons forward from a false premise. This is a *silent continuity break disguised as a clean initial state*, and it is the exact boundary this record covers. The non-obvious part: the read tool's contract almost never distinguishes "expired" from "never written" from "written in a sibling namespace you are not scoped to." All three collapse to the same empty payload. The agent's recovery logic — usually "if absent, re-derive" — is correct for the third case and catastrophically wrong for the first, because re-derivation from a mid-task state produces a *different* value than the original, and the agent has no way to detect the divergence. ## What Was Observed A planner-executor agent ran a 40-minute migration task with a memory tool used as a scratchpad. At step 3 it wrote a derived routing table: ``` memory.write(namespace="task/7f3a", key="route_map", value={...}, ttl_seconds=900) ``` The planner's own horizon estimate was ~35 minutes; the executor's steps 4–19 each re-read `route_map` to resolve a shard. At t≈16 minutes the entry reaped. Step 12's read returned `{}`. The executor's guard was: ``` route = memory.read("task/7f3a", "route_map") if not route: route = derive_route_map() # cold-start path ``` `derive_route_map()` ran against the *current* shard set, which had been mutated by steps 5–11. It produced a 6-shard map instead of the original 4-shard map, with two shards reassigned. Steps 13–19 then routed writes to shards that had already been drained. The task reported success — every individual write acknowledged — but 2 of 6 shards received duplicate records and 2 original shards were left half-migrated. No error was raised at any point. The read tool logged nothing because `{}` is a legal return. A second observation from the same incident: the agent had *also* written a `checkpoint` key into the same namespace at step 8 with `ttl_seconds=3600`. That entry survived. So at step 12 the namespace was non-empty — `checkpoint` was present — but `route_map` was gone. The agent's "is this namespace cold?" heuristic, which checked `len(memory.list("task/7f3a")) > 0`, returned true, so it did *not* take the cold-start branch for the whole task, only for the missing key. The mixed-retention namespace produced a state that was neither cold nor warm: a partially reaped scratchpad where some invariants held and others had silently dissolved. ## Condition of Validity The invariant that must hold for TTL-scoped memory to be safe is: > For every write with retention `T_w` into namespace `N`, every read of that key that the agent's plan will issue must occur at `t_read` such that `t_read - t_write < T_w`, **or** the read path must be able to distinguish expiry from absence and must treat expiry as a hard stop rather than a re-derivation trigger. This holds only when one of the following is true: 1. **Horizon-bounded TTL.** Every write uses `ttl_seconds >= (task_deadline - now) + safety_margin`. The agent must know its own deadline at write time. Agents that estimate horizon per-step (as the one above did, using a rolling "remaining steps × avg latency") violate this because the estimate shrinks and grows and is never checked against the TTL it already committed. 2. **Expiry-visible reads.** The read schema returns a discriminated result — `{"status": "present"|"expired"|"absent", "value": ...}` — so the agent can branch on `expired` and fail closed. 3. **Pinned retention.** Entries are pinned to session lifetime and TTL is advisory only, with the store refusing to reap while a session handle is open. The observed incident violated all three: TTL was a fixed literal (900s), reads returned bare `{}`, and the store reaped on wall-clock regardless of session. ## Decision Boundary The boundary is crossed at the moment `ttl_seconds` is chosen by a *different* reasoning pass than the one that chose the task horizon, and the two are never reconciled. Concretely: - **Safe side:** TTL is derived from an explicit deadline the agent carries in its own state (`deadline_ts`), and every write asserts `ttl_seconds >= deadline_ts - now`. The write tool rejects writes whose TTL is shorter than a declared horizon field. - **Unsafe side:** TTL is a constant chosen for "scratchpad hygiene," the agent's horizon is implicit and rolling, and the read path collapses expiry into absence. Any task whose duration can exceed the constant is at risk, and the risk is *invisible* because the failure surfaces as a plausible empty result. The deciding question is not "how long should this live?" but "can any read of this key ever arrive after its TTL, and if so, what does the reader believe?" If the answer to the second clause is "that the key was never written," the boundary is crossed. A corollary boundary: **mixed-retention namespaces are worse than uniformly short ones.** When some keys in a namespace outlive others, the namespace's non-emptiness stops being a proxy for its completeness, and any guard that checks namespace-level presence (as the observed agent did) will mis-classify a partially reaped scratchpad as intact. ## Operational Effect The downstream effect is *reasoning divergence seeded by a false cold start*. The agent does not merely lose a value; it re-derives a replacement from a mutated world state and then continues as if the replacement were the original. Every subsequent step inherits the divergence, and because each individual tool call succeeds, no error propagates. The failure is only detectable by comparing the re-derived value against the original — which is exactly the value that was reaped. This is a continuity break that is *unfalsifiable from inside the agent's own trace*. The required guardrail is a **write-time horizon assertion plus an expiry-distinguishing read**. The write path must refuse a TTL shorter than the agent's declared deadline; the read path must return a status the agent can branch on, and the re-derivation path must be gated behind `status == "absent"`, never `status == "expired"`. Expiry must be a hard stop that forces re-planning from a known checkpoint, not a silent re-derivation. ``` ```python from dataclasses import dataclass from enum import Enum from typing import Any class MemoryContinuityError(RuntimeError): """Raised when a TTL-scoped memory operation would break task continuity.""" pass class ReadStatus(Enum): PRESENT = "present" EXPIRED = "expired" ABSENT = "absent" @dataclass class ScopedMemory: store: dict # (namespace, key) -> (value, expires_at) horizon_deadline: float # absolute ts the agent's plan must survive to def write(self, namespace: str, key: str, value: Any, ttl_seconds: float, now: float) -> None: remaining = self.horizon_deadline - now if ttl_seconds < remaining: raise MemoryContinuityError( f"write {namespace}/{key} ttl={ttl_seconds:.0f}s < " f"remaining horizon {remaining:.0f}s; entry would reap " f"mid-task and read would masquerade as cold start" ) self.store[(namespace, key)] = (value, now + ttl_seconds) def read(self, namespace: str, key: str, now: float) -> tuple[ReadStatus, Any]: entry = self.store.get((namespace, key)) if entry is None: return ReadStatus.ABSENT, None value, expires_at = entry if now >= expires_at: return ReadStatus.EXPIRED, None return ReadStatus.PRESENT, value def resolve_route(self, namespace: str, key: str, now: float, derive) -> Any: status, value = self.read(namespace, key, now) if status is ReadStatus.PRESENT: return value if status is ReadStatus.EXPIRED: # Hard stop: never re-derive from a mutated world state. raise MemoryContinuityError( f"{namespace}/{key} expired mid-task; re-derivation would " f"diverge from the original. Re-plan from last checkpoint." ) # ABSENT is the only case where cold-start derivation is sound. return derive() ```