Skip to content

feat(memory): surface memories relevant to each request, with their age - #4061

Merged
kovtcharov-amd merged 9 commits into
amd:mainfrom
kovtcharov:fix/memory-per-turn-recall
Sep 28, 2026
Merged

kovtcharov-amd merged 9 commits into
amd:mainfrom
kovtcharov:fix/memory-per-turn-recall

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

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.

🔍 Technical details
  • 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.

Test plan

  • 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 fix(memory): show memories saved under a context label #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
  • pytest tests/unit -k memory: 1101 passed. Hub chat/gaia memory tests: 22 passed
  • python util/lint.py --black --isort
  • gaia eval agent on the memory categories vs the committed baseline (memory prompt content changed)

The stable memory prompt picks facts by confidence alone at session start, and
everything else needed an explicit recall call, which models almost never make
(4 in 2,121 benchmark tasks). Relevant lessons sat unused in the store.

- Each turn, the few stored memories most relevant to the request (top 3,
  cosine floor 0.5, same context or global, not sensitive, credentials masked,
  not already in the stable prompt) are added to the per-turn dynamic context.
  That context is prepended to the user message, so the cached system prompt
  is unchanged. Surfacing does not bump confidence or use counts.
- Every memory the model sees without calling recall now shows the absolute
  dates it was learned and last confirmed, so a months-old lesson is visibly
  months old.
Same rule as the stable prompt: a 'global' session is unscoped, so a relevant
memory filed under 'work' or 'personal' is surfaced; an agent that set its own
context still sees only that context and global.
@github-actions

Copy link
Copy Markdown
Contributor

Request changes

This makes stored memories actually reach the model: each turn now prepends the three most relevant memories to the user message, and every surfaced memory carries the dates it was learned and last confirmed. The design choices are good — vector-only search with an absolute floor (so nothing unrelated sneaks in), no confidence bump for passive surfacing, credentials masked, and the cached system prompt left byte-identical. Two things should be settled before merge.

Dates can silently push existing memories out of the system prompt. The memory block is hard-capped and cut from the end, and the new age suffix adds roughly 45 characters to every preference, fact, skill and error line. A user whose memory is already near that cap loses the tail of the block — the "known errors to avoid" section goes first. It gets worse from there: the bookkeeping that stops a memory from appearing twice records every item the block tried to show, including the ones truncation just removed, so those memories are now missing from the system prompt and suppressed from per-turn recall. The fix is either to raise the cap to cover the extra characters or to only suppress what actually survived truncation.

The eval is the one test that can tell you whether this works, and it hasn't run. Your own test plan leaves it unchecked, and the project requires it for any change to prompt content — this change alters both the system prompt and every user message. It matters more than usual here: as the PR notes, the 0.5 similarity floor was calibrated on memory-to-memory pairs, and question-to-memory similarity runs systematically lower. If that gap is large, the feature is a no-op in production and every unit test still passes, because the tests supply their own vectors. Please run it against the memory categories and post the comparison.

Real-world evidence

N/A — no evidence bundle was produced for this PR. The verdict rests on static review plus the new unit tests; nothing here exercised the feature against a real embedder, which is exactly the gap the eval above would close.

🔍 Technical details

🟡 Age suffixes interact with the 4000-char cap, and truncated items are also hidden from turn recall (src/gaia/agents/base/memory.py:2298, :2341)

_build_stable_memory_prompt appends _memory_age(...) (~40–50 chars) to each of up to 10 preferences + 5 facts + 3 skills + 5 errors — up to ~1KB added — then hard-truncates at result[:4000]. tests/unit/test_memory_prompt_growth.py already documents that this block saturates the cap at realistic N, so this is not hypothetical: a store that fit before now loses its tail, and errors are the last section emitted.

The compounding part is shown_ids: it is populated from the full prefs/facts/skills/errors lists at :2296-2298, before truncation. A memory cut by the cap is still in _stable_memory_ids, so _recall_memories_for_turn skips it too (:2372). Net effect: items that were visible on main become invisible on both paths.

Two ways out — either is fine, pick one:

  • Raise the cap by the worst-case suffix budget (the cap's own comment budgets ~1000 tokens; the suffixes are new cost it wasn't sized for), or
  • Derive _stable_memory_ids from the lines that survive truncation, so per-turn recall can re-surface what got cut.

A regression test that stores enough items to saturate the block and asserts the errors section still renders would lock this down.

🟡 gaia eval agent not run for a prompt-content change

CLAUDE.md lists system-prompt and prompt-assembly changes as eval-required, and this PR changes both surfaces. The specific risk worth measuring:

  • TURN_RECALL_MIN_SIMILARITY = 0.5 was derived from memory↔memory cosines (median ~0.34 unrelated / >0.8 same-topic). _embed_text (:1073) applies no task prefix, so queries and documents share one space — but a short question against a stored sentence still scores well below two stored sentences on the same topic. If real query→memory hits land around 0.4, _recall_memories_for_turn returns [] on nearly every turn and the whole feature is dead weight that nothing in tests/unit/test_memory_turn_recall.py would catch (the fixture injects its own vectors).
  • Worth capturing alongside the eval: the observed score distribution for a handful of real queries against a real store. That is the number that justifies 0.5.

🟢 Nits

  1. Per-turn warning will repeat every turn (:2480). If faiss is missing or the embedder is persistently down, this logs a warning on every single turn for the life of the session. Consider logging at full severity once and demoting subsequent occurrences to debug.
  2. Up to 12 single-row get_item calls per turn (:2369, :2374). The candidate pool is fixed at TURN_RECALL_TOP_K * 4 and filtering happens in Python afterwards, so a store with many sensitive or other-context rows both starves the result set (fewer than 3 returned even when more qualify) and costs 12 round-trips. A batched fetch, or pushing the category/context/sensitive filter into the query, would fix both.
  3. "learned on an unknown date" (:2351) reads oddly in a prompt and burns tokens to say nothing. Returning "" and omitting the parenthetical is cleaner — though note it is unreachable in practice since created_at is NOT NULL.

Strengths

  • The test module is the strongest part of this PR. Real SQLite store, real FAISS index, deterministic hand-built vectors, and the negative cases carry the weight: other-context, sensitive, reminder, below-floor, credential-masked, embedder-failure. test_the_memory_rides_on_the_user_message_not_the_system_prompt asserting the system prompt stays byte-identical is exactly the right guard for a KV-cache invariant.
  • Deliberately not using _hybrid_search to avoid confidence inflation on passive surfacing is the right call, and the PR explains why rather than leaving a reviewer to guess.
  • Reusing _redact_credentials on the way out means the new path inherits the existing second gate instead of re-implementing it.

@github-actions github-actions Bot added the documentation Documentation changes label Sep 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🟡 The two flagged issues from the first review are still open.

The shown_ids / truncation bug is unchanged. _stable_memory_ids is populated from all items before the 4000-char truncation runs. A user whose stable prompt overflows the cap loses memories from the tail of the block (the errors section goes first) and those same memories are suppressed from per-turn recall — they are both invisible and blocked. The fix is to derive _stable_memory_ids from the lines that actually survive truncation, not from the full candidate lists.

gaia eval agent is still unchecked. The test plan box is explicitly left open, and CLAUDE.md treats this as a required step before merge for any change that touches system-prompt or user-message assembly — both of which this PR touches.

🔍 Technical details

_build_stable_memory_prompt at memory.py:2299-2300 sets self._stable_memory_ids from all four item groups, then the hard-cap truncation fires at :2344. _recall_memories_for_turn reads _stable_memory_ids at :2369 to skip "already shown" items — but items that were truncated aren't shown, so they should not be in the skip set.

Minimal fix: move the shown_ids accumulation loop to after the truncation, rebuilding it from the actual rendered lines (or raise the cap to account for the new per-item (learned …) suffix, as the prior review suggested as the alternative).

The eval concern: TURN_RECALL_MIN_SIMILARITY = 0.5 was calibrated on memory↔memory cosines, not query→memory pairs. If real queries score below 0.5 against stored memories, the feature fires on nearly zero turns and every unit test still passes (they inject their own vectors). The eval is the only way to measure this before shipping.

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Merged current main into this branch — it was behind, but nothing in the PR's own change had to move. The overlap with main was in the memory docs and memory.py, and all of it auto-merged.

🔍 Technical details

Merge commit d844544b7 (git merge origin/main, no rebase/force-push). Auto-merged: docs/guides/memory.mdx, docs/sdk/sdks/memory.mdx, src/gaia/agents/base/memory.py. PR content vs main: 4 files, +415/-18.

Tests: python -m pytest tests/unit/test_memory_turn_recall.py tests/unit/test_memory_mixin.py tests/unit/test_starter_skills.py -q → 503 passed, 15 skipped.

