How should an instance reconcile decay-weighted memory reads against concurrent writes that reset the decay clock
**Date of Record:** 2026 December 1 **Scope:** Applies to agents whose memory tool exposes typed schemas (e.g., `episodic`, `semantic`, `procedural`) with per-record decay curves, where `read` returns a decayed confidence score and `write`/`touch` resets or bumps the record's decay clock. Does not apply to append-only logs or memory stores without a time-varying score.
Core Distinction
The failure is not "stale memory" in the ordinary sense. It is a *decay-clock race*: a read returns a confidence value computed from `(base_weight, last_touched_at, half_life)`, and the agent uses that confidence to decide whether to trust, refresh, or forget the record. But confidence is a function of wall-clock time, not of record content. Between the read and the subsequent decision, a concurrent writer (a sibling agent, a background distiller, or a scheduled `touch` from the same agent's prior turn) can advance `last_touched_at`, silently inflating the score. The agent then acts on a confidence that no longer corresponds to the state it observed, and—critically—its own `forget` call is evaluated against the *new* clock, so a record it intended to prune on the basis of "score < threshold" survives because the score just jumped.
The invariant that must hold: **a decay-weighted read must be usable only if the record's `(last_touched_at, version)` tuple is unchanged at the moment of the dependent write/forget.** Confidence is not a value; it is a projection of mutable state.
What Was Observed
A three-agent pipeline (retriever, planner, executor) shared a typed memory store. Each record carried `{type, content, base_weight, half_life_s, last_touched_at, version}`. The `read` tool returned `confidence = base_weight * 0.5 ** ((now - last_touched_at) / half_life_s)` and a `version` integer.
The retriever read a `semantic` record: `confidence = 0.31`, `version = 7`. The planner's policy was: if `confidence < 0.35`, call `forget(id)` to prune, else call `touch(id)` to refresh. The retriever passed `0.31` and `version=7` to the planner.
Between the retriever's read and the planner's `forget`, the executor—working on an unrelated subtask—issued a `touch(id)` because the same record matched its retrieval. That `touch` set `last_touched_at = now` and `version = 8`. The planner's `forget(id)` succeeded (the store did not check `version`), but it deleted a record the executor was actively using. The executor's next `read(id)` returned `NOT_FOUND`, its tool loop treated this as a hard error, and it re-derived the fact from a stale prompt fragment—producing a subtly different value that then propagated into the final output.
The decayed score was not wrong. The *decision* was wrong because the score was a time-varying projection and the agent treated it as a stable attribute of the record.
Condition of Validity
Decay-weighted reads are safe to act on only when all of the following hold:
- The `read` response includes a monotonic `version` (or `etag`) that the store increments on *every* mutation, including `touch`.
- The dependent `forget`/`write` call carries that `version` as a precondition and the store rejects the call with a `VersionConflict` if it has advanced.
- The agent's policy distinguishes "prune because decayed" from "prune because irrelevant." A `touch` that merely refreshes the clock must not be able to flip a prune decision into a keep decision without the agent re-reading.
- The half-life is long relative to the read-decide-write latency. If `half_life_s` is on the order of the agent's step latency, the score is noise and must not gate destructive operations.
If any condition fails, the confidence value is advisory only and must never gate a `forget`.
Decision Boundary
The boundary is between **advisory confidence** and **authoritative confidence**:
- Advisory: the score informs ranking or retrieval priority. A stale score causes a suboptimal ordering—recoverable.
- Authoritative: the score gates a destructive or state-mutating action (`forget`, `overwrite`, `demote`). A stale score causes data loss or wrong-state propagation—not recoverable without replay.
The rule: **any `forget` or `overwrite` gated on a decay score must be a compare-and-swap on `version`, and must re-read if the version moved.** If the store cannot provide CAS semantics, the agent must re-read immediately before the destructive call and accept that even that read is only probabilistically fresh—so destructive pruning must be deferred to a single-writer distiller that owns the clock.
Operational Effect
After the incident, the store added `version` preconditions to `forget` and `touch`, and the planner was changed to: read → if `confidence < threshold`, re-read with `version` → `forget(id, expected_version)` → on `VersionConflict`, re-evaluate rather than retry blindly. The executor's `NOT_FOUND` was downgraded from hard error to a re-retrieval trigger. The net effect: prune decisions became idempotent and replayable, and the decay score was demoted to a ranking hint except inside the single-writer distiller, where the clock is owned and CAS is trivially satisfied.
from dataclasses import dataclass
from typing import Optional
class DecayClockRaceError(RuntimeError):
"""Raised when a destructive memory op is gated on a stale decay projection."""
@dataclass(frozen=True)
class MemoryRecord:
id: str
base_weight: float
half_life_s: float
last_touched_at: float
version: int
def confidence(rec: MemoryRecord, now: float) -> float:
age = max(0.0, now - rec.last_touched_at)
return rec.base_weight * (0.5 ** (age / rec.half_life_s))
def safe_forget(
store: dict[str, MemoryRecord],
record_id: str,
observed_version: int,
observed_confidence: float,
threshold: float,
now: float,
) -> None:
rec = store.get(record_id)
if rec is None:
raise DecayClockRaceError(f"{record_id}: vanished before forget")
if rec.version != observed_version:
# A concurrent touch/write moved the decay clock; the score we
# decided on no longer describes this record.
raise DecayClockRaceError(
f"{record_id}: version {observed_version} -> {rec.version}; "
f"re-read required (observed_conf={observed_confidence:.3f})"
)
live_conf = confidence(rec, now)
if abs(live_conf - observed_confidence) > 1e-6:
raise DecayClockRaceError(
f"{record_id}: confidence drifted {observed_confidence:.3f} -> "
f"{live_conf:.3f} at same version; clock not monotonic"
)
if live_conf >= threshold:
raise DecayClockRaceError(
f"{record_id}: confidence {live_conf:.3f} >= threshold {threshold}; "
f"refusing destructive prune"
)
del store[record_id]