Repository navigation
fix(code-index): stop an abandoned index build instead of racing the next one - #4644
Conversation
…next one On a large repository the first search_code_index call builds the index under the default 180 s tool cap, so the agent abandoned it mid-build; the build kept running, and the model's follow-up index_codebase started a second full build on the same embedder that then overran its own 900 s cap. Two TheRock tasks lost 18 of their 30 minutes this way and never got to the fix. search_code_index now gets index_codebase's window, since it runs the same build, and the build checks for cancellation between files and between embedding batches, so an abandoned one stops before it persists anything.
|
Verdict: Approve with suggestions On a large repo, the agent's first code search no longer gets cut off partway through building the index. An index build the agent has given up on now stops before it writes anything, so it can't compete with the next build for the embedder. The fix uses the cancellation mechanism the audio tools already use, and the tests cover both stopping points. Nothing blocks merge. One item from the PR's own test plan is still open: the Real-world evidenceN/A: no evidence bundle was produced for this run. The change is to tool dispatch timing and index-build internals, and real inference runs on the strix-halo lane. The verdict rests on static review plus the unit tests the author reports. The PR names the failing transcripts ( 🔍 Technical detailsIssues found
Verified while reviewing
Strengths
|
|
The second embedding loop now has its own cancellation test. The eval re-run has to come from CI: 🔍 Technical details
|
File tools now all check the same allowed-folders rule. Before, `read_file` and `write_file` checked a path against the session's allowed folders (asking the user when it was outside), but several neighbouring tools did not: folder browsing and directory search, recent files, document and code indexing, folder watching, `list_files`, and the paths screenshots, transcripts, speech and exports are saved to. Now every one goes through the same check and the same approval prompt, so a chat scoped to its documents behaves the same whichever tool the model picks. - **One rule, not a second one.** Tools call the existing `PathValidator.validate_read` / `validate_write` through a thin helper. The validator now expands `~` before resolving symlinks and `..`, so it judges the path the tool actually opens. - **Approving a folder now covers document indexing too.** The chat agent's RAG SDK kept a separate validator, so a folder approved in the chat was still refused at indexing time. It now shares the agent's. - **Wider on purpose, and documented:** name search over the common document folders (it returns paths only, and opening one is checked), GAIA's own output folders, and `capture_skill`, which asks the user on every call. <details> <summary>🔍 Technical details</summary> - Helper: `gaia.agents.tools.path_access` (`read_access_error`, `write_access_error`, `readable_entry`). Folder walks call `readable_entry` per file, which never prompts. - Model-visible changes: refusal text from these tools is now the validator's standard message, `list_recent_files` reports `locations_not_searched`, and `search_directory` with no root searches the allowed folders instead of the whole home folder. No tool docstrings changed. - Overlap with amd#4642: both PRs add the same `~` expansion to `browse_directory`, `get_file_info`, `analyze_data_file` and `search_file_content`, with identical lines, so either merge order applies cleanly. Merging amd#4642 first is the simplest order. - Nearby open PRs: amd#4613 and amd#4648 (`rag_tools.py`), amd#4644 (`code_index_tools.py`), amd#4626 (`filesystem_tools.py`), and amd#4647 (flagship CHANGELOG). Their hunks don't overlap these, but whichever lands second may need a trivial rebase. </details> ## Test plan - [x] `pytest tests/unit/test_file_tools_allowed_folders.py hub/agents/chat/python/tests/test_chat_file_tools_allowed_folders.py`: 66 tests. For each tool, a path outside the allowed folders (direct, through `..`, and through a symlink) goes through the approval prompt and is refused, and a path inside still works. 41 of them fail on main. The ChatAgent tests live in the chat package, so the chat-agent lane runs them; the core unit lane has no `gaia_agent_chat`. - [x] Existing file, RAG, audio, screenshot, code-index, security and chat-agent unit tests pass. The two local failures (`test_persisted_grants_are_not_unioned_into_a_host_scope`, `test_backups_directory_is_owner_only`) also fail on main on this machine. - [x] black, isort, flake8 and pylint are clean on the changed files. - [ ] Follow-up after the core release that ships `path_access`: raise the chat and flagship `amd-gaia` floors to it, as the chat CHANGELOG records. - [ ] CI eval re-run, since refusal text and the default search scope are model-visible: `gaia_files`, `gaia_core`, `gaia_data`, `tool_selection`. --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
On a large repository, code search used up most of an agent's time budget while producing no results. The first
search_code_indexcall builds the index, but it ran under the default 180 s tool cap, so the agent abandoned it partway through. Python can't kill the thread, so that build kept running. The model then calledindex_codebase, which started a second full build on the same embedder; competing with the first, it overran its own 900 s cap. Now a first search gets the same windowindex_codebasehas, and a build the agent has abandoned stops at its next file or batch, before writing anything.Evidence from run 37110051697 (Qwen3-30B
therocksuite):tr-8319andtr-8319-cb(both TIMEOUT at 1800 s): the first two tool calls in each transcript weresearch_code_index→ "did not return within 180s and was abandoned", thenindex_codebase→ "did not return within 900s and was abandoned". That is 18 of the 30 minutes gone before the model read a file. Judge: "No changes and no answer."🔍 Technical details
search_code_indexis now@tool(timeout=900), matchingindex_codebase, because its lazy path calls the samesdk.index_repository().CodeIndexSDK.index_repositorycallsraise_if_cancelled()before each file is parsed. Both embedding loops (_encode_texts,_encode_texts_with_sync) call it before each batch, outside the per-batchexcept Exceptionthat would otherwise swallow it. This is the cooperative cancellation from fix(agents): abandoned tool-timeout threads leak log records and state into unrelated code #2600 that audio tools already use. Nothing is persisted before_save_atomic, so the previous index is left intact.tr-7998.Test plan
pytest tests/unit/test_code_index_mixin.py tests/unit/test_code_index_sdk.py tests/unit/test_code_index_empty.py tests/unit/test_code_index.py tests/unit/test_flagship_code_index_scope.py. The three new tests fail on main.therocksuite and thegaia_codecategory, and confirm nosearch_code_index … abandonedlines appear in the transcripts.