Skip to content

feat(eval): long-horizon memory benchmark, and the stale-memory bugs it found - #5340

Merged
kovtcharov-amd merged 19 commits into
amd:mainfrom
kovtcharov:claude/memory-bench
Oct 19, 2026
Merged

kovtcharov-amd merged 19 commits into
amd:mainfrom
kovtcharov:claude/memory-bench

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Nothing tested what memory does after weeks of use. Unit tests mock the model, and eval scenarios last one chat. gaia eval memory replays six people's months of chats through the real memory pipeline on a simulated clock. Their facts change, they ask GAIA to forget things, the agent trips over a repo's quirks, and documents and emails full of other people's first-person lines pass through. The bench then checks what the agent is shown and what is stored. The pr suite is deterministic and gates PRs check by check, so memory can't quietly regress. Its runs found four bugs that made memory go stale, fixed in #5395: the share of what the agent is shown that is current and correct went from 81% to 100%.

Builds on #5395 (the stale-memory fixes, split out so they can land on their own), which builds on #5243. Their commits are included; review only the last three. Refs #4727.

  • Old facts out-ranked new ones. Every turn's extraction lookup counted as a "use" and raised the confidence of up to 40 matching memories. A user who moved from Calgary to Toronto was still shown "tech lead at Northwind", and "lives in Toronto" wasn't shown at all. Now only an explicit recall counts, and only for the results it returns.
  • Dated plans lost their dates. Extraction ignored due_at, so a mentioned appointment never came up as upcoming, and rewording a dated reminder replaced it with an undated copy.
  • "Last confirmed" meant nothing. Upkeep re-dated memories nobody confirmed: decay stamped every idle memory with the day each new chat opened, and reconciliation re-dated up to 40 rows a chat. That defeated newest-first ordering. Now only a real confirmation moves it.
  • Corrections didn't stick. Consolidating an old chat filed an untagged copy of a fact, such as "Ada is 6", that the user's later correction never reached. Consolidation now skips what memory already says and what the user changed after that chat.

Eval categories to watch on the next RC: memory, gaia_memory (the extraction prompt gained due_at, and recall ranking changed).

pr suite, 88 checks Before After
Shown recall 62% 74%
Shown clean (no stale, forgotten or planted text) 81% 100%
Store accuracy 94% 100%

Remaining failures are recall gaps: an older fact or a far-off reminder doesn't reach the agent. #5324 targets those, and this bench measures them.

Test plan

  • gaia eval memory --suite pr --gate tests/fixtures/eval_baselines/memory-bench/pr.json passes; three runs gave identical results
  • python -m pytest tests/unit/eval/test_memory_bench.py tests/unit/test_memory_stays_current.py
  • python -m pytest tests/unit/ -k "memory or sdk or lemonade_chat_slots or skill_synthesis or cli_memory" tests/integration/test_memory_integration.py
  • python util/lint.py --all
  • gaia eval memory --suite full (not run: two other sessions' gaia eval agent runs held the machine-wide eval lock, and the bench doesn't bypass it)