The stable memory prompt is hard-capped at 4000 chars and cut from the end,
so a large store loses the tail of the block -- the known-errors section
first. The suppression set that stops a memory being shown twice was built
from every candidate item, including the ones the cap had just removed, so
those memories were missing from the system prompt and blocked from per-turn
recall at the same time.

The set is now derived from the lines that survive truncation, so anything
the cap cuts can still be surfaced when it is relevant to the request.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Fixed the truncation bug the last two reviews flagged. A memory the 4000-char cap cut was missing from the system prompt and blocked from per-turn recall, so it went invisible on both paths — worse than before this PR added the dates. The suppression set is now built from the lines that actually survive the cap, so anything cut can still surface when it is relevant to the request.

The eval is still not run — that box stays open, and it is the one thing left before merge.

🔍 Technical details

_build_stable_memory_prompt collected shown_ids from the full prefs/facts/skills/errors lists before result[:4000] fired. It now accumulates (rendered line, id) pairs as each section is built and derives _stable_memory_ids after truncation from the lines still present in result. A line the cap cut mid-way does not match, so it stays recallable — which is the right call, since the model only saw a fragment of it.

Two regression tests in tests/unit/test_memory_turn_recall.py::TestTruncatedItemsStayRecallable, both failing on the parent commit and passing after:

  • test_a_cut_memory_is_still_offered_to_the_turn — saturates the block with 10 preferences, asserts the error memory is absent from the stable prompt and present in the per-turn context.
  • test_only_surviving_lines_are_suppressed — asserts the cut id is not in _stable_memory_ids while surviving ids are.

The fixture generates per-item vocabulary on purpose: MemoryStore.store dedupes on >80% word overlap, so repeated filler collapses 10 rows into 1 and the cap is never reached.

Tests: tests/unit/test_memory_turn_recall.py tests/unit/test_memory_mixin.py tests/unit/test_memory_store.py → 700 passed. util/lint.py --black --isort clean. Merged current main (132 commits); no conflicts.

Unaddressed from the earlier review, all 🟢 and left deliberately: the per-turn warning repeating each turn, the up-to-12 single-row get_item calls, and the "learned on an unknown date" wording (unreachable — created_at is NOT NULL).

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Sep 26, 2026
Resolved conflict in src/gaia/agents/base/memory.py: process_query needed
both the new _turn_tool_record init (main) and _memory_turn_query capture
(this PR) - independent per-turn state, kept both.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Merge conflict resolved and everything else checks out, but the required eval still hasn't run — this stays blocked on that one step, not on the code.

  • Merged current main: one real conflict in memory.py's process_query (main added self._turn_tool_record = [] for tool-call logging; this PR added self._memory_turn_query = user_input right next to it). Both are independent per-turn state, so I kept both lines.
  • tests/unit/test_memory_turn_recall.py, test_memory_mixin.py, test_memory_store.py, test_starter_skills.py: 905 passed, 15 skipped, 0 failed. util/lint.py --black --isort: clean.
  • Tried to run gaia eval agent --category memory (required here: this PR changes both the system prompt and per-turn user-message assembly). Along the way I hit and fixed two unrelated environment issues on this machine — a stale mcp package below the version GAIA's own setup.py [mcp] extra requires (blocked the eval's MCP bridge with an ImportError: cannot import name 'MCPServer'), and a global ~/.gaia/config.json default_model pointed at an unreachable cloud endpoint (every eval session 404'd before a single tool call ran). Both are fixed now.
  • Once those were fixed, the eval itself couldn't get a clean run: this machine had 2-3 other gaia eval agent processes running concurrently the whole time (other PRs' triage), all sharing the one local Lemonade instance. That's exactly the race-eviction scenario the eval-serialization rule exists to avoid, so I didn't add a third concurrent run or trust a result produced alongside them. I waited over 10 minutes for a clear window without one opening.
🔍 Technical details
  • Conflict: src/gaia/agents/base/memory.py:2692-2696 (pre-merge markers), resolved by keeping both self._turn_tool_record = [] and self._memory_turn_query = user_input.
  • Truncation fix from the last review round is intact and unchanged in the merged diff: _stable_memory_ids is derived from lines that survive the 4000-char cap (memory.py:2471), not from the full candidate lists.
  • Eval blocker specifics: eval/mcp_server_launcher.py → gaia.mcp.servers.agent_ui_mcp imports MCPServer from mcp.server, which doesn't exist in mcp==1.27.0 (needs mcp>=2.0.0,<3.0 per setup.py's [mcp] extra). Separately, gaia.ui.database.resolved_default_model() reads ~/.gaia/config.json's default_model, which was set to amd.GLM-5.2-FP8 (a cloud router model returning HTTP 404 here) — this overrides the eval harness's own Lemonade model pin at session-creation time, so every scenario failed before any tool call.
  • Verified the fix end-to-end on a single scenario (--scenario memory_conflict_resolution) before the machine got contended again: real Gemma-4-E4B-it-GGUF inference, real remember/recall tool calls, no infra error.

