Repository navigation
fix(rag): re-index an edited file before a file-scoped query - #6936
Closed
github-actions[bot] wants to merge 1 commit into
Closed
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
A question scoped to one document searched its index without checking whether the file had changed, so an edited document kept answering with its old text on every file-scoped query. query_specific_file now runs the same is_current check index_document does and re-indexes within the same foreground budget, returning the still-indexing status for a big file. Closes #6932
5 tasks
Collaborator
|
Closing: #6947 covers this file-scoped fix and the other two search paths. |
kovtcharov
pushed a commit
to kovtcharov/gaia
that referenced
this pull request
Nov 7, 2026
…md#6947) If you edited a document after indexing it, document search kept answering from the old text, across the whole library and for a single file, until something re-indexed it. Now each search checks the files it covers and re-indexes any edited file before answering. If a file can't be served up to date, the search leaves it out and says why, with the same fix-it advice the index tool gives (embedder down, document cache locked). It never quietly serves the old text. Closes amd#6939, closes amd#6932 Builds on @rezamuliawijaya's work: amd#6937 (the file-scoped re-index, the kept error advice, and the same-size end-to-end test) and amd#6942 (checking the file's stat before hashing it). ## Test plan - [ ] `python -m pytest tests/unit/rag/test_query_staleness.py tests/unit/rag/test_edited_document_reindex.py`. The bug-reproduction tests fail on `main` for the library-wide, file-scoped and exact-text searches, and pass here. - [ ] In `gaia chat`, index a text file and ask about it. Edit the file, ask again, and the answer reflects the edit with no re-index request. - [ ] Ask the same question twice about an unchanged file. The second answer comes back as fast as the first and nothing re-embeds. - [ ] Delete an indexed file and ask about it. The agent says the file no longer exists instead of quoting it. - [ ] Eval: this changes the tool results the model sees (new `files_left_out` field, `in_progress` / `error` for stale files). Tool docstrings are unchanged. Re-run `rag_quality` and `gaia_rag` on the next RC. <details> <summary>🔍 Technical details</summary> - **Cheap check:** `RAGSDK.freshness(path)` returns `current` / `changed` / `missing` / `locked` / `unreadable` / `not_indexed`. It uses a stat recorded at index time (size, mtime, inode, plus ctime on POSIX) and hashes only when that stat changed, or when the file was written within 2 s of being recorded. The 2 s rule covers the same-tick rewrite that would otherwise fool the stat. Limitation: on Windows, which has no change time, an edit that restores both size and mtime more than 2 s after indexing passes the stat check. An explicit `index_document` still catches it, because that path always hashes. - **No global lock during the re-embed:** `index_document` on an edited file no longer goes through `reindex_document`. It builds the new generation outside `_state_lock` and swaps it in through the existing `_drop_other_generation` publish step. The old text keeps serving until the swap and stays if the re-index fails. A test probes the lock from another thread mid-embed. `reindex_document` itself (the file-watcher path) still holds the lock, so amd#6911 stays open for that path. - **Budget:** edited files re-index through `_index_within_budget` and share one 30 s deadline (`QUERY_REINDEX_BUDGET_S`) across the set. - **What the model sees:** - A file-scoped search on a file still re-indexing returns `in_progress`. - A failed re-index returns the index tool's own result: `_index_embedding_error` (with `next_step`) or `_index_cache_error` (with `hint`), or otherwise an `error` naming the cause. - A deleted or locked file returns `error`. - Library-wide searches drop that file's chunks by owner (vector hits through `_search_chunks`' indices, keyword hits and the small-index "whole index" path through `chunk_to_file`). An unchanged file with an identical chunk keeps it and is cited as the source. The skipped file is listed in `files_left_out` (including any `error_type` and next step) and named in the instruction. If every file is left out, the search returns `error` / `in_progress`. - **Adversarial tests:** - An unchanged file is never re-embedded, whether recently written or aged. - An aged unchanged file is never even hashed. - A touched but unchanged file is hashed once, then trusted. - Deleted, locked and failed re-index files are not served. - A failed re-index keeps the embedder or cache-lock advice. - A twin chunk in an unchanged file survives its left-out copy. - A slow re-index returns `in_progress` within the deadline. - **Overlap:** besides amd#6937 and amd#6942, amd#6917 (lock-free re-index) and the amd#6936 autofix cover parts of this. This PR covers all three search paths in one change. - **Regression run:** the RAG suites (`tests/unit/rag`, `tests/test_rag.py`, the RAG tool, resolution, status, citation, cache and library tests, `test_chat_reindex_locked.py`) pass with a temp HOME after merging `main`. The earlier broad run also covered `tests/unit/agents`, `tests/unit/chat/ui` and `hub/agents/gaia/python/tests`. In that long combined run, some logging and slot tests failed depending on test order. All 312 pass when their files run alone. Black, isort and flake8 (repo settings) are clean on the changed files. </details> Co-authored-by: rezamuliawijaya <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Asking about one specific document used to answer from the version GAIA indexed first. If you edited the file afterwards, every later question about it still got the old text, and nothing ever re-indexed it. Now the single-file question checks whether the file changed, the same check the index tool already makes. If it did, GAIA re-indexes it before answering. A large file that can't finish inside the usual indexing time reports "still indexing" instead of giving an old answer.
This is the fourth option from the issue thread, which still needs a product sign-off, so the PR is a draft until a maintainer confirms the direction.
Closes #6932
Test plan
python -m pytest tests/unit/rag/test_edited_document_reindex.pypasses, and the new edited-file test fails without the fixpython util/lint.py --allpassespython -m pytest tests/unit/in CI. Locally, only the RAG and indexing subset could run: 1,861 passed, and the 2 failures arepython-pptxmissing from this environment, which fail the same way without this changegaia chat, index a text file, ask about it by name, edit a fact in the file, ask again by name. The answer reflects the editrag_qualityeval category on the next RC🔍 Technical details
query_specific_fileresolved the target and calledrag._retrieve_chunks_from_filewithout comparing the file's content key to the one it was indexed from.src/gaia/agents/tools/rag_tools.py): once the target is resolved, if the file exists andrag.is_current()is false, the tool re-indexes through_index_within_budget._indexing_in_progresswhen the budget runs out.realpath, so a symlinked directory can't create a second index entry that would make the lookup ambiguous.