Skip to content

fix(tools): on macOS, default file search skips the folders macOS guards with a prompt - #5599

Merged
kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:kalin/fix-5578-search-skips-macos-protected
Oct 23, 2026
Merged

kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:kalin/fix-5578-search-skips-macos-protected

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

On a Mac, asking GAIA about a document could freeze the turn behind a macOS privacy dialog. The default file search walks ~/Documents, ~/Desktop and ~/Downloads; the first read made macOS ask "GAIA would like to access files in your Documents folder" and block until someone answered, so the tool hung 180 s, the agent retried, and the UI said only "Model is processing". An undirected search on macOS now skips those folders (and iCloud Drive) and says so in one line, so the model can ask the user to name the folder. A folder the user names, or one inside the chat's allowed paths, is still searched; other platforms are unchanged.

Found testing v0.25.1-rc5 on macOS (tccd: AUTHREQ_PROMPTING … kTCCServiceSystemPolicyDocumentsFolder). Fixes #5578.

LLM-affecting (tool output text changes). Eval categories to watch on the next RC: tool_selection, error_recovery, gaia_files, gaia_honesty.

Test plan

  • pytest tests/unit/test_search_skips_macos_protected_folders.py tests/unit/test_file_search_scope.py: 62 passed; 9 of the 14 new tests fail on main (the other 5 guard explicit scopes, allowed paths and Linux).
  • File-tool suites: 522 passed; the one failure (test_persisted_grants_are_not_unioned_into_a_host_scope) fails the same way on main.
  • gaia eval agent on the categories above (next RC).
  • On a fresh macOS install, ask about a document by name and check no Documents-folder prompt appears.
🔍 Technical details

The rule lives in a new src/gaia/agents/tools/protected_folders.py; find_files (smart/home/cwd/everywhere), search_file (incl. deep search) and search_directory gain small guard calls, to keep overlap with #5565 small. A 20 s search budget (#5565) can't interrupt a read blocked in the kernel on the prompt, so both are needed. ~ and / don't count as granting the folders, since the flagship's default sandbox is ~. list_recent_files is unchanged: its job is to list those folders, and its argument names them.

…rds with a prompt

On a Mac, an undirected file search no longer freezes the turn behind a
"GAIA would like to access files in your Documents folder" dialog the user
may never see. The default scopes walked ~/Documents, ~/Desktop and
~/Downloads, macOS blocked the first read until someone answered, and the
tool sat until its 180 s timeout, then the agent retried the same search.

- find_files (smart, home, cwd, everywhere), search_file (including deep
  search) and search_directory now skip Desktop, Documents, Downloads and
  iCloud Drive (~/Library/Mobile Documents) on macOS, unless the user named
  that folder as the scope or it is inside the chat's allowed paths. Home
  and / grant nothing, since the flagship's default sandbox is ~.
- When folders are skipped the result says so in one line, so the model
  can ask the user to name the folder.
- A time budget cannot help here: the read blocks inside the kernel on the
  prompt, so the walk must not start it. Other platforms are unchanged.

Changes tool output the model sees. Eval categories to watch on the next
RC: tool_selection, error_recovery, gaia_files, gaia_honesty.

Fixes amd#5578
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agents labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

On macOS, an open-ended file search no longer walks into Desktop, Documents, Downloads or iCloud Drive, so the turn can't freeze behind the macOS "GAIA would like to access your Documents folder" prompt. The result now says which folders it skipped so the model can ask the user to name one. The guard is applied at every point the three search tools descend into a folder, a folder the user names or allows is still searched, and other platforms behave exactly as before. Nothing blocks the merge.

Worth knowing before the macOS check:

  • The recent-files tool can still trigger the prompt. Its default reads all three folders, and the model calls it for questions like "what was I working on?". The PR leaves it alone on purpose, since listing those folders is its job. But a cold-start Mac can still hang there, so the unchecked "fresh macOS install" item should try it too, or a follow-up should track it.
  • Naming ~ doesn't unlock the folders. A search the user points at their whole home folder still skips them. The docs say so and the skip note explains it, so this is a deliberate choice, not a bug.

Real-world evidence