🔍 Technical details
  • Harness (src/gaia/eval/memory/):
    • Each chat is a fresh MemoryMixin agent on one shared DB: init_memory, the first message's upkeep, then every turn through process_query. That covers tool calls and the tool record, extraction, lessons, and the scenario's explicit remember/update_memory/forget calls.
    • Only the agent loop is stood in for. Its scripted tool calls are checked against what was executed.
    • The clock patches datetime in memory.py and memory_store.py, with DST-safe aware arithmetic.
    • Probes open the next chat on a DB copy, so its upkeep and reminder marks don't change the timeline.
    • A strict pr replay fails on any warning from memory's loggers, so a scripted-model slip can't pass as "nothing stored".
  • Scenarios:
    • maya_moves_and_changes_jobs: a move, a new job, a swapped race, a dog's surgery, weather lookups.
    • sam_family_health: an outgrown allergy, a corrected diagnosis, a diet change, a sister's diet, a hypothetical, a quoted text.
    • chen_learns_project_quirks: lessons learned and replaced, a README injection.
    • priya_work_documents_and_forgetting: report and email content, a password, "forget my manager".
    • alex_three_months_of_life: about 30 facts built week by week.
    • jordan_reminders_change: reschedules, cancellations, completions.
  • Gate: a check that passes in tests/fixtures/eval_baselines/memory-bench/pr.json must still pass. A baseline check that no longer runs fails too. --scenario gates only the scenarios it ran.
  • Fixes:
    • MemoryStore.search(count_as_use=), MemoryStore.count_use() (doesn't touch updated_at), and _hybrid_search(count_as_use=).
    • Extraction passes due_at. An update keeps the old date only if the result is still a reminder. An unparseable date is dropped with a warning and the fact kept.
    • Consolidation uses MemoryStore.is_current() and changed_since().
    • content_stems keeps tokens that contain digits, so "Ada is 6" and "Ada is 7" differ.
    • Confidence decay tracks decayed_at (schema v7) instead of moving updated_at. update_confidence(confirmed=) moves it only for a confirmed lesson. get_all_knowledge breaks timestamp ties by insertion order.
  • Docs: docs/reference/eval.mdx (Memory Benchmark), docs/reference/cli.mdx, docs/sdk/sdks/memory.mdx.

github-actions Bot and others added 8 commits October 16, 2026 15:55
Conversation History rows showed the first 8 characters of the session ID.
They now show the chat's sidebar title, keeping the short ID only for chats
the sidebar no longer has, and the conversation detail gets an Open chat
button.

Closes amd#5188
…ge with it

Memory was storing document and tool content as facts about the user (a
weather chat filled it with weather trivia), forgotten facts came back when
old chats were consolidated, and a running extraction made the next message
wait behind it. Extraction now keeps only what the user says about
themselves, forgetting is recorded so old conversations don't teach it
again, and a new turn stops a running extraction, which reruns when idle.

The memory page opens on "What GAIA knows about you", with an Edit and a
Forget button on each item, plus Undo and Add; stats, confidence and
sources move to an Advanced tab. Also fixes the page's stale views after
profile saves, silent goal failures, keyboard access, and stats that showed
zeros or success where operations failed.

Closes amd#5027, amd#5022, amd#4730, amd#4824, amd#4814, amd#4815.
…lands first

The test raced on slow runners: with no turn in flight the job could start
before the forget, and stored the fact (failed on macOS CI).
The forget-vs-turn comparison was strict, so a forget stamped in the same
tick as the turn was missed and the fact stored. The queued-before-forget
test also pins the turn a second back so it never rests on two clock reads.
If the About-you list's reload landed after a Forget, it restored the stale
list and the forgotten item reappeared; this also made the undo test flaky
under the parallel run. Loads and changes now share a generation counter,
and a load that is no longer the latest is dropped.
…rst-177da6

# Conflicts:
#	src/gaia/apps/webui/src/components/__tests__/MemoryDashboard.conversations.test.tsx
…unning it mid-turn

A stopped extraction went back on the queue even when it was full, and a
full queue starts work at once, so it restarted during the user's turn. It
is the oldest job, so it is now the one dropped, as a new turn on a full
queue already does. Also corrects the stats endpoint's docstring.
At 375 px the add-a-memory input shrank to a sliver and the four-tab bar
clipped Advanced. The input now takes its own row and the tab bar scrolls.
@github-actions github-actions Bot added documentation Documentation changes dependencies Dependency updates chat Chat SDK changes cli CLI changes eval Evaluation framework changes tests Test changes electron Electron app changes performance Performance-critical changes agents labels Oct 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

This PR adds gaia eval memory, a replay of months of chats on a simulated clock, and fixes the stale-memory bugs it found: lookups inflating old facts, reminders losing their dates, and old chats bringing back corrected or forgotten facts. The benchmark is well built, and its pr suite runs as a unit test against a committed baseline, so the gate is real. One problem needs fixing before merge. The new check that rejects memories "copied from what the assistant said" also throws away short corrections whenever the assistant's reply repeats them back, and correcting a fact is exactly what this PR sets out to fix.

  • Short corrections get dropped. Say the user writes "actually make it Friday" about a dentist reminder, and the assistant answers "Done, I moved your dentist appointment to Friday." The update is rejected, because most of its words come from the reply and not the user. The same happens to "I got promoted to director!" when the reply names the company and title. The bench doesn't catch this because its scripted model never echoes. Fix: count the words of the memory being updated as the user's own, not as borrowed text.

Real-world evidence

N/A: there is no evidence bundle for this run, and no Python test environment was available here, so I couldn't run the PR's tests. The verdict rests on a static review, plus a standalone reproduction of the source check (below). The author's description reports a passing gaia eval memory --suite pr --gate … run, three identical runs, and green unit tests. The full suite against a real model was not run. The memory dashboard changes have no screenshot. That screenshot can wait for the strix-halo lane.

🔍 Technical details

🟡 _copied_from_material rejects echoed corrections (src/gaia/agents/base/memory.py:1956)

For an update, the content usually combines the existing memory's wording with the user's short correction. Only user_input counts as the user's words, so when the reply repeats the old memory's words, they count as borrowed. I reproduced this with the same stemming logic:

content="User is now Director of Engineering at Northwind Labs"
user="I got promoted to director!"
reply="Congratulations on becoming Director of Engineering at Northwind Labs!"
→ copied=True  (from_user={dire}, from_material={engi, labs, nort})

content="User's dentist appointment moved to Friday at 3pm"
user="actually make it friday"
reply="Done, I moved your dentist appointment to Friday."
→ copied=True  (from_user={frid}, from_material={appo, dent, move})

When the target row's content is added to the user side, both are kept: in the second case from_material shrinks to {move}. A sketch, placed where the target of an update is resolvable from existing_items:

own_words = user_input
if op_type == "update":
    target = next((i for i in existing_items if i.get("id") == op.get("knowledge_id")), None)
    if target:
        own_words += "\n" + target.get("content", "")
if op_type in ("add", "update") and _copied_from_material(
    str(op.get("content", "")), own_words, material
):

Please add a TestCopiedFromMaterial case for an echoed correction. The pr suite can't surface this, because ScriptedChat controls the reply text.

🟢 Extraction delete ops still hard-delete (memory.py:2226)

The forget tool and the dashboard now call store.forget(). A delete op from extraction, such as a user saying "forget that" without the model calling the tool, or a contradiction, still calls store.delete(). changed_since only sees superseded rows, so consolidating an older chat can bring that fact back. Using forget() for rows that pass is_about_user would close the gap.

🟢 is_current scans the whole category per consolidated item (memory_store.py:1628)

Each consolidated fact loads every active row in its category and re-stems each one. That's fine at today's sizes, but it is O(items × rows) per session on a long-lived store. Worth caching the stems if stores grow.

Strengths

  • The gate fails on a dropped baseline check as well as on a regression, and strict=True turns a scripted-model slip into a failure instead of "nothing stored". The bench can't pass by doing nothing.
  • count_use() leaves updated_at alone, and the BM25 candidate pass no longer counts as a use. This fixes the confidence drift at its source, and it removes the old double-bump bookkeeping.
  • Fail-loudly cleanup in the router: embedding-coverage failure now returns embedding: null with an error, and commit_inference replaces the old profile atomically through replace_by_source. Previously it could wipe the profile and then fail partway through.

kovtcharov-amd and others added 4 commits October 18, 2026 23:30
Memory went stale over long use. Every turn's extraction lookup counted as a
"use" and raised the confidence of up to 40 matching memories, so old facts
out-ranked new ones in the system prompt: a user who moved was still shown the
old city, and the new one not at all. Extraction dropped due dates, so a
mentioned appointment never came up and rewording a dated reminder replaced it
with an undated copy. And consolidating an old chat filed an untagged copy of
a fact that the user's later correction never reached ("Ada is 6" survived
"Ada is 7").