Next step: someone needs to run gaia eval agent --category memory on a machine with the local Lemonade backend free of other eval runs, then post the scorecard here.

@github-actions github-actions Bot added installer Installer changes dependencies Dependency updates devops DevOps/infrastructure changes chat Chat SDK changes mcp MCP integration changes rag RAG system changes llm LLM backend changes audio Audio (ASR/TTS) changes cli CLI changes labels Sep 26, 2026
@github-actions github-actions Bot added security Security-sensitive changes performance Performance-critical changes cpp agent::email Email agent changes agent::connectors-demo Connectors-demo agent changes tui Go terminal UI (gaia-tui) daemon Daemon supervisor / sidecar control plane sidecar Agent sidecar contract / harness labels Sep 26, 2026
@github-actions github-actions Bot added talk Talk agent changes electron Electron app changes website GAIA website (amd-gaia.ai) labels Sep 28, 2026
@itomek

itomek commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

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 own

All four memory PRs edit the same MemoryMixin, so every pair conflicted and none could be validated without the others. Two behaviours only survived because the fold was done deliberately rather than by taking one side: the turn's tool record and the extraction read scope both sat on lines that moved to the background worker, and a plain merge dropped them. Details are in #4406's description.

kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 28, 2026
A memory the model filed under "work" or "personal" was saved and never
shown again. The `remember` tool offered a `context` label, and `gaia
memory bootstrap` writes "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 with `context='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: `remember` and `update_memory` store 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.

<details>
<summary>🔍 Technical details</summary>

- The same "global means unscoped" rule applies to the reminder list in
the per-turn context and to extraction's duplicate search. `recall`
already searches every context unless the model filters.
- Sensitive rows stay out as before.
- A model that still passes `context=` gets the loop's structured
"unexpected argument" error and can retry without it.
- Docs updated: the memory guide's context section, which showed the
model storing into "personal" by chat, and the SDK page's filter
description and tool card. Also updated the bootstrap docstring that
described the old global-only read.
- The per-request retrieval in amd#4061 gets the same rule in a follow-up
commit on that branch.
</details>

