Skip to content

fix(gaia): start code search in a folder the chat can reach - #4647

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/code-search-start-in-a-folder
Oct 4, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/code-search-start-in-a-folder

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

In an Agent UI chat that isn't inside a project, search_code_index failed 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 log Error 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_paths returns sorted({attached files…, managed documents dir, cwd}). In C:\Users\X\.gaia\documents vs C:\Users\X\proj, . (0x2E) sorts before letters, so the managed folder was allowed[0] on Windows and macOS alike.
  • The new _code_search_start(allowed) picks the first folder in scope that is a repository (is_code_repository), else the first one that exists, else allowed[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.
  • The project-map root still takes priority. The ceilings stay allowed_paths (fix(code-index): only one repository can be indexed per agent session #3544).
  • hub/agents/gaia/npm/CHANGELOG.md has a Fixed entry.

Test plan

  • pytest tests/unit/test_flagship_code_index_scope.py. Both new tests fail on main.
  • Agent UI started from a non-repo folder: ask "search the code for X" and check that search runs instead of erroring.
  • Re-score gaia_code and gaia_skills_tasks.

…'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.
@github-actions github-actions Bot added the tests Test changes label Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

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 evidence

N/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 details

Issues found

🟢 The fallback is the first existing folder in sort order, not the working directory (hub/agents/gaia/python/gaia_agent/agent.py:286)

  • If the scope holds both a parent folder and a child with no repo between them (for example the home folder and the folder the session was started in), search starts at the parent. That's the broader tree, so a first index takes longer.
  • This doesn't break anything, since the ceilings are unchanged. If it shows up in evals, a tiebreak that prefers the deepest existing folder would fix it.

Strengths

  • The helper reuses is_code_repository from project_map, so "repository" means the same thing here as it does for the project map. It also keeps the old allowed[0] as the last resort, so where no folder in scope exists the error stays accurate instead of being hidden.
  • It separates where search starts (repo_path) from how far it can reach (ceiling_paths), keeping the fix(code-index): only one repository can be indexed per agent session #3544 behaviour.
  • The first new test builds the real failure shape (a missing managed folder, an attached file, and a working folder, sorted), and the PR says it fails on main.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 4, 2026
Merged via the queue into amd:main with commit 26545d5 Oct 4, 2026
@kovtcharov-amd
kovtcharov-amd deleted the kalin/code-search-start-in-a-folder branch October 4, 2026 09:36
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Oct 4, 2026
… (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`
kovtcharov-amd pushed a commit to kovtcharov/gaia that referenced this pull request Oct 4, 2026
…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>
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Oct 5, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants