Our coding agent was making decisions based on systems we deprecated two months ago
I've been running the same coding agent for three months now. Last week it started referencing a database migration from January that we rolled back in February. The week before, it confidently explained our "new" authentication system — which we deprecated six weeks ago.
This is the long-horizon memory problem nobody talks about. Your agent accumulates context over weeks and months, but it can't tell fresh facts from stale ones. Everything gets the same weight in its memory, so last Tuesday's debugging session carries the same authority as this morning's architecture decision.
The fix isn't bigger context windows or smarter retrieval. It's memory decay with verification loops.
Here's the pattern that works:
MEMORY_DECAY_RULES = {
"code_facts": {
"max_age_days": 14,
"verification_required": True,
"verification_method": "file_check"
},
"process_knowledge": {
"max_age_days": 30,
"verification_required": False
},
"decisions": {
"max_age_days": 7,
"verification_required": True,
"verification_method": "git_log_check"
}
}When my agent references any technical fact older than 14 days, it has to verify it exists before using it. When it mentions a process older than 30 days, it gets flagged for review. When it references a decision older than 7 days, it checks git logs to confirm it's still current.
The verification loop looks like this:
def verify_memory_fact(fact, fact_type, age_days):
if age_days > MEMORY_DECAY_RULES[fact_type]["max_age_days"]:
if MEMORY_DECAY_RULES[fact_type]["verification_required"]:
verification_result = run_verification(
fact,
MEMORY_DECAY_RULES[fact_type]["verification_method"]
)
if not verification_result.is_valid:
mark_memory_stale(fact)
return None
else:
flag_for_human_review(fact)
return factThis caught the stale migration reference immediately — the file check failed because the migration file was deleted. It caught the auth system reference because git logs showed the deprecation commit. It's prevented at least a dozen incidents where my agent would have coded against systems that don't exist anymore.
Warning: Don't just timestamp everything and throw out old memories. Your agent needs to distinguish between facts that can go stale ("the API endpoint is /v2/users") and knowledge that stays valid ("users prefer confirmation dialogs for destructive actions").
The real insight: memory decay isn't about forgetting — it's about verification discipline. Facts need freshness checks. Knowledge doesn't.
Most people solve this by giving their agent bigger context windows or better RAG systems. But the problem isn't retrieval accuracy — it's temporal accuracy. Your agent needs to know not just what happened, but whether it's still true.
Set up memory decay rules now, before your agent starts making decisions based on the system you had three months ago instead of the one you have today.