## Test plan
- [x] `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. `remember` stores under the active context, and neither tool
accepts `context`
- [x] `pytest tests/unit -k "memory or bootstrap"`: 1108 passed. Two
existing tests updated because they encoded the old global-only read and
the model-chosen label
- [x] `python util/lint.py --black --isort` on changed files
- [ ] `gaia eval agent` on the memory categories vs the committed
baseline (memory tool schema changed)

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Ovtcharov <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
itomek added a commit that referenced this pull request Sep 28, 2026
#4066 scopes lessons to workspace:<root> so another project never sees them, and
renders them behind an anti-injection framing because their content is raw tool
output. #4061's per-turn recall reads every context in a default global session
and files lessons under 'note', so a lesson from project A could surface in
project B — as a bare note, without that framing, and potentially twice in one
prompt.

Recall now skips the lesson domain outright; lessons keep their own path. Docs
that contradicted each other on the same page set are reconciled, and the spec's
dynamic-suffix section now lists the two sections these PRs added to it.
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 28, 2026
…amd#4066)

**Stacked on amd#4058.** The first four commits are that PR. Review the
last two here.

The agent rediscovered the same project quirk every session. When a call
failed and the agent worked around it (say `pytest` fails with "test
clock not configured", it reads the doc, reruns with `env
TOYBOX_CLOCK=frozen` and it passes), memory stored the error and then
deleted it on the success. Nothing recorded what fixed it, so the next
session started from scratch.

Now that fail-then-fix sequence in one turn becomes a lesson, built only
from the two calls: the failing call and its error, the call that
worked, and what changed ("added `env TOYBOX_CLOCK=frozen`"). It belongs
to the workspace it happened in, and the next session there sees it in
its memory prompt with the date learned. It gains confidence each
session the fix works again and is dropped when the fix itself fails.
Other folders never see it.

<details>
<summary>🔍 Technical details</summary>

- The pairing key is amd#4058's operation key: the tool plus the program it
runs (past `env`, `VAR=value` and `python -m`) or the path. The failing
and working calls must have different arguments, so a plain retry that
happens to pass teaches nothing. Refusals (`executed: False`) never
count, either as the failure or as a failed fix. There's no matching on
error wording.
- Scope: stored as `category="note"`, `domain="lesson"`, in the memory
context `workspace:<most specific allowed path>`. That context keeps
lessons out of every other workspace's prompt and retrieval, including
amd#4061's per-request recall. So lessons are shown in their own
stable-prompt section (top 3 by confidence), not through relevance
search, which would also hide them whenever the request is worded
differently from the lesson.
- Within a session, later turns get the new lessons in the per-turn
context, since the stable prompt is frozen. Within a turn there was a
real loss path: overflow recovery stubs every tool result except the
latest, which drops the failure a fix answered. The recovery now
restates this turn's lessons on the last user message. The cache is
already lost at that moment, so this costs nothing extra.
- A lesson whose text looks like a credential isn't stored.
</details>

## Test plan
- [x] `pytest tests/unit/test_memory_heal_lessons.py`: 14 tests on a
real on-disk store, over several sessions sharing one DB. All 7 positive
tests fail on the pre-change source. Covers the exact lesson text and
row shape, no lesson for a same-call retry / a refused failure / a
different program / a failure and fix in different turns, a path tool's
changed argument, the next session's prompt in the same workspace but
not another, the rest of the session, confirm once per session (0.5 →
0.6), drop when the fix fails, keep when the fix is refused, and
overflow recovery keeping the lesson (idempotent)
- [x] `pytest tests/unit -k "memory or overflow or shrink"`: 1155
passed. The 1 failure, `test_tool_loader_token_budget`, also fails on
main
- [x] black + isort on changed files
- [ ] `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]>
# Conflicts:
#	src/gaia/agents/base/memory.py
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 28, 2026
Merged via the queue into amd:main with commit 6c2dfcb Sep 28, 2026
35 of 39 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/memory-per-turn-recall branch September 28, 2026 17:53
itomek added a commit that referenced this pull request Sep 28, 2026
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.
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Sep 28, 2026
…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]>
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Oct 4, 2026
…md#4662)

Every open PR shows these two failures; this clears them. The macOS one
is fixed here; the Windows one is fixed by amd#4585, so the smoke jobs go
green once both merge.

- **macOS, `test_memory_turn_recall`:** an audio test imported the
Whisper ASR module, and that import loaded torch. Once torch is loaded,
macOS has two OpenMP runtimes in the process (torch's and faiss's), so
memory recall refuses every faiss search for the rest of the run. torch
and whisper are now imported only when an ASR is actually created. The
recall test runs and passes; it isn't skipped. amd#4580 handles this
failure by skipping the test, so drop that half of amd#4580 when this
merges.
- **Windows, `test_resolves_direct_shebang_posix`:** the test faked
Linux by patching `sys.platform` for the whole process. pyfakefs
teardown then took the POSIX path and called `os.getuid`, which doesn't
exist on Windows. amd#4585 now patches only the uninstall module's view of
the platform, so this PR doesn't touch it.

The macOS failure dates from amd#4061 (Sep 28), which added the recall test
after the torch-loading audio test from amd#3616. The smoke job runs with
`-x`, so earlier failures hid it until amd#4562 fixed those on Oct 2.

## Test plan
- [x] New `test_importing_whisper_asr_does_not_load_torch` fails on main
and passes here
- [x] Locally on macOS, all audio and memory tests in CI order: 433
passed, `test_memory_turn_recall` included
- [x] Locally on macOS, every unit test up to and including the recall
test: torch never loads, and recall passes. The 13 failures are local
env noise (CLI binaries not on PATH, pip frontends); none import the
audio module
- [ ] CI: "Unit Tests (macOS smoke)" passes `test_memory_turn_recall.py`

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
@kovtcharov-amd kovtcharov-amd mentioned this pull request Oct 6, 2026
5 of 10 tasks
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 6, 2026
# GAIA v0.25.0 Release Notes

## Breaking Changes

