Repository navigation
fix(gaia): start code search in a folder the chat can reach - #4647
Conversation
…'s docs dir With no project root, the flagship started code search at allowed_paths[0]. An Agent UI session's scope is sorted and holds GAIA's managed documents folder (often not created yet) ahead of the working directory, so every search_code_index failed with "repo_path does not exist: ~/.gaia/documents". It now starts in a repository in scope, else the first folder in scope that exists; the scope itself (the ceiling) is unchanged.
|
Verdict: Approve Code search in an Agent UI chat that isn't inside a project failed every time, because it started in GAIA's own documents folder, which usually doesn't exist yet. The fix is small and correct. Code search now starts in a repository the chat can reach. If there isn't one, it starts in the first folder in reach that exists. How far it can reach is unchanged. The two new tests cover both cases, and the gaia agent's CHANGELOG has an entry. I found nothing blocking. The one point worth knowing is below; it isn't a regression. Real-world evidenceN/A: no evidence bundle was produced for this run. The PR links backend log lines from eval run 37110051697 that show the failure before the fix, but nothing yet shows a successful search from a non-repo folder. That item and the eval re-score are still unchecked in the test plan. For the live path, this verdict rests on static review and the PR's unit tests. pytest isn't installed on this runner, so I couldn't re-run them here. 🔍 Technical detailsIssues found 🟢 The fallback is the first existing folder in sort order, not the working directory (
Strengths
|
… (amd#4661) Every PR's Linux unit test run has been failing on main since amd#4647, unrelated to what the PR actually changes. amd#4647 changed the flagship's `index_root` fallback from `allowed[0]` to `_code_search_start(allowed)`, but the AST-pinned regression test in `test_project_map.py` still asserted the old expression. The test is a deliberate pin against drift between the agent and its test double, so it broke the moment the real code moved. ## Test plan - [x] `pytest tests/unit/test_project_map.py` (87 passed) - [x] `python util/lint.py --black --isort`
…4663) The required `Unit Tests (Linux, py3.12)` check fails on `main` for every PR. amd#4647 changed where the flagship starts code search, but the test that pins that choice still expected the old rule. This brings the test in line with the agent, and adds a case for the bug amd#4647 actually fixed: the first allowed path doesn't exist yet. Closes amd#4660 ## Test plan - [x] `python -m pytest tests/unit/test_project_map.py` passes (88 passed) - [x] `python util/lint.py --all` passes - [ ] `Unit Tests (Linux, py3.12)` is green on this PR <details> <summary>🔍 Technical details</summary> - The pinned expression is now `self._project_map_root() or _code_search_start(allowed)`. - `_IndexRootAgent` calls the flagship's real `_code_search_start`. The test pulls that one function out of `agent.py` with `ast` and compiles it, so it doesn't have to import `GaiaAgent`, which the file avoids because of the editable-install problem. That way the stand-in can't drift from the helper's logic. - New test `test_the_index_skips_an_allowed_path_that_does_not_exist`: `allowed[0]` is missing and `allowed[1]` exists. It fails under the old `allowed[0]` rule and passes under the new one. - The full `tests/unit/` suite couldn't finish in this job (missing optional test deps such as `responses`, and a time limit). The change only touches this test file. </details> Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
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]>
In an Agent UI chat that isn't inside a project,
search_code_indexfailed every time with "repo_path does not exist: ~/.gaia/documents". With no project root, the flagship started code search at the first entry of the chat's allowed paths. That list is sorted, and GAIA's own documents folder sorts first even though it usually doesn't exist yet. Code search now starts in a repository the chat can reach, or else the first folder it can reach that exists. How far code search may reach is unchanged.Evidence from run 37110051697:
code_index_and_find,code_find_class_method,task_coding_mini_repo: backend logError executing tool search_code_index: repo_path does not exist: C:\Users\Administrator\.gaia\documents(3×, gaia-code and gaia-tasks lanes).🔍 Technical details
_compute_allowed_pathsreturnssorted({attached files…, managed documents dir, cwd}). InC:\Users\X\.gaia\documentsvsC:\Users\X\proj,.(0x2E) sorts before letters, so the managed folder wasallowed[0]on Windows and macOS alike._code_search_start(allowed)picks the first folder in scope that is a repository (is_code_repository), else the first one that exists, elseallowed[0]as before. That last case leaves the "does not exist" error in place, and it is accurate there. Attached document files are no longer candidates either.allowed_paths(fix(code-index): only one repository can be indexed per agent session #3544).hub/agents/gaia/npm/CHANGELOG.mdhas a Fixed entry.Test plan
pytest tests/unit/test_flagship_code_index_scope.py. Both new tests fail on main.gaia_codeandgaia_skills_tasks.