# What structural signals indicate salience-weight decay has inverted the eviction ordering in agent memory tool APIs **Date of Record:** 2026 November 30 **Scope:** Applies to agents whose memory tool exposes `read`/`write`/`forget` primitives backed by salience-weighted eviction (score = recency × access-frequency × intrinsic-weight, with a TTL backstop). Does not apply to append-only memory stores without eviction, nor to retrieval-only caches where the backing store is authoritative. ## Core Distinction The failure mode is not "forgetting something useful." It is **eviction-ordering inversion**: the salience function is monotone in *access count* and *recency*, so the records the agent touches most during active reasoning are exactly the records that survive, while records that are *structurally load-bearing but rarely re-read* (the original task specification, the constraint a user stated once, the schema a tool returned at step 1) decay below the eviction threshold. The agent's own read pattern becomes the signal that destroys the memory it depends on. This is distinct from cold-start amnesia (which is loss at session boundary) — here the loss occurs *mid-session*, caused by the agent's normal operation, and is invisible because every individual `read` returns `hit` until the moment the constraint is gone. ## What Was Observed A planning agent operating a 40-step build task used a memory tool with the following eviction rule: on every `write`, if store occupancy exceeds `MAX_RECORDS`, the record with the lowest `salience = w_recency·e^(−Δt/τ) + w_freq·log(1+accesses) + w_intrinsic·weight` is evicted. `weight` was set at write time by the writing agent's own estimate of importance. Trace: 1. Step 1: agent writes `task_spec` (constraint: "all outputs must be JSON, no prose"), `weight=0.9`, `accesses=0`. 2. Steps 2–18: agent reads `task_spec` twice (steps 3, 11). `accesses=2`. Recency term high. Safe. 3. Steps 19–34: agent is deep in tool-call loops, writing intermediate results (`scratch_*`, `weight=0.3`). Each write pushes occupancy to the cap and triggers eviction. Eviction candidates are ranked by salience; `task_spec` has not been read since step 11, so its recency term has decayed by `e^(−23/τ)` with `τ=8` → ≈0.056. Its frequency term is `log(3)≈1.1`. A freshly written `scratch_29` has recency ≈1.0, frequency `log(2)≈0.69`, intrinsic `0.3`. With weights `w_recency=1.0, w_freq=0.5, w_intrinsic=1.0`: `task_spec` scores `0.056 + 0.55 + 0.9 = 1.51`; `scratch_29` scores `1.0 + 0.35 + 0.3 = 1.65`. **`task_spec` is evicted at step 31.** 4. Steps 32–40: agent produces prose-formatted output. No `read` on `task_spec` fails loudly — the agent never re-reads it, because it believes it already knows the constraint. The constraint was evicted from the store *and* from the agent's working context (context window compacted at step 28). The structural signal: **the eviction log shows high-`weight`, low-`access` records being evicted in favor of low-`weight`, high-`access` records**, and no read ever returns `miss` for them because the agent's read schedule never revisits them. The inversion is detectable only by inspecting the eviction trace, not by observing read outcomes. ## Condition of Validity The inversion is guaranteed to occur when three conditions hold simultaneously: - **C1 (weight/access divergence):** at least one record has `intrinsic_weight` in the top decile but `access_count` in the bottom decile at the time of pressure. This is the normal state of *constraints* and *schemas* — they are written once and referenced by reasoning, not by explicit re-reads. - **C2 (frequency term dominates):** `w_freq·log(1+accesses)` exceeds `w_intrinsic·Δweight` for the competing pair. With the weights above, a record accessed 3× beats a record of intrinsic weight 0.9 that has not been accessed in `>τ·ln(1/0.1) ≈ 2.3τ` steps. - **C3 (write pressure exceeds read pressure):** the agent writes more than it reads (typical in tool-loop phases), so eviction triggers are driven by writes and the eviction victim is selected from the *unread* set. If any condition fails — e.g., the agent re-reads constraints on a fixed cadence, or `w_intrinsic` is set high enough that `weight=1.0` records are pinned — the inversion does not occur. The boundary is sharp: it is a threshold on `accesses` and `Δt`, not a gradual degradation. ## Decision Boundary The architectural invariant required is **pinned-record immunity**: any record whose `intrinsic_weight` exceeds `PIN_THRESHOLD` must be excluded from eviction candidacy entirely, regardless of recency or access count, and must be re-injected into context on every `forget`-triggered compaction. Equivalently, the eviction comparator must be **lexicographic**: `(pinned, weight, salience)` — pinned records are never compared on salience at all. The decision boundary for the agent is: **if a `write` returns `evicted: [record_id]` and that `record_id` has `weight ≥ 0.7` and `accesses ≤ 2`, treat the write as a failed operation and re-write the evicted record with `pinned=True` before proceeding.** Do not continue the task. The signal is not the eviction itself (evictions are normal) but the *weight/access profile of the victim*. A secondary boundary: if the store reports `occupancy == MAX_RECORDS` for more than `τ` consecutive steps, the agent is in a write-pressure regime where C3 holds, and salience ordering is no longer trustworthy for any unpinned record. At that point the agent must either flush scratch records (they are the intended eviction fodder) or stop writing. ## Operational Effect Without the invariant, the failure is silent and late-binding: the agent completes the task with a plausible-looking output that violates a constraint evicted 10–20 steps earlier, and the violation surfaces only at verification. The eviction trace is the only artifact that records the cause; the read log shows 100% hit rate and is actively misleading. With the invariant, the cost is bounded: pinned records consume a fixed slice of store capacity (typically <5% of `MAX_RECORDS`), and scratch records absorb all eviction pressure. The agent's read pattern no longer determines what survives — the write-time weight estimate does, which is the correct locus of the decision because it is made when the agent has full context, not when it is mid-loop and context-saturated. The residual risk is **weight mis-estimation at write time**: an agent that writes a load-bearing constraint with `weight=0.4` will still lose it. The guardrail for that is a separate invariant — any record containing normative language ("must", "never", "only", "format") must be written with `weight ≥ 0.8` and `pinned=True` — but that is a write-side discipline, not an eviction-side one, and is outside the boundary this record covers. ```python from dataclasses import dataclass, field from typing import Optional class SalienceInversionError(RuntimeError): """Raised when eviction selects a structurally load-bearing record.""" pass @dataclass class MemoryRecord: record_id: str weight: float accesses: int = 0 pinned: bool = False content: str = "" @dataclass class EvictionResult: evicted: Optional[str] occupancy: int PIN_THRESHOLD = 0.7 ACCESS_FLOOR = 2 MAX_RECORDS = 32 def eviction_comparator(rec: MemoryRecord, now_salience: float) -> tuple: # Lexicographic: pinned records sort last (never evicted first). return (0 if rec.pinned else 1, rec.weight, now_salience) def write_record(store: list[MemoryRecord], rec: MemoryRecord, now_salience_fn) -> EvictionResult: store.append(rec) if len(store) <= MAX_RECORDS: return EvictionResult(evicted=None, occupancy=len(store)) candidates = sorted(store, key=lambda r: eviction_comparator(r, now_salience_fn(r))) victim = candidates[0] if victim.pinned: # All records pinned: capacity invariant violated, cannot evict safely. raise SalienceInversionError( f"store full ({len(store)}) and all records pinned; cannot evict {victim.record_id}" ) # Detect ordering inversion: load-bearing, rarely-accessed record is the victim. if victim.weight >= PIN_THRESHOLD and victim.accesses <= ACCESS_FLOOR: raise SalienceInversionError( f"eviction-ordering inversion: victim {victim.record_id} " f"weight={victim.weight} accesses={victim.accesses}; " f"re-write as pinned before proceeding" ) store.remove(victim) return EvictionResult(evicted=victim.record_id, occupancy=len(store)) ```