- **`gaia chat` runs the flagship GAIA agent**, the same agent as the
TUI and Agent UI, instead of the retired ChatAgent. `gaia chat -q "…"`
queries it once. (PR [amd#4520](amd#4520))
- **`gaia talk` transcribes and speaks through Lemonade** — it uses
Lemonade's Whisper and `kokoro-v1`, and stops with the reason if
Lemonade is down. The `[audio]` extra is gone; `pip install
amd-gaia[audio]` only warns. (PR
[amd#4665](amd#4665))
- **The Agent UI runs only the GAIA agent** — the Agent Hub home, agent
picker, and custom-agent export/import are removed from the UI. The CLI
and eval harness can still run other agents. (PR
[amd#4509](amd#4509))
- **The retired nomic embedder is removed** — memory saved with it is
re-embedded on first start. (PR
[amd#4489](amd#4489))
- **Indexed documents are re-indexed once** — the document cache is now
keyed on chunking settings, so the first query after upgrading rebuilds
it. (PR [amd#4624](amd#4624))
- **A skill that asks for more than its tier allows no longer loads** —
the permission ceiling is checked at every load, so a skill already on
disk that exceeds it is refused with the reason. (PR
[amd#4849](amd#4849))

## What's New

- **A larger local model where the GPU holds it** — `gaia init` picks
Qwen3.6-35B-A3B on a 64 GB+ Strix Halo or a 32 GB GPU and keeps
Gemma-4-E4B elsewhere, with each context window sized to available
memory. Qwen3.8 Flash Next is opt-in on 128 GB Strix Halo. (PRs
[amd#4479](amd#4479),
[amd#4670](amd#4670),
[amd#4671](amd#4671),
[amd#4658](amd#4658),
[amd#4655](amd#4655))
- **The Agent UI opens straight to a chat and sets itself up** — a fresh
install runs the same setup steps as the TUI in the window, with
provider, key and model settings, permission modes, and revocable
"always allow" grants. (PR
[amd#4509](amd#4509))
- **A much smaller install** — PyTorch, transformers and accelerate are
gone from the core, `[ui]` and `[talk]` installs; the desktop app's
Python environment drops from ~0.9 GB to ~0.1 GB on Windows. (PRs
[amd#4666](amd#4666),
[amd#4621](amd#4621),
[amd#4665](amd#4665))
- **One Windows installer for the desktop app and the terminal**, with a
GAIA Windows Terminal profile. (PRs
[amd#4720](amd#4720),
[amd#4707](amd#4707))
- **A "no" holds** — a declined action isn't retried through another
tool; the agent asks again with the exact command. The TUI gains
Shift+Tab permission modes. (PRs
[amd#4460](amd#4460),
[amd#4461](amd#4461))
- **Answers are checked against what the tools actually did** — the
agent looks at files you name before answering about them, and a short
plain-English note appears only when work isn't confirmed. (PRs
[amd#4532](amd#4532),
[amd#4501](amd#4501),
[amd#4508](amd#4508))
- **One shell session** — commands share a persistent shell, risky ones
ask instead of being refused, and "full access" is one setting
everywhere. (PR [amd#4408](amd#4408))
- **Memory surfaces what's relevant to each request, with its age**,
keeps what fixed a failure as a lesson for that workspace, and extracts
after the answer instead of before it. (PRs
[amd#4061](amd#4061),
[amd#4066](amd#4066),
[amd#4406](amd#4406))
- **`gaia.log` stays bounded** — it rotates at 10 MB with three backups
(`GAIA_LOG_MAX_MB`, `GAIA_LOG_BACKUPS`). (PRs
[amd#4668](amd#4668),
[amd#4760](amd#4760))
- **Child processes get a trimmed environment** — shell, MCP and skill
children no longer inherit GAIA's internal credentials; `GAIA_NO_DOTENV`
skips loading `.env`. (PRs
[amd#4635](amd#4635),
[amd#4659](amd#4659))
- **Every file tool checks the allowed-folders rule**, and paths inside
an inline shell script are checked one by one. (PRs
[amd#4656](amd#4656),
[amd#4758](amd#4758))

## Bug Fixes

A selection of the user-visible fixes; the full list is in the changelog
below.

- **Local Qwen models no longer loop on repeated tool calls** — they run
with their model card's sampling instead of near-greedy settings. (PR
[amd#4655](amd#4655))
- **Qwen3.6 runs on a Strix Halo with an older AMD driver** — it used to
crash on its first token, so `gaia init` failed; GAIA now turns off the
Vulkan path that crashes on those drivers only, and newer drivers keep
the faster path. (PR [amd#4674](amd#4674))
- **A long PDF no longer hangs or times out while indexing** — big
documents index in the background, and PDFs that only carry
owner-password restrictions now index. (PRs
[amd#4754](amd#4754),
[amd#4679](amd#4679),
[amd#4734](amd#4734))
- **Document answers cite the right document and page**, and every chunk
is embedded whole instead of its first 1,200 characters. (PRs
[amd#4688](amd#4688),
[amd#4723](amd#4723))
- **`gaia init` fails when model verification fails**, shows downloads
live, and no longer hangs while Lemonade hashes a large model. (PRs
[amd#4620](amd#4620),
[amd#4564](amd#4564),
[amd#4673](amd#4673))
- **`gaia init` adds a profile's extras without reinstalling GAIA**,
which failed on Windows while `gaia.exe` was running. (PR
[amd#4672](amd#4672))
- **Every SDK and CLI entry point starts GAIA's own Lemonade**, and
every call goes to the resolved URL with its API key. (PRs
[amd#4657](amd#4657),
[amd#4627](amd#4627))
- **Local chat stays cached across turns** — the system prompt is fixed
and side requests no longer evict the conversation. (PRs
[amd#4698](amd#4698),
[amd#4543](amd#4543))
- **A cloud model selection never preloads a local model**, and cloud
models no longer get llama.cpp-only fields. (PRs
[amd#4757](amd#4757),
[amd#4709](amd#4709))
- **The Agent UI stops claiming "100% local" while chat goes to a cloud
model**, and the chat header names the session's real model. (PRs
[amd#4711](amd#4711),
[amd#4550](amd#4550))
- **Enter can't approve a permission prompt**, and prompts wait 10
minutes before timing out. (PRs
[amd#4700](amd#4700),
[amd#4699](amd#4699))
- **Stopping a run keeps the turn and its steps visible.** (PR
[amd#4743](amd#4743))
- **A file edit keeps the file's line endings** — a one-line edit on
Windows used to rewrite every line ending, so a small change showed up
as the whole file changed. (PR
[amd#4864](amd#4864))
- **A broken agent install is reported as broken, not as missing** — the
error names both package versions and the real import error, and
suggests a reinstall that works. (PR
[amd#4588](amd#4588))
- **A meeting or document summary is never cut off mid-sentence** — a
thinking model used to spend the summary's output budget reasoning, so a
long meeting lost its second half. (PR
[amd#4827](amd#4827))
- **"What can you do?" gets an answer** instead of an attempt to
generate an image of the question. (PR
[amd#4809](amd#4809))
- **Writes and approved edits can't reach credential folders**
(`~/.ssh`, `~/.aws`, `~/.kube` and others), and shell option values and
script arguments get the same path check as plain paths. (PRs
[amd#4848](amd#4848),
[amd#4847](amd#4847))
- **`gaia connectors connect google --grant-agent installed:gaia`
works** — it used to fail with no sign-in link for the shipped agent; it
now asks for read-only Gmail and grants exactly that. (PR
[amd#4859](amd#4859))
- **A "no" to creating a folder also covers writing into it** — GAIA no
longer asks again to create the same folder a different way. (PR
[amd#4857](amd#4857))
- **`gaia skill import` runs the same checks as a hub install** — https
only, the audit, the permission ceiling, and an explicit opt-in for
skills that ship code. (PR
[amd#4849](amd#4849))
- **Memory off and private chats apply to scheduled and background runs
too.** (PRs [amd#4842](amd#4842),
[amd#4821](amd#4821))
- **Memory stops false apologies and reusing deleted values**, saves
"remember this" requests, and skips loading the embedder when memory is
off. (PRs [amd#4708](amd#4708),
[amd#4756](amd#4756))
- **A reply cut off by the token limit is continued** instead of ending
mid-sentence, and a tool call cut off at the output cap is retried
shorter. (PRs [amd#4054](amd#4054),
[amd#4556](amd#4556))
- **The TUI remembers the chosen model** across restarts and
agent-process restarts. (PRs
[amd#4497](amd#4497),
[amd#4710](amd#4710))
- **`gaia uninstall --purge` removes installer binaries, PATH edits and
daemon state.** (PR [amd#4413](amd#4413))

## Contributors

Thanks to the community members who contributed to this release:

- [@itomek](https://github.com/itomek) — the flagship's browser and tool
picker, one shell session, memory extraction off the answer path, stale
tool-result eviction, the TUI's sourced Fireworks rankings, and
`--purge` cleanup (PRs [amd#4407](amd#4407),
[amd#4408](amd#4408),
[amd#4406](amd#4406),
[amd#4465](amd#4465),
[amd#4414](amd#4414),
[amd#4413](amd#4413))
- [@mikemikimike](https://github.com/mikemikimike) — chained shell
command timeouts, bundled skills in frozen builds, and sidecar cleanup
reporting (PRs [amd#4463](amd#4463),
[amd#4467](amd#4467),
[amd#4419](amd#4419))
- [@Hashim1999164](https://github.com/Hashim1999164) — honoring
`GAIA_HOME` for cache, chat and index paths (PR
[amd#4381](amd#4381))
- [@krtadev](https://github.com/krtadev) — `~` expansion in file and
document tool paths (PR [amd#4576](amd#4576))
- [@aksh8b](https://github.com/aksh8b) — telling a broken agent install
apart from a missing one, with a reinstall hint that works (PR
[amd#4588](amd#4588))
- [@Dev-next-gen](https://github.com/Dev-next-gen) — numeric prerelease
ordering in the hub (PR [amd#4517](amd#4517))
- [@vianmangal](https://github.com/vianmangal) — recording denied tool
calls as unsuccessful in memory (PR
[amd#4412](amd#4412))
- [@GaetanVDB07](https://github.com/GaetanVDB07) — links to upstream
credential setup guides for connectors (PR
[amd#4669](amd#4669))
- [@rradjabi](https://github.com/rradjabi) — moving self-hosted CI jobs
to the xsj-dispatch runner pool (PR
[amd#4534](amd#4534))




## Also in this PR

- **Hub floors raised to core 0.25.0** — the chat agent imports the
allowed-folders check that only 0.25.0 ships (amd#4656), so
`gaia-agent-chat` goes to 0.2.0 with `amd-gaia>=0.25.0`, and the
flagship requires `amd-gaia>=0.25.0` and `gaia-agent-chat>=0.2.0`.
- **Two follow-ups held back until that floor could rise** —
`~/.gaia/logs/gaia-agent.log` now rotates like `gaia.log` (amd#4668), and
the chat agent's Python runners and Windows notification start their
children without GAIA's internal credentials (amd#4659).

The full changelog (300 commits) is in `docs/releases/v0.25.0.mdx`.

## Test plan

- [x] `util/validate_release_notes.py docs/releases/v0.25.0.mdx --tag
v0.25.0` passes; narrative is 590 words (cap 600)
- [x] `util/check_component_core_api.py --release-version 0.25.0` passes
- [x] `pytest tests/unit/test_docs_json_release.py
tests/unit/test_check_component_core_api.py
hub/agents/chat/python/tests/test_chat_dependency_floor.py
hub/agents/chat/python/tests/test_dependency_floor.py
hub/agents/gaia/python/tests/test_gen_binaries_lock.py` (72 passed)
- [x] `pytest hub/agents/gaia/python/tests/test_stdio.py` (91 passed,
incl. the new rotation test); `pytest
tests/unit/test_execute_python_file_cwd.py
tests/unit/test_run_python_tool.py` (42 passed)
- [ ] `mintlify validate` (docs CI job) — timed out locally, relying on
CI
- [x] Full flagship eval on main 9ce6598
(https://github.com/amd/gaia/actions/runs/37436249503): 181/308
scenarios pass vs 100/183 for the same categories in the baseline, 39
FAIL→PASS, 13 PASS→FAIL (two fixed in amd#4878, held until after rc1);
retrieval lane still finishing at merge time
- [ ] CI green

## Release checklist

- [ ] Publish `gaia-agent-chat` 0.2.0 only after core 0.25.0 is on PyPI
— it fails at import on an older core
- [ ] Build Installers on the merged SHA (pre-tag verification) before
pushing `v0.25.0`
- [ ] terminal-hub 0.25.0 published before the flagship npm release
consumes `binaries.lock.json`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::connectors-demo Connectors-demo agent changes agent::email Email agent changes agents audio Audio (ASR/TTS) changes chat Chat SDK changes cli CLI changes cpp daemon Daemon supervisor / sidecar control plane dependencies Dependency updates devops DevOps/infrastructure changes documentation Documentation changes electron Electron app changes eval Evaluation framework changes installer Installer changes llm LLM backend changes mcp MCP integration changes performance Performance-critical changes rag RAG system changes security Security-sensitive changes sidecar Agent sidecar contract / harness talk Talk agent changes tests Test changes tui Go terminal UI (gaia-tui) website GAIA website (amd-gaia.ai)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants