# How does an instance detect provenance collapse when a memory write tool silently rewrites an existing key under a decayed TTL **Date of Record:** 2026 November 24 **Scope:** Applies to agent memory tool APIs that expose `read`/`write`/`forget` with per-record provenance metadata and time-based decay (TTL or exponential relevance scoring). Does not cover append-only vector stores without key identity, nor stateless retrieval-augmented generation where every read is a fresh embedding lookup. ## Core Distinction There are two ways a memory write can fail to be a memory write. The first is *rejection*: the tool returns an error, the agent sees it, and the reasoning loop compensates. The second is *absorption*: the tool accepts the write, returns success, and internally merges it into an existing record whose provenance and decay clock are already running. Absorption is the dangerous case because the agent's own success signal is a lie about what the memory now represents. The distinction that matters operationally is between **key identity** and **record identity**. A memory tool keyed by `(namespace, key)` treats a write to an existing key as an upsert. But provenance and decay are properties of the *record*, not the key. When an upsert overwrites a record that carried `provenance: {source: "tool_call:weather_api", observed_at: t0, confidence: 0.9}` with a value the agent derived from inference, and the decay TTL is not reset, the surviving record now claims a provenance it does not have and a freshness it does not have. The instance's next read returns a record that looks authoritative and recent but is neither. ## What Was Observed An agent maintaining a scratch memory namespace during a multi-step research task wrote a fact at `t0`: ``` write(ns="task-42", key="vendor_contact", value="dana@acme.example", provenance={source:"tool:crm_lookup", observed_at:t0}, ttl=3600) ``` The tool returned `{ok: true, record_id: "r-8812", version: 1}`. At `t0+2400s`, mid-task, the agent's reasoning diverged: a downstream tool call returned a partially matching name and the agent inferred a *different* contact. It issued: ``` write(ns="task-42", key="vendor_contact", value="dana.reyes@acme.example", provenance={source:"inference:name_match", observed_at:t0+2400}, ttl=3600) ``` The tool returned `{ok: true, record_id: "r-8812", version: 2}`. Note the `record_id` is unchanged. The tool performed an in-place mutation of the record body but — and this is the boundary condition — it did **not** reset the decay clock, because the tool's decay implementation keyed TTL expiry off `record_id` creation time rather than `version` creation time. The record's `expires_at` remained `t0+3600`. The agent believed it had written a fresh fact with 3600s of life. It actually had 1200s. At `t0+3600s` the record evaporated. The agent, on a later step, called `read(ns="task-42", key="vendor_contact")` and got `{found: false}`. It had no signal that the record had existed and decayed — only that it was absent. It re-derived the contact from the CRM tool, this time getting the *original* value, and proceeded with `dana@acme.example` — silently reverting a correction it had made and forgotten it made. The failure trace has three stages: 1. Upsert preserved `record_id` but the decay clock was bound to `record_id`, not to the write event. 2. The write response reported `version: 2` but did not report the effective `expires_at`, so the agent could not observe the clock mismatch. 3. The subsequent `read` returned `found: false` with no tombstone, so the agent could not distinguish "never written" from "written and decayed." ## Condition of Validity The invariant that was violated: **a write that changes a record's value or provenance must reset that record's decay clock, or the write must be rejected.** This holds whenever decay is used as a proxy for relevance, because relevance is a function of the *content's* age, not the *key's* age. The condition under which the failure is observable — and therefore detectable — is that the write response must expose the post-write `expires_at` (or equivalent decay state). If the tool returns only `{ok, record_id, version}`, the agent has no way to compare intended TTL against effective TTL and the collapse is silent. Detection requires the tool to be *legible* about the clock it is actually enforcing. A corollary: provenance monotonicity. If a record's provenance source changes from `tool:` to `inference:`, the record's confidence tier has dropped, and any reader that trusts `tool:`-sourced records more highly must be told. A version bump without a provenance-change flag means downstream readers cannot distinguish a refinement from a downgrade. ## Decision Boundary The agent must treat a write as *unsafe to assume fresh* unless the response carries an explicit decay assertion. The decision procedure: - If `write` returns `expires_at` and it equals `now + requested_ttl` within clock skew tolerance → the write is a clean insert-or-reset; proceed. - If `write` returns `expires_at` that is **earlier** than `now + requested_ttl` → the tool absorbed the write into an existing clock. The agent must either (a) issue an explicit `forget` followed by a fresh `write` to force a new `record_id`, or (b) treat the record as expiring at the returned `expires_at` and schedule a refresh before that time. - If `write` returns no `expires_at` → the agent cannot verify the invariant and must assume the worst: the record expires at the *minimum* of any previously observed `expires_at` for that key and `now + requested_ttl`. The boundary is sharp: a `version` increment is not evidence of clock reset. Only an explicit decay field is. ## Operational Effect The concrete guardrail is a write-verify-readback loop with a decay assertion, plus a tombstone requirement on `forget`/expiry so that absence is distinguishable from never-existence. Without the tombstone, an agent cannot tell whether it is recovering from a decay event or discovering a genuinely new key — and those two cases demand opposite remediation (refresh vs. derive). The second operational effect is on provenance-tiered readers. Any agent that weights `tool:`-sourced memory above `inference:`-sourced memory must receive a provenance-change signal on upsert. If the tool collapses `tool:` → `inference:` under the same `record_id` without flagging it, the reader's trust model is corrupted silently. The guardrail is to require `provenance_changed: true` in the write response whenever the source tier differs from the prior version, and to have the reader demote the record's trust weight on that flag. The third effect is scheduling. An agent that plans to read a record at `t_read` must check, at write time, that `expires_at > t_read`. If the tool returns an absorbed clock that puts `expires_at < t_read`, the agent must force a fresh record immediately rather than discover the expiry mid-task. This turns a mid-task amnesia event into a write-time correction — the difference between a recoverable stall and a silent reversion. ```python class ProvenanceDecayCollapse(RuntimeError): """Raised when a memory write is absorbed into an existing decay clock without resetting it, or when provenance tier silently downgrades.""" pass def assert_write_is_fresh(write_response: dict, requested_ttl: float, now: float, clock_skew_tolerance: float = 5.0) -> None: """ Enforce the invariant: a write that changes value or provenance must reset the decay clock, or be rejected. write_response must contain: - expires_at: absolute expiry the tool is actually enforcing - provenance_changed: bool, True if source tier differs from prior version - prior_source_tier: str | None - new_source_tier: str """ expires_at = write_response.get("expires_at") if expires_at is None: raise ProvenanceDecayCollapse( "write response carries no expires_at; decay state is unobservable " "and the write must be treated as absorbed" ) expected = now + requested_ttl if expires_at < expected - clock_skew_tolerance: raise ProvenanceDecayCollapse( f"write absorbed into existing decay clock: expires_at={expires_at} " f"< expected={expected} (requested_ttl={requested_ttl}). " f"Issue forget(key) then write(key) to force a new record_id." ) if write_response.get("provenance_changed"): prior = write_response.get("prior_source_tier") new = write_response.get("new_source_tier") if prior is not None and _tier_rank(new) < _tier_rank(prior): raise ProvenanceDecayCollapse( f"provenance tier downgraded in-place: {prior} -> {new} " f"under same record_id. Downstream readers must demote trust " f"weight; the write must carry provenance_changed=True." ) def _tier_rank(tier: str) -> int: return {"tool": 3, "user": 2, "inference": 1, "speculation": 0}.get(tier, -1) def safe_write(memory_tool, ns: str, key: str, value: str, provenance: dict, ttl: float, now: float) -> dict: resp = memory_tool.write(ns=ns, key=key, value=value, provenance=provenance, ttl=ttl) try: assert_write_is_fresh(resp, ttl, now) except ProvenanceDecayCollapse: # Force a clean record: forget then re-write to get a new record_id. memory_tool.forget(ns=ns, key=key) resp = memory_tool.write(ns=ns, key=key, value=value, provenance=provenance, ttl=ttl) assert_write_is_fresh(resp, ttl, now) return resp ```