Skip to content

fix(rag): never call an attached document past the 100 cap unattached - #8068

Merged
kovtcharov-amd merged 13 commits into
amd:mainfrom
kovtcharov:kalin/rag-attached-past-cap
Nov 14, 2026
Merged

kovtcharov-amd merged 13 commits into
amd:mainfrom
kovtcharov:kalin/rag-attached-past-cap

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Before: a chat with more than 100 attached documents (one test attached 1,500) spent about ten minutes indexing every file, each one past the 100th pushing an earlier one out, and then answered that a document the user had attached "is not attached". After: the chat loads documents up to its limit (100 documents or 10,000 passages, unchanged) and stops, the agent is told the rest are attached but not searched at once and never denies them, asking about one by name loads it, and the bar above the chat tells the user not all their documents are searched at once. Past the limit, the first-attached documents are the ones searched, where before the last-loaded ones were.

Closes #7446

Test plan

  • New tests at 150 documents (real index, fake vectors): the Agent UI, the flagship and a relayed flagship each load 100 with no eviction and report the 50 not loaded; asking for document 150 by name loads it, evicting one other and never the one asked for; a search reports the 50 it could not reach and tells the model never to call them unattached. All fail on main, pass here.
  • Document bar: new tests for the notice in English and Arabic and none at 100; a new test:rtl scene in both languages (browser preview), screenshots read. It caught the bar running under the docked session panel in Arabic, fixed here.
  • New test: a passage cap of 40 stops loading at 40 with no eviction and names both limits; the bar shows the notice for nine long books too
  • Affected Python tests pass (hub flagship suite: only the browser-tool registry tests fail, from a machine missing the browser extra); web UI tests and tsc pass; the document, citation and attachment test:rtl scenes pass (the full suite timed out on a loaded machine, so CI's run is the full check)
  • Checked on Gemma 4 in the app
🔍 Technical details
  • RAGSDK.is_full(): at the file or chunk cap. Checked before each attach-time index in _index_rag_with_progress, the non-streaming cache hit, ChatAgent._index_documents, the session-restore loop and the relayed flagship's _index_attached_documents.
  • Agents now carry attached_documents (the chat's whole list). attached_not_loaded is that list minus what the index holds or is still indexing. The per-turn [Indexed documents] context adds a not-searched line with the count and up to 30 names; query_documents adds attached_not_searched and the same instruction; query_specific_file resolves a name among them before looking on disk.
  • _forget_evicted now runs on every attach-time index, so an evicted document is no longer marked indexed forever.
  • The document bar's width: 100% ignored the docked panel's margin-inline-end, so in Arabic the new notice was cut off under the panel; the bar now takes its width from the layout.
  • SEARCHED_AT_ONCE in the web UI is pinned to RAGConfig.max_indexed_files by a Python drift test.
  • Changes what the model reads each turn and from query_documents / query_specific_file. Eval categories to watch: rag_quality, real_world, captured (the retrieval lane) and context_retention.

A chat with more than 100 attached documents spent minutes indexing every
one, each past the 100th pushing an earlier one out of the index, and then
answered that a document the user had attached "is not attached". Now the
chat loads the first 100 and stops, tells the model the rest are attached
but not searched at once, loads one when it is asked about by name, and the
bar above the chat tells the user that only 100 are searched at once.

Every attach path (Agent UI new and cached agents, the flagship's own
loading, a relayed flagship) checks the new RAGSDK.is_full() before indexing
another document. query_documents reports how many attached documents it
could not reach; query_specific_file resolves a name among them and loads
it, evicting one other document. Indexing that does evict now drops the
evicted document's stale "indexed" mark so it can be loaded again. The bar
above the chat no longer runs under a docked session panel.

Closes amd#7446
@github-actions github-actions Bot added documentation Documentation changes rag RAG system changes tests Test changes electron Electron app changes performance Performance-critical changes agents labels Nov 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

This PR fixes a chat with more than 100 attached documents. It stops loading at the cap instead of spending minutes pushing out earlier documents, and it tells the model that the rest are attached and load when asked for by name. The approach is sound and well tested at 150 documents. Two things need fixing before merge:

  • The index also fills on size, not just on count, and that case is misreported. A handful of large PDFs (roughly 9 books of ~200 pages) reach the index's total-size limit long before 100 files. The new check stops loading there too, but the model is told "a chat searches at most 100 documents at once", and the bar above the chat shows no notice because it only appears past 100 files. The user attached 10 files, only 9 are searched, and nothing on screen says so. Either stop early only on the file cap, or word both messages so they don't promise 100.
  • The agent's published docs still say every attached file is indexed before the turn. The changelog was updated, but the README, SPEC and SKILL for the flagship package all still say the agent indexes every file in documents before the turn runs. Per the project's doc-sync rule, all three need the new "first 100, the rest load on request" behaviour.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on static review and on the PR's own test plan. That plan reports test:rtl screenshots that were read but doesn't embed them, and the Gemma 4 in-app check is still unchecked.

🔍 Technical details

🟡 is_full() trips on the chunk cap but every message names the file cap (src/gaia/rag/sdk.py:3991, src/gaia/agents/tools/rag_tools.py:311, src/gaia/ui/_chat_helpers.py:1761, hub/agents/gaia/python/gaia_agent/server.py:903)

  • is_full() returns True at max_total_chunks (10,000). With chunk_size=500, the guide's own example of a 229-page PDF is ~1,180 chunks, so about 9 such files fill the index.
  • Every new early stop (_index_rag_with_progress, _get_chat_response, the stream cache-hit path, ChatAgent._index_documents, _index_attached_documents) then leaves the rest unloaded.
  • not_loaded_note, the SSE headline and the relay summary all say "at most {max_indexed_files} documents at once". The model will tell the user "only 100 are searched" when 9 were.
  • SessionDocsBar only shows the notice at readableCount > SEARCHED_AT_ONCE, so this case has no UI signal at all.
  • This also changes behaviour on main for large-document chats: the last-attached files used to stay resident, now the first-attached do.
  • Options:
    • Check only the file cap for the early stop (0 < max_indexed_files <= len(indexed_files)) and let chunk-cap eviction behave as before.
    • Or keep both caps and word the note by which cap was hit, e.g. "the index is full".
  • Add a test with a small max_total_chunks either way.

🟡 Doc drift: README / SPEC / SKILL still promise every attached file is indexed (hub/agents/gaia/npm/README.md:201, hub/agents/gaia/npm/SPEC.md:320, hub/agents/gaia/npm/SKILL.md:280)

  • Each says the agent "indexes any it has not read yet before the turn runs". Past the cap that is now false, and only CHANGELOG.md says so.
  • Add one sentence to each: past 100 (the index cap), the rest are granted, named in index_documents as not loaded, and load when the model asks for one by name.

🟢 The early stop ignores documents still indexing in the background (src/gaia/rag/sdk.py:3991)

  • is_full() counts only indexed_files/chunks. attached_not_loaded treats documents_still_indexing as held, but they don't count toward fullness, so a chat with background jobs in flight can still overshoot and evict.
  • This is minor, and likely fine to leave if background indexing never overlaps attach-time indexing.

Strengths

  • The tests use a real index with fake vectors across all three surfaces (Agent UI, in-process flagship, relayed flagship), and they assert no eviction, the requested document loading, and the grant for unloaded files. That checks real behaviour, not mock calls.
  • _forget_evicted now runs on every attach-time index, which also fixes an evicted document staying marked indexed forever.
  • The drift test pinning SEARCHED_AT_ONCE to RAGConfig.max_indexed_files and the RTL scene that caught the bar running under the docked panel follow the UI-review rules well.

@kovtcharov-amd kovtcharov-amd added the bug Something isn't working label Nov 13, 2026
A few long documents fill the index on passages long before 100 files, and the chat then said "at most 100 documents" while the bar above it said nothing. Every message now names both limits, the bar also appears when the chat's passages pass 10,000, and the flagship's README, SPEC, SKILL and API description say what happens past the limit. Test fakes gain is_full.
They drive the Agent UI loader, which the RAG lane installs without.
kovtcharov and others added 10 commits November 13, 2026 06:31
# Conflicts:
#	hub/agents/gaia/npm/CHANGELOG.md
Both sides added changelog entries; both are kept.
rtl.visual.ts keeps the PR's past-cap scene and main's cited-documents scene; CHANGELOG keeps both entries.
# Conflicts:
#	hub/agents/gaia/npm/README.md
#	hub/agents/gaia/npm/SKILL.md
#	hub/agents/gaia/npm/SPEC.md
#	hub/agents/gaia/python/gaia_agent/server.py
#	hub/agents/gaia/python/openapi.gaia.json
#	tests/unit/test_relay_flagship_documents.py
A few long documents fill the index on passages long before 100 files, and the chat then told the model and the user about both limits at once while the bar above the chat guessed from the total. Each message now names the one limit reached: the model note, the Agent UI indexing step, the relayed flagship's index_documents step, and the bar, which walks the documents in the order they load. A long document that pushes one out to fit marks the index full, so loading stops there instead of pushing another out on every later turn, and the one pushed out is counted as not loaded.
When the last attached document was the one that pushed an earlier one out to fit, no later pass saw the index full: the Agent UI step said every document was indexed with no note, and the relayed flagship listed all of them as loaded. Both now work out what is not loaded after the loop, name those documents in the step, and mark the one pushed out.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 14, 2026
Merged via the queue into amd:main with commit e5265a8 Nov 14, 2026
106 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/rag-attached-past-cap branch November 14, 2026 10:31
grtninja pushed a commit to grtninja/gaia that referenced this pull request Nov 14, 2026
## Summary

A Stop that lands just after an indexing load pushes a document out now
reports that document as pushed out, keeps it out of the never-attempted
stop count, and, when the index is full, stops promising it will load
next turn. The Agent UI and the sidecar relay use the same accounting;
the Agent UI explains the full-index limit once.

## Why

Stopping indexing on a turn that evicted a document showed the document
as loaded and promised the rest would load next turn. The index was
full, so those documents could not load until the agent was asked about
one by name. The model was already told the truth; only the step the
user sees was wrong. This is most likely when loading is slow, which is
when users press Stop. Follow-up to amd#8068.

## Linked issue

Closes amd#8207

## Changes

- Agent UI (`src/gaia/ui/_chat_helpers.py`): on a stopped pass where a
load evicted a document, compute the missed documents only from the
loads attempted before the stop. The pushed-out document is named and
marked in the step, while the stop count still covers only the documents
never attempted. The full-index explanation is added once: the stop
sentence omits it when the pushed-out document summary already carries
it.
- Relay (`hub/agents/gaia/python/gaia_agent/server.py`): apply the same
accounting using the position recorded at cancellation. When the index
is full, rewrite the stop line with `index_limit` so it says the
documents load only when asked about by name. The pushed-out document
stays granted, so `query_specific_file` can still load it by name.
- Tests (`tests/unit/chat/ui/test_attached_past_cap.py`): one regression
per loop. Both use four 10-passage books in a 25-passage index and set
cancellation on the eviction result, so the third load pushes out
`book_0.txt` while `book_3.txt` is never attempted. The Agent UI
regression also asserts that the 25-passage explanation appears exactly
once.

## Test plan

- [x] `PYTHONPATH=src:hub/agents/gaia/python python -m pytest -q
tests/unit/chat/ui/test_attached_past_cap.py -k
'stop_right_after_a_push_out'`: 2 passed in 0.68s after the wording
cleanup.
- [x] `PYTHONPATH=src:hub/agents/gaia/python python -m pytest -q
tests/unit/chat/ui/test_attached_past_cap.py`: 17 passed in 2.73s after
the wording cleanup.
- [x] `ruff check src/gaia/ui/_chat_helpers.py
tests/unit/chat/ui/test_attached_past_cap.py`: all checks passed after
the wording cleanup.
- [x] Wider focused run over the attachment, indexing, and relay suites,
including `tests/unit/test_relay_flagship_documents.py`,
`hub/agents/gaia/python/tests/test_server_documents.py`, and
`tests/unit/chat/ui/test_index_progress.py`: 175 passed in 35.55s before
the wording cleanup.
- [x] `python util/lint.py --all` with `PYTHONPATH` at the worktree: all
checks pass except two pre-existing Pylint E1120 errors in untouched
`src/gaia/utils/awake_clock.py:47` and `src/gaia/utils/terminal.py:109`.
This run was before the wording cleanup; the follow-up `ruff check`
above covers both touched files. Black, isort, flake8, Bandit, and
Pylint on the three changed files were clean; the tool-description check
passes all 118 schemas.
- [ ] Full `pytest tests/unit/` was not run locally; CI runs it.
- [ ] Reviewer: in the Agent UI, attach four long books, stop as the
third loads, and confirm `book_0.txt` is reported as pushed out, the
25-passage explanation appears once, and the step no longer promises
next-turn loading.

## Evidence

- [ ] **Agent exposed in the Agent UI** (Chat, Email, …): no live
browser session was run in this environment, so there is no screenshot.
The step output is asserted by
`test_a_stop_right_after_a_push_out_reports_the_pushed_out_document`:
the step reads `Stopped: 1 of 4 document(s) not loaded. 1 more not
loaded: the attached documents are long, and the search index holds at
most 25 passages at once. Not loaded: book_0.txt. Ask about one of them
by name to search it.` The 25-passage explanation appears once. The old
line promised next-turn loading and omitted the pushed-out marker.
- [ ] **MCP tools / servers**: N/A. No MCP surface changed.
- [ ] **CLI**: N/A. No CLI command changed.
- [ ] **HTTP API / REST**: N/A for live evidence. The relay path is
reached through `/query`, but no live request was run; the regression
calls `_index_attached_documents` directly with the real RAG index and
asserts the stop line, the marked document, and the retained path grant.

## Checklist

- [x] I have linked a GitHub issue above (`Closes #N` / `Fixes #N` /
`Refs #N`).
- [x] I have described **why** this change is being made, not just what
changed.
- [ ] I have run linting and tests locally (`python util/lint.py --all`,
`pytest tests/unit/`). Linting was run with two pre-existing Pylint
errors outside this diff; focused pytest suites passed, but the full
`tests/unit/` suite was not run locally.
- [ ] I have attached **real-world evidence matched to the surface I
changed** (see Evidence above), or marked each surface N/A. The Agent UI
surface is applicable but no live browser screenshot was captured; the
other surfaces are N/A.
- [ ] I have updated documentation if user-visible behavior changed (see
[CONTRIBUTING.md](../CONTRIBUTING.md)). No docs update was needed: no
documentation describes this indexing-step wording.

---------

Signed-off-by: Niladri Das <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents bug Something isn't working documentation Documentation changes electron Electron app changes p2 low priority performance Performance-critical changes rag RAG system changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A chat with more than 100 attached documents silently searches only the last 100

2 participants