All posts

AI Engineering

Stop Coding Agents from Reusing Stale Advice: Evidence and Expiry for Memory

Check scope, evidence, review dates and conflicts before a coding agent reuses old API advice. Run a dependency-free Node.js fixture and learn what the checks can and cannot prove.

Published and maintained by Sambro · Report a correction

7 min read Agent memoryEvidenceCoding agentsNode.js

A relevant memory can still be the wrong answer

An agent fixing a CSV importer retrieves a useful-looking note: send tags as a comma-separated string. That was correct for the v1 contract. Today's v2 task requires an array of strings. Finding a related note does not establish that it applies to the code being changed.

This guide proposes a small check before remembered advice enters the working context. All contracts and notes in the example are invented. It calls no model, uses no customer data, and does not alter a product's memory implementation.

A question prompted by the new research

Anthropic's November 6, 2026 article describes checking mistaken or stale notes against original records. In its internal 25-question document evaluation, graded criteria met were 53% for search alone, up to 61% for wiki plus search, and up to 48% for wiki alone. Primary source: www.anthropic.com — components-of-agent-memory

These are vendor-reported, task-specific results, not evidence of a general coding accuracy gain. Our question is narrower: which stored advice should be withheld from today's task? The fields and selector below are Sambro's teaching design, not a schema prescribed by Anthropic.

Store the conditions for reuse beside the claim

An id and a claim are insufficient to explain why a note was trusted or where it applies. The example uses scope for the component, version for the API version, key and value for a fact, and evidenceId for an invented contract object. verifiedAt records the last check; reviewAfter is the first day another check is required. status and supersededBy distinguish hypotheses and replaced advice.

A verified label is an assertion by the writer. Recent dates and an existing source do not prove semantic truth. In a real implementation, retain the contract test, reviewed commit and verification method. Rewriting a summary must not automatically promote a hypothesis to verified or extend its review date.

Choose a review interval based on change frequency and the cost of a wrong recommendation. A contract or dependency change should trigger rechecking affected notes even before the date expires. The selector cannot discover those change events by itself.

Run old v1 advice against a v2 task

The example runs on Node.js 22 or later. Save these files in one directory: selector memory evidence — selector.mjs , tests memory evidence — selector.test.mjs , input memory evidence — fixture.json , and runner memory evidence — demo.mjs . Also save results.json from the next paragraph; save all five files to run the tests and demo. Read the code before running the commands below. No install or API key is needed.

The naive path picks the first tag-related note and returns the old v1 advice. The guarded path checks task scope, status, evidence, dates and replacement metadata. If no usable v2 note remains, fresh contract inspection is required rather than filling the gap with a guess. This is neither semantic retrieval nor an LLM benchmark.

The recorded output is available as JSON: memory evidence — results.json . evidenceId is a key inside the fixture, not a URL or a live filesystem read. To inspect the invented JSON, use the English formatter: JSON formatter . Keep secrets and real conversation histories out of this exercise.

Run after saving all five example files together
node --test selector.test.mjs
node demo.mjs

Make expiry and conflicts visible

A note due for review, missing evidence, a future verification date or an impossible calendar date should produce an explicit reason to recheck. Silently filling defaults can hide broken memory records behind a successful-looking result. Test exclusions as carefully as accepted notes.

When candidates that passed all prior checks contain different values for the same fact key, do not arbitrarily prefer the newest sentence. Withhold that key and return a conflict. This example detects only structured key/value disagreements. It cannot recognize equivalent prose or contradictions spread across different keys.

Replaced advice can leave the injected context while remaining in a review history. That makes a decision explainable without continuing to use the old claim. Personal-data retention periods and deletion requests still need their own policy.

Keep the always-loaded index small

Claude Code's documentation, checked November 10, 2026, loads the first 200 lines or 25KB of auto-memory MEMORY.md at session start, whichever comes first. Topic files are read on demand. That index limit is not the same rule as CLAUDE.md loading. Official documentation: code.claude.com — memory

For our design, a compact index can hold currently usable summaries and pointers, with long evidence records retrieved when needed. Do not optimize only for fewer notes. Track wrong reuse, time spent rechecking, and useful facts excluded by overly strict filters.

A remembered statement such as deployment is allowed is not permission for the current action. Treat instructions embedded in source material as data. Enforce tool permissions and the user's actual authorization separately from memory selection.

What the tests establish

All 27 included tests passed on Node v24.22.1. In the base fixture, the naive path chose old-v1 with comma-separated-string; the guarded path chose current-v2 with string-array and rejected old-v1 as SCOPE_MISMATCH. The asOf date is fixed at 2026-11-10. These tests check rules on invented inputs. They do not measure a real agent's answer accuracy, cost savings, long-term recall or resistance to attacks. Metadata and timestamps cannot guarantee that a claim is true.

Start with one contract type that repeatedly causes mistakes. Use a small set of notes checked against current code, retain readable exclusion reasons, and measure both avoided errors and review effort on real tasks before expanding the design.

Back to Sambro Blog