Repository navigation
fix(tools): file search ignores accents and stops within its time budget - #5565
Conversation
Asking for "the resume file" never found "résumé 📄 draft.txt": every name match compared lowercased strings, so the agent widened the search to the whole drive, and one find_files call ran past the 180 s tool timeout. - Name matching in find_files, search_file and the file index folds case and accents (NFKD, drop diacritics, casefold) on both sides, globs included. - find_files' name and content walks and search_file_content share search_file's 20 s / 200k-entry budget; a stopped search returns what it found and names the folders it did not finish. - Junctions and symlinks are no longer walked: DirEntry.is_dir() without following links is True for a Windows junction, so a .cache junction to a model store was crawled.
|
Verdict: Request changes (one small fix) This fixes the two "the agent couldn't find my résumé" problems properly. Name search now ignores accents and case. Every file search stops after 20 s and says which folders it didn't finish, so a miss no longer looks like "nothing there". Searches also stop crawling into junctions and symlinks. The budget, the folding and the junction check each live in one shared helper, and the tests cover them well. One thing to fix before merge: when the file index is on, globs that start with Real-world evidenceN/A: no evidence bundle was produced for this run, and the PR's Agent UI check ("ask for the resume file") is still unchecked. This verdict rests on static review alone. I couldn't run the tests here because pytest isn't installed in the review environment. Before merge, please post the Agent UI run, or the 🔍 Technical details🟡 Index path drops infix matches for leading-wildcard globs ( Suggested gate: Please also add a test to 🟡 No real-world evidence for an agent-visible change 🟢 Strengths
|
|
Merge note: #5554 and #5565 both change the result text of 🔍 Technical detailsResolution tested locally (both test files plus
|
|
Checked live: asking "what languages does morgan speak? its in the resume file with the emoji" now finds 🔍 Technical detailsLive Agent UI build with this branch (and #5554, combined as in the merge note above), relayed sidecar frozen from the same commit, |
With the index on, `*port*` returned port.txt but not report.pdf: the index matches word starts only, and any hit skipped the folder walk. A glob whose word follows a wildcard now goes straight to the walk. The link test also asserted the Windows junction quirk on Linux and macOS, where a symlink never reports as a plain directory; that check now runs on Windows only.
|
Fixed: with the index on, 🔍 Technical detailsIndex fix. I used a narrower gate than the suggested
CI root cause. On Linux and macOS, Résumé case (
#5554 overlap. This PR's own result-text logic is unchanged. The resolution in the earlier comment still applies. Tests run.
Commit: 32fe172 |
…5610) Four timing-sensitive unit tests failed 8 unrelated PRs this week (#5537, #5539, #5562, #5563, #5564, #5565, #5566, #5568) and one of main's last 11 completed runs. Each still guards the same bug, but no longer races the clock on a busy runner. Every rewritten test was checked by breaking the code: it fails on the real bug and passes 50/50 runs, including under full CPU load. The PR also keeps three tests out of the developer's real `~/.gaia`. ## Test plan - [x] `pytest tests/unit/mcp/client/test_stdio_hung_server.py tests/unit/test_file_lock.py tests/unit/test_mcp_bridge_concurrency.py tests/unit/chat/ui/test_agent_model_override.py tests/integration/test_folder_indexing.py -n 4`: 316 passed, 3 skipped - [x] The four de-flaked tests, run 50x each: 250/250 serial, and 250/250 under xdist (32 workers) with all 32 cores also running busy loops. Main's versions in that same loaded run: redaction failed 10/50. - [x] Each test fails when its bug is put back in the code (see details) - [x] `tests/integration/test_folder_indexing.py -n 4`, 5 runs: all pass. Main's version fails 7 to 9 tests per run. - [x] Test 841 passes with `GAIA_HOME` set to a temp dir. Main's version fails. - [x] Electron `npx jest`: 1098 passed. The one failure, `test_electron_chat_installer.js` (component size 103,725 > 102,400), also fails on main and is unrelated. - [ ] CI green on Linux, macOS and Windows unit lanes <details> <summary>🔍 Technical details</summary> **`test_redaction_stays_fast_on_dense_escapes`** (Linux, 2.01 to 2.03 s against a 2 s limit) - Cause: an absolute 2 s bound. Locally the worst text takes 0.19 s. On a 4-worker, coverage-traced runner it took about 10x that. - Fix: time one 1M-char text against eight 125K texts with the same total length, on the same machine. Linear code scores about 1.0 and a quadratic scan scores 8, so the test asserts < 3. It takes the best of up to three paired runs, and uses the lower of the wall-clock and CPU (`thread_time`) ratios. Contention inflates wall time, and Windows samples CPU time on ticks. The test also fails if the 1M text takes more than 15 s of CPU, which catches a per-position rescan: that is linear but takes minutes. - Break checks: a quadratic prefix copy in `_candidate_windows` (`len(text[:start].rstrip("\\"))`) gives a ratio of 5.9x and the test fails. Main's 2 s test passed that same regression locally (1.57 s). A per-anchor rescan without merging takes 56 s and hits the 15 s ceiling. **`test_children_of_an_exited_server_are_still_stopped`** (Linux) - Cause: the test slept a fixed 2 s for the child watcher. The watcher backs off (0.5, 1, 2, 4 s…), so on a slow start its next scan came after the launcher had exited and the child was never recorded. - Fix: poll until `child_pid in transport._children`, with a deadline of 3 × `_CHILD_SCAN_MAX_S`. - Break checks: never recording children fails with "never recorded". Clearing `_children` before stopping fails with "kept running". Delaying the watcher's first scan by 2.5 s reproduces the CI failure on main's test, and the new test passes. - Note for the product side: a launcher that spawns a child and exits inside a backoff window still orphans that child. Real `npx`/`uvx` launchers outlive the window. **`test_the_next_waiter_takes_the_lock_within_milliseconds`** (macOS, median 6.5 to 8.1 ms against 5 ms) - Cause: macOS stretches `sleep(0.001)` under load, and the 5 ms median left no headroom. - Fix: the test wraps `_poll_interval`, which records each interval and signals the moment the waiter starts a poll's sleep. The lock is released right then, so the whole interval stands between the waiter and the lock. - Assertions: every interval the front waiter asks for is ≤ 2 ms, and the median hand-off is < 15 ms. A 20 ms poll always waits at least 20 ms, so it fails the median even with the bound widened. - Break checks: `_NEXT_POLL_SECONDS = 0.02` or `0.1` fails the interval assertion. Sleeping `_POLL_SECONDS` directly, so `_poll_interval` is bypassed, fails the median (20.8 ms). **`test_a_dropped_idle_connection_is_logged[True]`** (Linux) - Cause: the test asserted that `"Traceback"` was absent from the stderr captured by `capsys`. The traceback in that run came from a fake Lemonade server that `test_lemonade_shared_server.py` left running on the same xdist worker (`BrokenPipeError`). - Fix: the `serve` fixture records the bridge server's own `handle_error` calls, and the test asserts that list is empty. socketserver calls `handle_error` before it closes the connection, so the check doesn't race. A plugin that writes a traceback to stderr during the test fails main's version and passes the new one. - Break check: making `log_error` also call the base `log_error`, and reverting `str(args[0])`, raises `TypeError` in the handler, and the test fails. **Isolation fixes** - `test_folder_indexing.py`: `temp_folder` now lives in `isolated_gaia_home`, a per-test fake home, so `ensure_within_home` still admits it. Parallel workers no longer share or delete `~/.gaia/test_temp`. - `test_issue_841…`: the test now sets `GAIA_HOME` itself, so an inherited value can't override the patched `Path.home`. - `tests/electron/setup.js`: `os.homedir()` points at a per-file temp dir. It is assigned rather than spied, so `jest.restoreAllMocks()` can't undo it. Setting `HOME` would not work, because Jest's sandboxed `process.env` never reaches `os.homedir()`. - The "Ignoring invalid agents section in …\.gaia\tray-config.json" log came from `crash-loop-notification.test.cjs`, which mocks `fs` with a config the validator rejects. The real file was never read, but the path now names the temp home. </details>
…rds with a prompt (amd#5599) 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 amd#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 - [x] `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). - [x] 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. <details> <summary>🔍 Technical details</summary> 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 amd#5565 small. A 20 s search budget (amd#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. </details> --------- Co-authored-by: Kalin Ovtcharov <[email protected]>
# Conflicts: # src/gaia/agents/tools/file_tools.py # src/gaia/agents/tools/filesystem_tools.py
|
Merged main in. The conflicts were all with main's new macOS protected-folder guard. Both behaviours are kept: searches still skip the guarded macOS folders, and they still honour the 20 s budget and don't follow links.
Tests: every #5554 is not on main yet, so the combined resolution from the earlier merge note still applies to whichever of the two merges second. |
# Conflicts: # src/gaia/agents/tools/file_tools.py # src/gaia/agents/tools/filesystem_tools.py
|
Merged main, which now has #5554 and #5445. Both behaviours are kept in file search: unreadable files are skipped without a prompt and counted, and the 20 s budget still applies, including to 🔍 Technical details
|
tests/unit/test_file_watcher.py reads both pages since amd#5480, so the CI path-coverage lint failed on main and every PR merging it.
Asked to find and delete a file it had saved itself, GAIA searched the home folder and then the whole drive, and told the user the file doesn't exist. File search skips every folder whose name starts with a dot, so GAIA's own documents folder (`~/.gaia/documents`, the chat's default read/write folder) was never searched. Now "home" and "everywhere" searches also look in GAIA's documents folder and in any folder the chat was granted that sits under a skipped folder. Other dot-folders such as `~/.cache` are still skipped, and nothing outside the requested scope gets added. How it combines with amd#5565 and amd#5554: this only adds folders to the list a search walks. It leaves the walkers alone. The extra folders share amd#5565's one time and entry budget, and amd#5554's per-file readability check applies inside them. Both PRs already conflict with current main. This branch adds no new conflict regions to either one (checked with `git merge-tree`). Evals: no local run. This changes `find_files` / `search_file` results the model sees. Watch `gaia_files`, `gaia_tool_selection` and `tool_selection` on the next RC. ## Test plan - [x] `python -m pytest tests/unit/test_search_gaia_documents.py`: 8 passed, and 7 of them fail without the fix - [x] Every unit test file that uses `find_files` or `search_file`, plus `test_file_tools.py`: 679 passed, 17 skipped - [x] `python util/lint.py --black --isort` passes - [ ] In the desktop app, save a file to GAIA's documents folder, then ask GAIA to find it. `find_files` with scope `home` returns it. <details> <summary>🔍 Technical details</summary> - `hidden_granted_roots()` in `search_scope.py` returns `gaia_home()/"documents"` plus the validator's `allowed_paths` (minus the scratch dir) when a walk of the search roots would skip a folder on the way to them. A candidate is returned only if it sits under one of the roots, so `confine_roots`, `ProtectedFolders` and the content search's per-file read check all still apply. Candidates go outermost first, so `~/.gaia` and `~/.gaia/documents` both granted still return each file once. - `find_files` appends these as extra roots. `search_file` walks them after its phase-0 roots at `SHALLOW_ROOT_DEPTH`, and it already dedupes its results. </details>
Before: asking for "the resume file" never found
résumé 📄 draft.txtsitting in the chat's own documents folder, so the agent spent ~20 tool calls and 4 minutes widening the search up toC:\, and one widefind_filescall could hang for 3 minutes until the tool timeout abandoned it with nothing. After: file-name search ignores case and accents ("resume" finds "résumé", "cafe" finds "Café", emoji and CJK still match themselves), and every file search stops within 20 s, returning what it found plus a plain note naming the folders it didn't finish. Searches also stop walking into junctions and symlinks, so a home.cachejunction to a huge model store is no longer crawled.Eval categories to watch on the next RC (tool output text changed):
tool_selection,error_recovery.Test plan
pytest tests/unit/test_file_search_accents_and_budget.pycovers accent folding both ways, NFC vs NFD names, emoji and CJK names, globs and regexes with accents, the index path, the time budget on a fake clock, and a real junction (a symlink off Windows; skipped where one can't be created)pytest tests/unit/test_file_search_scope.py tests/unit/test_filesystem_tools_mixin.py tests/unit/test_file_access_scope.py tests/unit -k "search or find_files or file_tools" -n 4résumé 📄 draft.txtinto a chat's documents and ask for "the resume file". It's found on the first search.🔍 Technical details
.lower()strings, and"resume" in "résumé"is false. The newgaia/filesystem/name_match.pyfolds both sides: NFKD, drop the Latin/Greek/Cyrillic combining-diacritic blocks, NFC, then casefold. Recomposing keeps a Hangul syllable from matching half of another. Marks that change the letter, like Japanese dakuten, are kept. Globs usefnmatchcaseon the folded text, so*,?and[...]behave the same on every OS.search_file's regex path strips accents but doesn't casefold, because casefolding would turn\Dinto\d.unicode61tokenizer already drops diacritics from indexed names, NFD included. The bug there was passing the raw query toMATCH, whererésumé*.txtis a syntax error that silently fell through to the walk.query_filesnow buildsname : ("w1"* "w2"*)from the folded words.find_filesoverfetches and filters the rows with the same matcher as the walk, so glob semantics hold. A query with no words (*.pdf) goes straight to the walk.find_fileshad no budget, so its name and content walks ran until done.search_filealready had one (SEARCH_TIME_BUDGET_S = 20,SEARCH_ENTRY_BUDGET = 200_000). That logic is nowsearch_scope.SearchBudget, and the clock is injectable (clock=) or patchable (search_scope.monotonic). It's shared byfind_files(name and content),search_fileandsearch_file_content, which used unboundedrglob. Results carryunfinished_pathsand the note.DirEntry.is_dir(follow_symlinks=False)returns True for a junction andis_symlink()returns False, so bothfind_filesandsearch_filewalked into them (the new tests fail onmain).search_scope.is_linkskips symlinks and the two link reparse tags (mount point0xA0000003, symlink0xA000000C). OneDrive cloud placeholders are reparse points too, but they hold the user's files, so they are still walked.FileSystemIndexService.scan_directoryuses the sameis_dir(follow_symlinks=False)test, so the indexer still follows junctions.