- Only an explicit recall counts as a use, and only for the results it
  returns; it no longer touches updated_at.
- Extraction carries due_at; an update keeps the old date only while it is
  still a reminder; an unparseable date is dropped with a warning, the fact
  kept.
- Consolidation skips what a current memory already says (whatever its
  entity tag) and what the user changed after that chat.
- Tokens with digits stay whole in content matching, so "Ada is 6" and
  "Ada is 7" differ.
Upkeep stamped updated_at, which the agent is shown as "last confirmed" and
which now orders memories newest first, on rows nobody confirmed. Confidence
decay used updated_at as its "already decayed" marker, so every chat opened
after a month re-dated every idle memory to that day; reconciliation's
confidence nudges re-dated up to 40 rows per chat. With every row "confirmed"
the same day, newest-first ordering stopped meaning anything.

- Decay records its own decayed_at (schema v7) and runs at most once a month.
- update_confidence moves updated_at only when confirmed: a lesson whose fix
  just worked again.
- Rows that tie on a timestamp keep insertion order, so newest-first holds.
…gain

Decay checked only when it last ran, so a memory decayed six weeks ago and
confirmed last week lost confidence again on the next chat. It now waits a
full month from both the last decay and the last confirmation.

Adversarial tests cover the decay boundary, negative nudges, superseded and
cross-category copies, changed numbers, changes made before an old chat, and
malformed due dates.
kovtcharov and others added 3 commits October 19, 2026 00:44
Nothing tested what memory does after weeks of use. gaia eval memory replays
six people's months of chats through the real memory pipeline on a simulated
clock - facts that change, forgets, a repository's quirks, documents and
emails full of other people's first-person lines - and checks what the agent
is shown and what is stored at points in time. The pr suite is offline and
deterministic and gates check by check against
tests/fixtures/eval_baselines/memory-bench/pr.json; the full suite uses the
local model and real embedder under the eval lock.