N/A: no evidence bundle was produced, and the change only does anything on macOS, which this Linux runner can't exercise. The verdict rests on static review alone. I couldn't run the new tests here either (pytest isn't installed on this runner), so the pass counts are the author's. The macOS golden-path check and the eval categories named in the PR are still open.

🔍 Technical details

Issues

🟢 list_recent_files (src/gaia/agents/tools/file_tools.py:2932) defaults to location="all", which scans ~/Documents, ~/Downloads and ~/Desktop with no folder named by the user. That is the same cold-start hang this PR fixes in the search tools. Excluding it is defensible, but please cover it in the manual macOS test item or a follow-up issue. agents/base/discovery.py also probes ~/Documents/* and is worth a look in the same follow-up.

🟢 ProtectedFolders.blocks matches on exact Path equality against both the unresolved and the resolved home/<folder>. That works because every walker builds child paths from a root that is already resolved (or from Path.home()). A future caller passing a differently-normalised path (trailing .., an unresolved symlinked home) would miss silently. A one-line docstring note that callers must pass paths derived from resolved roots would protect the invariant.

Checked and fine

  • search_file rebinds guard with named=[scope] before the explicit-directory walk. with_truncation closes over the name, so it sees the rebound guard.
  • find_files with a path scope passes the validated scope_root. The keyword scopes (smart, home, cwd, everywhere) pass named=[]. everywhere is still guarded on the way down from /, because _search_names and _search_contents both check guard.blocks(entry.path) before recursing.
  • When the cwd is inside a guarded folder (e.g. ~/Documents/proj), only the parent is guarded. The project root itself is still walked.
  • The index fast path doesn't read the folders on disk, so leaving it unguarded is correct.

Strengths

  • The guard sits at the point each walker descends, rather than filtering results afterwards, so the walk never even lists a guarded folder. The os.scandir and Path.iterdir spy tests prove this directly.
  • The skip note is a single actionable line, and it is attached on both hits and misses, so a zero result isn't presented as a complete answer.
  • The tests patch the platform and use a temp home, so they run on Linux CI and can't touch the real home folder. The Linux tests pin that other platforms are unchanged.

…ved paths

A caller passing an unresolved path would miss a guarded folder silently, so the guard's docstring now says paths must come from a resolved root.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

Took the docstring note: the guard now says it matches exact paths built from a resolved root. The recent-files prompt risk is left for a follow-up, since listing those folders is that tool's job.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 23, 2026
Merged via the queue into amd:main with commit 3f690f4 Oct 23, 2026
36 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/fix-5578-search-skips-macos-protected branch October 23, 2026 07:13
kovtcharov-amd pushed a commit to kovtcharov/gaia that referenced this pull request Oct 23, 2026
)

On a Mac, an open-ended file search could freeze a chat in `~/Music`.
macOS guards that folder behind its "Media & Apple Music" prompt, and
the first read blocks until someone answers. amd#5599 made searches skip
Desktop, Documents, Downloads and iCloud Drive, but not Music. On rc6
that left a chat stuck on "Finding files" for over two minutes. Music,
the TV app's library (`~/Movies/TV`, behind the same prompt) and the
Photos library (guarded by the "Photos" prompt) are now skipped too,
unless the user names them or the chat allows them, and the result says
which folders were skipped. A whole-disk search now skips them too: it
used to reach them through macOS's `/System/Volumes/Data` path, which
the guard didn't recognise.

Fixes amd#5669

## Test plan
- [x] `pytest tests/unit/test_search_skips_macos_protected_folders.py`:
14 pass. With the two folders added to the test's guarded list, 3 failed
before the fix: an undirected search, a deep search and the skip note
all walked into them.
- [x] Reproduced on rc6, macOS 26.5.1: the sidecar's search thread was
blocked in `opendir` on `~/Music`.
- [x] Retested on rc6 plus the open fixes: a home-wide `find_files`
still hit the 180 s timeout, this time blocked on `~/Movies/TV`. With it
skipped, a walk of the same home finishes in about 8 s.
- [x] A whole-disk search (scope `everywhere`) reached `~/Music` again
as `/System/Volumes/Data/Users/<u>/Music` and hung. The guard now
matches by inode as well; the same search answers in 28 s and names the
skipped folders.
- [ ] On a Mac that has never granted media-library access, ask GAIA to
find a file without naming a folder. It answers without a prompt, and
the result names `~/Music` as skipped.

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
philippeback pushed a commit to philippeback/gaia that referenced this pull request Oct 24, 2026
…reezing (amd#5709)

On a fresh Mac, asking GAIA "what was I working on?" froze the turn
behind macOS's "GAIA would like to access files in your Documents
folder" dialog until the tool timed out. The first read of a guarded
folder blocks in the kernel until someone answers. Now GAIA opens each
guarded folder on a background thread first. All probes share one
2-second deadline. A read still held after it means the dialog is up:
that folder is reported as waiting, with a line telling the user to
answer the dialog and ask again, and the other folders are listed
meanwhile. A folder the user answered "Don't Allow" for is reported as
denied, with where in System Settings to turn access on, instead of as
searched with nothing in it. On a Mac that has already granted access,
nothing changes, and the probe costs about 0.1 ms per folder.

Closes amd#5607. Builds on amd#5599, which made undirected searches skip these
folders. This tool can't skip them, because listing them is its job.

## Test plan
- [x] `pytest tests/unit/test_recent_files_waits_on_macos.py` (11 tests,
platform patched, temp home):
  - a held read counts as pending and clears once answered;
  - asking again while the dialog is open reuses the waiting probe;
  - only guarded folders are probed, and nothing is probed off macOS;
  - the other folders are listed while one waits;
  - all folders waiting is a not-executed error that says what to do;
  - three held folders cost one shared wait, not three;
  - a denied folder is reported with where to allow it;
  - a folder outside the sandbox is never probed.
  The two tool-level tests fail without the fix.
- [x] `test_search_skips_macos_protected_folders.py`,
`test_file_tools.py`, `test_file_tools_allowed_folders.py`,
`test_file_search_scope.py` (297 passed)
- [x] On this Mac (access already granted): each probe takes 0.1–0.2 ms,
and `list_recent_files(days=7)` returns the same 2 files in 0.01 s
- [x] black, isort, pylint (errors only)
- [ ] On a Mac that hasn't granted GAIA folder access: ask "What files
have I changed recently?" The answer names the folder macOS is asking
about within a few seconds, instead of hanging.

---------

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 documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(tools): on macOS, find_files' default scope triggers a hidden Documents-folder prompt and hangs 180 s

2 participants