Skip to content

fix(tools): expand ~ in the data, file-info, browse and grep tools - #4642

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/data-tools-expand-tilde
Oct 4, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/data-tools-expand-tilde

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Asking "what's the total revenue in ~/data/sales.csv?" returned "File not found: ~/data/sales.csv". The agent then either gave up or searched for a similarly named file and analysed that one instead. #4576 fixed ~ for read/write/edit and indexing, but four read-side tools still treated ~/x as a relative path: analyze_data_file, get_file_info, browse_directory and search_file_content. All four now expand ~ before their sandbox check, the same way the #4576 tools do.

Evidence from run 37110051697:

  • data_total_revenue: analyze_data_file("~/gaia-eval/csv/sales.csv") → File not found (backend log). The agent then picked sales_data_2025.csv and answered $340,000 instead of $18,600.
  • data_top_product, data_followup_compound, mcp_builtin_fits_better: the same File not found on the first call, followed by a find_files detour.
🔍 Technical details
  • Each tool previously built Path(file_path) or ran resolve() on the raw string. Path("~/x").resolve() is <cwd>/~/x, so the sandbox check also judged the wrong path.
  • These are tool bodies only. Docstrings and schemas are unchanged.
  • A known gap remains: browse_directory doesn't call _read_access_error at all. It is left as it was here and will be raised separately.

Test plan

  • pytest tests/unit/test_tool_tilde_expansion.py: four new tests, run inside a sandbox scoped to the fake home. They fail on main and pass with this change.
  • Categories to re-score: gaia_data, gaia_tool_selection, gaia_mcp, gaia_skills_tasks, gaia_code.

amd#4576 expanded a leading ~ in the read/write/edit and indexing tools, but
analyze_data_file, get_file_info, browse_directory and search_file_content
still treated "~/sales.csv" as a relative path. "What's the total in
~/data/sales.csv?" answered "File not found: ~/data/sales.csv", or the agent
went searching and analysed a different file with a similar name.

Each now expands at its entry, before the sandbox check, the same way the
amd#4576 tools do.
@github-actions github-actions Bot added tests Test changes agents labels Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve

Four more file tools (data analysis, file info, folder browsing, and text search) now understand ~/... paths instead of reporting "File not found". The fix is small, matches how the earlier read/write tools were fixed, and expands ~ before the sandbox check, so the access check is applied to the real path.

One thing is still open: the eval categories in the test plan haven't been re-scored. Running gaia_data at least would show the agent now answers the ~/gaia-eval/csv/sales.csv question correctly instead of picking a different file.

Real-world evidence

N/A: the evidence stage didn't run for this PR (no evidence bundle). The PR description includes before-state evidence from eval run 37110051697 (File not found on ~/... paths), but no after-state run. This verdict rests on reading the code and the four new unit tests. I couldn't run the tests here because pytest isn't installed in the review environment.

🔍 Technical details

Issues found

  • 🟢 After-state eval still pending. The test-plan item to re-score gaia_data / gaia_tool_selection / gaia_mcp / gaia_skills_tasks / gaia_code is unchecked. This change only touches tool bodies, not prompts or schemas, so CLAUDE.md doesn't require the eval before merge. A gaia_data run is still the direct proof that data_total_revenue now returns $18,600.
  • 🟢 Error text still shows the unexpanded path (file_tools.py:1975, and the same pattern in analyze_data_file's File not found: {file_path}). Showing the raw ~/x is arguably friendlier to the user. Noting it only so a future reader knows it's intentional.

Checked and fine

  • search_file_content (file_tools.py:1065) now expands ~ before _read_access_error. This keeps the sandbox check before the existence probe, so it can't be used to tell whether directories outside the sandbox exist.
  • get_file_info / analyze_data_file pass the expanded fp to _read_access_error(str(fp)), and every later step (exists, _resolve_indexed_basename, _read_tabular_file) uses fp, not the raw string.
  • browse_directory still has no _read_access_error call at all. This PR doesn't change that, and the description says it will be raised separately.

Strengths

  • The tests run inside a PathValidator scoped to the fake home. That covers both the ~ expansion and the sandbox check against the expanded path, so a regression in either would fail.
  • Uses the same expanduser() idiom as the earlier fixes, so all the file tools now handle ~ the same way.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 4, 2026
Merged via the queue into amd:main with commit e7e5ad2 Oct 4, 2026
@kovtcharov-amd
kovtcharov-amd deleted the kalin/data-tools-expand-tilde branch October 4, 2026 09:36
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

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants