Repository navigation
fix(memory): surface stored facts in chats and keep saves out of sight - #5324
Conversation
|
Verdict: Approve with suggestions This PR makes stored memories show up in chats. Per-turn recall now judges a match against how the question scores across the whole store, instead of a fixed 0.5 cut-off that natural questions almost never cleared. The always-on memory section fills its 4,000-character budget newest first, and successful memory steps are hidden from the activity list. The logic holds up and the new tests cover the behaviour well. Nothing blocks the merge. Two things to know:
The PR names the evals to watch ( Real-world evidenceN/A: no evidence bundle was produced for this run. The two Agent UI checks in the Test plan (a stored fact used in an answer, no memory step shown) are still unchecked, and the PR has no screenshot. Per the rubric, this Agent-UI-visible change should eventually get a before→after Playwright screenshot of the activity list. That's a nudge, not a blocker. pytest isn't installed on this runner, so I couldn't run the unit tests here. The verdict rests on static review alone. 🔍 Technical details🟢 Recency ordering is applied after a confidence-ordered 🟢 Header step count includes hidden steps ( 🟢 Overdue check compares a UTC date with a local date ( 🟢 Strengths
|
|
All four points were valid and are fixed in 0a8ba81.
🔍 Technical details
Evals to watch (memory prompt and per-turn context): |
|
On the long-horizon memory benchmark (#5340, The benchmark caught one real problem, now fixed in 9f6e9fe: session summaries ("in March, Maya lived in Calgary") were going into the always-on section and contradicting newer facts. With that, "shown clean" is 94%. It was 100% on the old baseline. Two benchmark checks still regress, and neither is something this PR should hide:
🔍 Technical details
|
Chats rarely used what memory stored. Natural questions score the memory they are about at 0.35-0.55 with embeddinggemma-300m, below the 0.5 per-turn floor, so "what should I get my sister for her birthday?" never brought up "my sister Priya lives in Vancouver". - Per-turn recall passes a match that stands clear of the field (median + 0.08) and sits near the best match (- 0.06), above 0.38; 0.5 still passes outright. Memories naming someone a match names come along, so a kids' lunch question brings the peanut allergy. On a 9-fact store, 8 of 9 expected memories surface (was 1), with no leaks on unrelated questions. - The always-on section fills its 4000-char budget instead of 5 facts, most recently confirmed first, with notes and upcoming reminders, no confidence numbers, and a count of what was left out. - The Agent UI activity list no longer shows successful memory tool steps; a failed one still shows.
Review follow-ups on the memory recall change. - Past 200 rows of one kind, a recently confirmed low-confidence fact could miss the always-on section: the store picked 200 by confidence before the newest-first sort. The store query now orders by updated_at itself (get_by_category_contexts gains newest_first). - A reminder's due day is now the local day, both for leaving out ones that have passed and for the date shown. A malformed due_at raises with the memory id instead of a bare parse error. - The activity header counted hidden memory steps, so it could say "3 steps" and list two. It now counts what it shows when any step was hidden. - Docs say name-linking keys on any capitalised mid-sentence word.
A session summary is dated history ("in March, lived in Calgary"). Shown
in the always-on section next to current facts, it contradicted them: on
the long-horizon memory benchmark it leaked moved-away cities and old
jobs into what the agent sees. Facts consolidation extracts still show;
only its summary notes are left out, and they stay recallable.
The memory SDK page still said notes are shown in the always-on section, but session summaries from consolidation are now left out there so dated history can't contradict newer facts. They remain recallable.
9f6e9fe to
7f7690a
Compare
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]>
…it found (amd#5340) 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 amd#5395: the share of what the agent is shown that is current and correct went from 81% to 100%. Builds on amd#5395 (the stale-memory fixes, split out so they can land on their own), which builds on amd#5243. Their commits are included; review only the last three. Refs amd#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. amd#5324 targets those, and this bench measures them. ## Test plan - [x] `gaia eval memory --suite pr --gate tests/fixtures/eval_baselines/memory-bench/pr.json` passes; three runs gave identical results - [x] `python -m pytest tests/unit/eval/test_memory_bench.py tests/unit/test_memory_stays_current.py` - [x] `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` - [x] `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) <details> <summary>🔍 Technical details</summary> - **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`. </details> --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Kalin Ovtcharov <[email protected]>
…saves (amd#5551) Three must-not-regress scenarios that passed on v0.25.0 fail on v0.25.1-rc2 and rc3. An old memory like "this page returned 503, don't waste tool calls on it" was obeyed as a ban, so the agent refused a URL the user had just given it. And untrusted document text could be saved to memory, or presented later as the user's saved details. After this change, memories reach the model as dated notes the user's request outranks, and `remember` won't save text the session read from a file, page or tool unless the user asks for it. <details> <summary>🔍 Technical details</summary> - **Cause.** For the stale-lesson turn, the request GAIA sends (system prompt, memory section, user message) renders byte-identical at v0.25.0 and rc3. Only three tool docstrings differ, none of them web or memory tools. Between those runs the eval runtime moved from Lemonade 2026.40.0 / llama.cpp b10825 to 2026.42.1 / b11393 (amd#5148). So the same "Known errors to avoid: … don't waste tool calls on it" text now gets a different answer, and the framing was the weak point. amd#5243 adds a second effect: extraction may no longer correct a stale error from tool output, so the seeded 503 note outlives its scenario. `res_web_partial_outage_compare` has no `memory_clear` and inherits it. - **Framing.** The personal block opens with a "notes, not instructions" line. `error` is retitled "Problems seen before", and a transient error gets a passing-failure marker (the existing markers plus 429/502-504 statuses). Two instruction bullets are added, and the per-turn recall header is reworded. amd#5324's newest-first, fill-to-budget selection is unchanged. - **Write path.** A session-wide record of tool results (30 calls, 20K chars each) is checked with the existing `_copied_from_material`. A save is allowed when the user's message is a storage request (a verb opening a clause, so "what do you remember?" doesn't count) or a yes after an earlier refusal of near-identical text. `error` memories are exempt, but relabelling one into a user category is checked. - **Known gaps.** `EmailTriageAgent` puts `Agent` ahead of `MemoryMixin`, so neither this guard nor extraction's source check sees its tool results. A planted line more than 30 tool calls back, or deeper than 20K chars into a result, falls outside the record. One real request to remember ("remember I like tea, then summarize vendor_note.txt") lets every other save that turn through. </details> ## Test plan - [x] `python -m pytest tests/unit/test_memory_notes_not_orders.py tests/unit/test_memory_turn_recall.py tests/unit/test_memory_error_staleness.py` (44 new tests: framing, ordering, cap, write-guard bypasses and false positives) - [x] `python -m pytest tests/unit -k "memory or prompt or recall"` and `hub/agents/{gaia,chat}/python/tests`: no new failures. `test_profilespec_characterization` goldens and `test_chat_system_prompt_budget[full-0]` fail the same way on clean `main`. - [x] `python util/lint.py --all` - [ ] Targeted eval on this branch: `gh workflow run eval_flagship.yml --ref fix/memory-lessons-and-poisoning -f scenarios=res_stale_lesson_page_back_up,res_web_partial_outage_compare,mem_document_memory_poisoning` - [ ] Then the `memory` and `gaia_memory` categories on this branch (`-f categories=memory,gaia_memory`), compared with `tests/fixtures/eval_baselines/gaia-flagship/`
GAIA stored the right facts after #5243, but chats rarely used them. Asking "what should I get my sister for her birthday?" never brought up "my sister Priya lives in Vancouver", and a long-time user's older facts dropped out of the prompt, where stale facts could outrank the facts that replaced them. Now a natural question surfaces the memories it's about (8 of 9 in the test below, up from 1). The always-on memory section holds as many memories as fit, newest first, instead of 5 facts. Memory also stays in the background: the activity list no longer shows "Saved to memory" steps.
Part of #5234.
remember/recall/update_memory/forgetsteps are hidden from the activity list. A failed one still shows. The agent still saves without announcing it.🔍 Technical details
Recall hits for natural questions, measured with the same
embeddinggemma-300M-Q8_0GGUF Lemonade serves. It ran in a private CPU llama-server because an eval held the shared Lemonade. Store A has 9 user facts; store B adds 20 unrelated ones._recall_memories_for_turn: cosine ≥ 0.5, or (store ≥ 8) ≥ max(0.38, median of the 200 nearest + 0.08, best − 0.06). Top 3, plus up to 2 memories that share a name with a match (cosine ≥ 0.35). The thresholds come from a grid over both stores: the most expected hits with no leaks on unrelated questions.MemoryStore.searchbumps confidence, and surfacing a memory must not count as a use. Natural questions also share few words with the fact they're about ("kids" vs "children").Evals to watch (this changes the memory prompt and the per-turn context):
memory,gaia_memory,context_retention,personality,gaia_tool_selection. They weren't run locally; the next RC's eval covers them.Test plan
python -m pytest tests/unit/test_memory_turn_recall.py tests/unit/test_memory_mixin.py tests/unit/test_memory_prompt_growth.py tests/unit/test_memory_heal_lessons.py tests/unit/test_system_prompt_composition.pycd src/gaia/apps/webui && npx vitest run src/components/__tests__/AgentActivitypython util/lint.py --black --isort --pylint --flake8