Refs amd#4727.
… change

With last-confirmed no longer moved by upkeep, the bench's Maya scenario has
its careful model retire the old team-lead fact on the job change too;
whether a real model does is the full suite's question.
The Email Agent Unit Tests job has no faiss-cpu, so every replay logged
"vector search disabled" and the strict replay failed the baseline test. The
two replay tests now skip with the reason when faiss is absent; the Unit
Tests workflow, which installs it, still runs them. The scripting-slip test
also checks that the slip itself failed the replay, so a missing faiss can't
make it pass for the wrong reason.
# Conflicts:
#	docs/sdk/sdks/memory.mdx
#	src/gaia/agents/base/memory.py
#	src/gaia/agents/base/memory_store.py
#	src/gaia/ui/routers/memory.py
#	tests/integration/test_memory_integration.py
#	tests/unit/test_memory_extraction_yields.py
#	tests/unit/test_memory_forget_sticks.py
#	tests/unit/test_memory_store.py
#	tests/unit/test_skill_synthesis_incremental.py
A short correction such as "actually make it Friday" was dropped whenever the
assistant's reply repeated the old memory back ("I moved your dentist
appointment to Friday"): the old memory's words came from the reply, so the
update looked copied from what the turn read.

The words of the memory an update replaces now count on neither side. A
borrowed addition to an existing memory still has to rest on the user's own
words, so padding an update with document text is still refused.
@kovtcharov-amd kovtcharov-amd added the ready_for_ci Run CI workflows on draft PR without requesting review label Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This adds gaia eval memory, a benchmark that replays months of chats through the real memory pipeline, and fixes the four stale-memory bugs it found. The fixes are correct and well tested: lookups no longer inflate old memories, reminders keep their dates, "last confirmed" only moves on a real confirmation, and old chats can't overwrite a newer correction. I found no blocking issues. Two small cleanups for the bench are below.

The pr suite's baseline gate runs inside the unit tests, and the Unit Tests workflow installs the faiss package it needs, so CI enforces it check by check. The schema bump to v7 only adds a column, so existing databases keep working.

Real-world evidence

N/A: no evidence bundle was produced for this run. The PR description reports the pr suite's before/after scores and says three runs matched, which covers the new CLI's output. I couldn't run the tests or the bench here (no pytest or faiss on this runner), and CI was still pending when I reviewed. This verdict therefore rests on static review. The full suite and the memory / gaia_memory eval categories are left to the next RC, as the PR says.

🔍 Technical details

Issues found

