Skip to content

fix(tools): recent-files reports the macOS folder dialog instead of freezing - #5709

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/recent-files-macos-prompt
Oct 24, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/recent-files-macos-prompt

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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 #5607. Builds on #5599, which made undirected searches skip these folders. This tool can't skip them, because listing them is its job.

Test plan

  • 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.
  • test_search_skips_macos_protected_folders.py, test_file_tools.py, test_file_tools_allowed_folders.py, test_file_search_scope.py (297 passed)
  • 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
  • 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.

…reezing

On a fresh Mac the first read of ~/Documents blocks behind "GAIA would like
to access files in your Documents folder" until someone answers, so "what
was I working on?" froze the turn until the tool timed out. list_recent_files
can't skip those folders the way an undirected search does, since listing them
is its job. It now opens each guarded folder on a thread first. A read still
held after 2 s means the dialog is up, so that folder is reported as waiting
(locations_waiting_for_macos, with a line telling the user to answer it) and
the other folders are listed. The probe ends on its own once the user answers,
and a probe already waiting is reused.

Closes amd#5607.
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

On a fresh Mac, "what was I working on?" no longer hangs behind the macOS folder-access dialog. GAIA now probes each guarded folder on a background thread. Any folder still blocked after 2 seconds is reported as waiting on the dialog, and the other folders are listed as usual. The approach is sound: no blocking read ever runs on the agent's thread, and asking again reuses the probe that's already waiting, so blocked threads don't pile up. I found no blocking issues.

One thing to know: the only proof so far comes from a Mac that had already granted access. The unchecked test-plan item, a Mac that hasn't granted it yet, is the case this PR exists for, so please run it before merge. The probe is right in principle, but nothing here has exercised the real dialog.

Real-world evidence

N/A: no evidence bundle was produced. The changed surface only behaves differently on macOS, and this CI lane runs on Linux, so none of it could be exercised here. This verdict rests on static review plus the author's own measurements on a Mac that had already granted access. The cold-start dialog case is still unverified. I also couldn't run the new tests in this lane because pytest isn't installed.

🔍 Technical details

Issues

🟢 Worst-case wait adds up across folders (file_tools.py:3157). With location="all" on a fresh Mac, Documents, Downloads and Desktop are probed one after another, so the turn can stall about 6 s before the tool returns. That still beats a hang. Starting all the probes first and joining them against one shared 2 s deadline would cap the stall at about 2 s. Optional.

🟢 "Don't Allow" still counts as searched (file_tools.py:3202, existing behaviour). If the user denies the dialog, the probe ends immediately with an OSError. The rglob then fails inside the except (PermissionError, OSError) block, which only logs at debug level. The folder therefore shows up in locations_searched with zero files. Now that the tool tells users to answer the dialog and ask again, a user who chooses "Don't Allow" will get "nothing changed recently" with no hint why. Consider recording that folder in locations_not_searched with a message pointing them to System Settings → Privacy & Security → Files and Folders.

Strengths

  • Reusing the probe through a per-folder registry under a lock means a dialog left open never accumulates blocked threads. A test pins this down.
  • The probe is narrowly scoped: macOS only, the exact guarded paths only, and scandir only reads the first entry. Everything else pays nothing.
  • When every folder is waiting, the result is a NOT_EXECUTED error that tells the model what to ask the user, not a success with an empty list. That fits the fail-loudly rule.
  • The tests patch the platform and use a temp home, so they run on any OS, and they cover held, cleared, reused, partial and all-waiting cases.

…as denied

All guarded folders are probed at once against one shared 2 s deadline, so a
fresh Mac stalls the turn about 2 s, not 2 s per folder. A folder the user
answered "Don't Allow" for is no longer counted as searched with no files: it
is reported in locations_denied_by_macos, with where to turn access on. A
folder GAIA's own sandbox refuses is never probed, so it can't raise the
macOS dialog.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Both suggestions are done in the latest commit: the folder probes now share one 2-second wait, and a folder the user answered "Don't Allow" for is reported as denied, with where in System Settings to turn access on.

The cold-Mac check in the test plan still needs a Mac that hasn't granted folder access. It's left for manual release testing.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 24, 2026
Merged via the queue into amd:main with commit 03b30ed Oct 24, 2026
32 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/recent-files-macos-prompt branch October 24, 2026 03:20
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.

fix(tools): on macOS, list_recent_files can still hang on the Documents-folder prompt

2 participants