Repository navigation
fix(memory): show memories saved under a context label - #4062
Conversation
The remember tool let the model file a memory under 'work' or 'personal', and
bootstrap writes 'work' rows, but a default session reads only 'global' rows
and nothing sets another context. Those memories were stored and never shown
again. In a learning benchmark two standing rules saved with context='work'
were missing from the next three sessions.
- Read side: a default ('global') session now reads every non-sensitive
context in the stable prompt, the reminder context, and the extraction
dedup search. An agent that set its own context (email) keeps it + global.
- Write side: remember and update_memory no longer take a context. New
memories go under the agent's active context, so a model-picked label can't
hide one.
|
Request changes — the core fix is right and well-tested, but widening the read scope also widens a gap in the "sensitive" privacy flag, and one doc still describes the old, now-removed behaviour. Memories the model filed under a label like "work" or "personal" were written and never read back. Making a default session read every context (and taking the label away from the model) is the right call, and it repairs rows already on disk without a migration. Two things to fix before merge:
Also: the agent eval on the memory categories is still unchecked in the test plan. The project requires it whenever a tool's schema or docstring changes, which this PR does (a parameter was dropped) — please run it against the committed baseline before merge, or say explicitly why it's being waived. Real-world evidenceN/A — no 🔍 Technical details🟡 Sensitive reminders bypass the sensitivity filter (
(Filtering in SQL via a 🟡
CLAUDE.md's doc-sync rule ("a functional change must update EVERY doc that describes it") covers this file alongside the guide and SDK page you did update. 🟢 Dead local (
🟢 Duplicate scope logic (
🟢
Strengths
|
|
Merged current 🔍 Technical detailsMerge commit Tests: |
_build_dynamic_memory_context reads the scope through _read_scope() now, so the old ctx binding is unused and pylint W0612 reds the gate.
Marking a memory sensitive is documented as keeping it out of the prompt, but the upcoming/overdue reminder list never checked the flag. It only ever showed default-scope rows, so the gap was unreachable; reading every context makes it reachable, and a reminder the user marked private could be injected into the turn — which for a cloud model means it leaves the machine. get_upcoming now filters sensitive rows in SQL, so private rows cannot consume the limit and leave the visible list empty. The same list also skipped the credential masking the other memory sections run, so it now goes through _redact_credentials too. The dashboard keeps its access via an include_sensitive query param, matching /api/memory/knowledge. Also syncs docs/spec/agent-memory-architecture.md, which still showed remember() and update_memory() taking a context label and still described the old global-plus-active-context read rule.
|
Closed the privacy gap this PR made reachable: a reminder the user marked private can no longer reach the model's turn. Marking a memory sensitive is documented as keeping it out of the prompt, but the upcoming/overdue reminder list never checked the flag. It only ever showed default-scope rows, so the gap was unreachable — widening the read to every context is what made it live. A private reminder could then be injected into the turn, which for a cloud model means it leaves the machine. Filtering happens in SQL rather than after the fact, so ten private rows can't consume the limit and leave the visible list empty. The same list also skipped the credential masking every other memory section runs, so it goes through that now too. The dashboard keeps its access through an Also synced the memory spec, which still showed 🔍 Technical detailsThe fix. Three tests added to The middle one is the reason for filtering in SQL: 10 sensitive rows + 1 visible one, and the visible one must still appear. Docs. In Tests. Both failures ( Merged current Still open from the review: the |
|
Re-merged current main (129 commits further since the last sync) — clean, no conflicts left after resolving one docstring collision, and the memory test suite still passes in full. What's still missing before this can merge is the one item the last review left open: the I attempted it twice against a local backend and both runs came back Still needed before merge: 🔍 Technical detailsMerge. Fetched Tests: Lint: Eval attempts. First run used the shared |
|
🟡 The Memory dashboard's "Upcoming" panel now hides the user's own private reminders. The privacy fix correctly keeps sensitive reminders out of the model's turn, but it also changed the dashboard endpoint to drop them by default, and the dashboard doesn't ask for them. A reminder the user marks private silently disappears from their own Upcoming list, while the stats header still counts it — so the count and the list disagree. Suggested fix: have the dashboard request sensitive items on this call, the same way its knowledge list already does, and add a test for that endpoint's default. 🔍 Technical details
Fix: append |
|
Folded into #4406, which combines this with the other three memory PRs so they can be tested as one change. This one is fully contained there — GitHub refuses to repoint the base at the combined branch precisely because there are no commits left between them. Closing this once #4406 merges; nothing here is dropped. 🔍 Why it was combined rather than merged on its ownAll four memory PRs edit the same |
…ge (amd#4061) Memory held useful lessons that the model almost never saw. The memory section of the system prompt is fixed at session start and picks facts by confidence alone, whatever the user is asking. Everything else only surfaced if the model called `recall`, and it did so 4 times in a 2,121-task benchmark sweep. Surfaced memories also had no dates, so a lesson learned months ago under different permissions looked as current as one confirmed yesterday. Each turn now adds the three stored memories most relevant to the request to the per-turn context, which is prepended to the user message. The cached system prompt doesn't change. A memory has to clear a similarity floor, so an unrelated nearest match isn't shown. It must also be in this context or global and not sensitive, credentials are masked, and anything the system prompt already shows is skipped. Every memory the model sees without calling `recall` now carries a short "(learned 2026-06-03, last confirmed 2026-09-20)". The dates are absolute, so the fixed prompt stays stable, and the per-turn context already carries the current time. <details> <summary>🔍 Technical details</summary> - Uses a vector-only FAISS search with an absolute cosine floor (`TURN_RECALL_MIN_SIMILARITY = 0.5`), not `_hybrid_search`. RRF gives no absolute floor, and hybrid search bumps confidence on every hit, which would inflate anything shown passively. - About the floor: it is set from memory-to-memory similarity in the sweep stores (nomic-embed-text-v2). Unrelated pairs have a median around 0.34 and same-topic pairs sit above 0.8. It hasn't been measured on query-to-memory pairs, and the eval below is where it gets checked. - Cost: one embedding call before each turn when the index isn't empty. Extraction already embeds the same text after the turn, so that later call now hits the embedding cache. If embedding fails, the turn still gets its time and reminders, and a warning is logged. - "Last confirmed" is `updated_at`, which moves when the same memory is stored again or updated. </details> ## Test plan - [x] `pytest tests/unit/test_memory_turn_recall.py`: 13 new tests on a real SQLite store and FAISS index. The 6 positive ones fail on main. Covers the exact injected line with its age, the top-3 cap, dedup against the stable prompt, no confidence or use-count bump, context scope (a default session reads every context, the same rule as amd#4062; a scoped one reads its own), excluded rows (sensitive, reminder, below floor), credential masking, embedder failure, stable-prompt ages, and that the memory arrives on the user message while the system prompt stays byte-identical - [x] `pytest tests/unit -k memory`: 1101 passed. Hub chat/gaia memory tests: 22 passed - [x] `python util/lint.py --black --isort` - [ ] `gaia eval agent` on the memory categories vs the committed baseline (memory prompt content changed) --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
Three of the four consolidated PRs were merged to main directly while this branch was under test, so most conflicts here are the same work arriving twice. Took main's arrangement of the lesson constants and the session-lessons block, and kept this branch's two things main does not have: #4034's background extraction, and the lesson-scope fixes the hardware run found.
…n their workspace (amd#4406) Memory extraction used to run *before* the answer reached the screen, so every turn that stated a fact paid the model call twice over — once for the answer, once to decide what to remember. This moves extraction to a background worker: the answer lands, the turn returns, and the extraction follows. On a Ryzen AI machine that was measured at 19 seconds of the user's time given back on a single turn. It also carries four fixes found while testing this against the memory work that landed on main (amd#4061, amd#4062, amd#4066) — two of which only exist *because* those changes now run together. Closes amd#4034. The other three memory PRs merged to main directly; this branch has been merged with main and carries only what main lacks. ### What's fixed here that isn't on main - **A closed memory store could segfault the process.** `MemoryStore.close()` took no lock, so agent teardown freed the SQLite connection while the extraction thread was mid-statement. A segfault aborts the whole process, so this would have taken the Linux unit job down rather than failing four tests. `close()` now holds the connection lock and every DB method refuses a call that lost the race. - **A workspace lesson could reach another project.** amd#4066 scopes lessons to one workspace and frames them against injection because their content is raw tool output; amd#4061's per-turn recall reads every context in a default `global` session. A lesson from project A could surface in project B, unframed. **This one is live on main today.** - **The same leak, one call further in.** The background extraction job builds its "existing memory" list from the same unfiltered scope, so another workspace's lessons reached that prompt too. Observed on hardware, then fixed. - **An ordinary fact could be silenced forever.** The lesson filter keyed on `domain`, which the *extraction model* picks — so a turn that merely mentioned a lesson got its ordinary facts tagged `domain='lesson'` and suppressed from recall permanently. It now keys on `source`, which only the write path sets. ### Test plan - [x] `pytest tests/unit/test_memory_mixin.py tests/unit/test_memory_turn_recall.py tests/unit/test_memory_heal_lessons.py tests/unit/test_memory_context_visibility.py tests/unit/test_cli_memory_drain_on_exit.py tests/unit/test_memory_extraction_grounding.py` — **389 passed** - [x] `pytest tests/unit/` — 17,198 passed, 33 failed, **all 33 reproduce identically on main** (verified in a separate main worktree, not via `PYTHONPATH`, which cannot baseline in this repo) - [x] Real-world run on AMD Ryzen AI MAX+ 395 (Radeon 8060S, Vulkan, all three models on GPU) - [ ] `gaia eval agent` — not run; see note below ### Evidence Every fix has a test verified to fail without it — each was disabled in turn and the test watched go red. **Extraction is off the answer path.** Answer rendered at `13:20:15`; extraction finished at `13:20:34`. 19 seconds returned to the user on one turn. ``` 13:20:15 PERF process_query session=a1997a20 took=5.084s 13:20:15 [MemoryMixin] extraction started (context=global, waited 0.0s) 13:20:34 [MemoryMixin] extraction finished in 19.0s ``` **A lesson does not leave its workspace.** A real `tool_lesson` row in workspace A, then a turn from workspace B — absent from both the user-visible chat prompt and the extraction job's internal prompt. Before the fix it appeared in the latter; after, the "existing memory" list carries nine items and the lesson's id is not among them. **A fact the model mislabelled still surfaces.** A row with `domain=lesson` but `source=llm_extract` now reaches the turn: ``` Stored memories that may bear on this message: - [note] Tool call list_files on /tmp/gaia-scratch-… reported 0 total files. (learned 2026-09-28) ``` <details> <summary>🔍 Full evidence table and method</summary> Driven through the Agent UI in a real browser on `t-nx-strx-halo`, against a Lemonade already serving Gemma-4-E4B. Proof for prompt-content claims is the literal prompt sent to the model (llama-server `--log-prompts-dir`), not the answer text — an answer can be right for the wrong reason, and absence claims cannot be proven from an answer at all. | Claim | Verdict | Artifact | |---|---|---| | Answer renders before extraction finishes | CONFIRMED | `backend.log` timestamps above | | A memory outside the stable prompt still surfaces per-turn, with its age | CONFIRMED | One prompt dump showing both halves: the stable `Known facts` list (5 highest-confidence decoys) and the dynamic `Stored memories that may bear on this message:` block carrying the target fact | | A memory under a non-global context label is visible | CONFIRMED | Dashboard row with `CONTEXT=work-project` | | A same-operation fail→fix in one turn is stored as a workspace-scoped lesson | CONFIRMED | `knowledge` row, `domain=lesson`, `source=tool_lesson`, `context=workspace:/…` | | That lesson is absent from another workspace's chat prompt AND extraction prompt | CONFIRMED | Both prompt dumps, zero hits; extraction half required this branch's fix | Two findings worth knowing, neither a defect in this PR: - **Per-turn recall is invisible on a small store.** The stable prompt records every memory it renders and recall skips exactly those, so with only a handful of memories recall correctly has nothing left to surface. Proving it needs enough memories to overflow the 4000-char stable cap. This cost two test rounds before the mechanism was understood. - **Nothing in the product sets a non-global memory context except the email sidecar.** `set_memory_context()` has no callers, and `remember()`'s docstring advertises a `context` parameter its signature lacks. Two unrelated bugs found along the way are filed separately as amd#4409 and amd#4410. **On the eval:** this branch changes no prompt wording, no tool schema, and no tool registration — it adds none. The dynamic-context sections it touches came from amd#4061/amd#4066, which are already on main. A scorecard run would measure main's behaviour, not this diff, and there is no committed flagship baseline to compare against. </details> --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
A memory the model filed under "work" or "personal" was saved and never shown again. The
remembertool offered acontextlabel, andgaia memory bootstrapwrites "work" rows. But a default session reads only "global" rows, and nothing in GAIA switches to another context. In a learning benchmark the user stated two standing rules, and the model saved them withcontext='work'. Sessions 2–4 ran on the same store, never saw the rules, and all three failed to follow them.A default session now shows memories from every context, and that also fixes rows already on disk. An agent that picked its own context, such as email, keeps it plus "global". The model can no longer choose a label:
rememberandupdate_memorystore under the agent's active context. I dropped the parameter rather than validating it. Validation would mean either rejecting the call, which wastes a turn, or quietly relabelling it, which is a silent substitution. The model can't know the agent's scoping anyway.🔍 Technical details
recallalready searches every context unless the model filters.context=gets the loop's structured "unexpected argument" error and can retry without it.Test plan
pytest tests/unit/test_memory_context_visibility.py: 6 new tests on a real on-disk store. A "work" preference saved in one session is in the next session's system prompt, and a "personal" reminder reaches the next turn (both fail on main). Sensitive rows stay out. Email scoping holds.rememberstores under the active context, and neither tool acceptscontextpytest tests/unit -k "memory or bootstrap": 1108 passed. Two existing tests updated because they encoded the old global-only read and the model-chosen labelpython util/lint.py --black --isorton changed filesgaia eval agenton the memory categories vs the committed baseline (memory tool schema changed)