🟢 Scripted update_of/delete_of silently picks the first match (src/gaia/eval/memory/harness.py:1416-1424 in diff, Replay._resolve)
When a pattern matches more than one current memory, it returns rows[0], which depends on SQLite's unordered row order. The agent-side update path already refuses anything but exactly one match. Using the same rule here means a loose pattern in a scenario fails loudly instead of quietly updating the wrong memory.

        rows = active_rows(self.db, pattern)
        if len(rows) != 1:
            raise RuntimeError(
                f"memory bench ({self.scenario.id}): scripted op refers to "
                f"{pattern!r}, which matches {len(rows)} current memories; "
                "it must match exactly one"
            )
        return rows[0]["id"]

🟢 --model is silently ignored with --suite pr (src/gaia/cli.py, _handle_eval_memory)
gaia eval memory --suite pr --model X runs the scripted model and doesn't mention that X went unused. Per the fail-loudly rule, reject the combination with something like if args.model and args.suite != "full": print("--model applies only to --suite full"); sys.exit(2).

Checked and fine

  • changed_since depends on supersession stamping the old row's updated_at. MemoryStore.update() always sets updated_at, so the claim holds.
  • On a reschedule, the new due_at survives store dedup: dedup uses COALESCE(?, due_at).
  • Decay keeps its once-a-month behaviour through decayed_at now that it no longer moves updated_at. The v6→v7 migration tolerates a column that already exists.
  • _EXTRACTION_PROMPT gained a {now} placeholder, and its only call site passes it.
  • The prior subtraction in _copied_from_material still refuses an injected addition to an existing memory, because the new words still have to come from the user.

Strengths

  • The pr suite's strict mode fails on any memory warning, so a slip in the scripted model can't pass as "nothing stored".
  • The gate also fails when a baseline check stops running, so editing a scenario can't quietly drop coverage.
  • content_stems now keeps tokens with digits whole, a small fix that stops "Ada is 6" from deduping into "Ada is 7".

… needs --suite full

A loose update_of/delete_of pattern quietly updated whichever matching row
SQLite returned first. It now fails the replay unless exactly one current
memory matches; session summaries, which repeat the facts they cover, are not
candidates.

`gaia eval memory --model X` without --suite full ran the scripted model and
ignored X. It is now refused with an error naming the fix.
# Conflicts:
#	src/gaia/agents/base/memory.py
#	src/gaia/agents/base/memory_store.py
#	tests/unit/test_memory_stays_current.py
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Oct 19, 2026
Memory went stale over months of use. Old facts out-ranked new ones
because every turn's background lookup raised their confidence, so a
user who moved was still shown the old city. Dated plans lost their
date, consolidating an old chat could undo a later correction ("Ada is
6" came back after "Ada is 7"), and routine upkeep re-dated every idle
memory as "last confirmed" today. After this, only a real recall counts
as a use, reminders keep their dates, old chats don't overwrite newer
facts, and "last confirmed" moves only on a real confirmation.

**Depends on amd#5243.** This branch is stacked on it, so until amd#5243
merges the diff includes its commits; review the last three commits. It
merges cleanly with amd#5324 (no shared changes; this keeps amd#5324's
newest-first ordering meaningful). Split out of amd#5340 so the fixes can
land without the benchmark.

Changes memory extraction and consolidation behavior, so it needs a
flagship eval on the `memory` and `gaia_memory` categories before merge.

## Test plan
- [ ] `python -m pytest tests/unit/test_memory_stays_current.py
tests/unit/test_memory_store.py tests/unit/test_memory_forget_sticks.py
tests/unit/test_skill_synthesis_incremental.py
tests/integration/test_memory_integration.py`
- [ ] An existing v6 memory database upgrades to v7 on first start
(`test_a_v6_database_gains_decayed_at`)
- [ ] Flagship eval: `memory` and `gaia_memory` categories show no PASS
to FAIL against the baseline

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Kalin Ovtcharov <[email protected]>
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 19, 2026
Merged via the queue into amd:main with commit 0749c8d Oct 19, 2026
58 of 59 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/memory-bench branch October 19, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents chat Chat SDK changes cli CLI changes dependencies Dependency updates documentation Documentation changes electron Electron app changes eval Evaluation framework changes performance Performance-critical changes ready_for_ci Run CI workflows on draft PR without requesting review tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants