Repository navigation
Description
What happened
I found two filesystem-tool issues while testing proactive discovery on #6730 with a large, authorized directory tree. A broad Grep query with very few matches took minutes and prompted repeated model waits. A broad Glob query returned a large path list to the model in one result.
Grep search scope, native traversal, and waiting
In the discovery run, a search for a rare literal identifier across the home directory was cancelled after 241.1 s. A follow-up search under Documents completed in 274.6 s with 7 matching lines. During those two searches, the agent made 9 model requests whose sole tool call was wait. Those requests used 735,707 input and output tokens, including 732,416 cached input tokens.
| Same query on the real directory tree | Wall time | Result |
|---|---|---|
Native Grep across Documents |
281.7 s | All 7 original lines matched |
Native Grep across Documents with a file-type filter |
Still running at 60 s | Cancelled by the harness |
Native Grep across Documents with a 30 s deadline |
30.0 s | Cancelled without returning matches |
| Native Grep in the known subdirectory | 0.77–0.90 s | Same 7 lines in both runs |
| Native Grep in that subdirectory with a file-type filter | 0.65–0.71 s | Same 7 lines in both runs |
Standalone ripgrep 15.2 across Documents |
13.3–14.8 s | Same 7 lines in both runs |
The narrow directory was selected from the earlier results. Standalone ripgrep serves as a performance reference for this query and uses its own permission and ignore handling. A five-second sample of the native probe showed repeated path resolution and file opens among the main sources of time. Native Grep implementation
Keep the Grep interface and exhaustive search behavior. Use a narrower authorized path when discovery has a relevant directory, and reduce redundant path resolution and opens in the native traversal while preserving filesystem policy and ignore rules. For broad searches, surface an explicit timeout when the search cannot finish within its budget. The runtime could notify the agent when a pending tool call settles, so the model can resume when a result or timeout is available.
I also tested an isolated match-limit prototype. The numbers are medians of three runs.
| Synthetic query | Current Grep | Prototype returning up to 100 matches |
|---|---|---|
| Zero matches | 259 ms | 256 ms, complete |
| Seven matches among unrelated files | 247 ms | 264 ms, complete |
| 20,000 matching lines | 103.4 ms, 3.55 MB of JSON | 1.4 ms, 17.8 KB of JSON, complete: false |
| Exactly 100 matching lines | All 100 returned | All 100 returned, complete: true |
The match limit helped the high-volume case. Making it the default broke an existing exhaustive-search test, so a limit is better exposed as an option for callers that can accept partial results.
Glob output size and continuation
The Rust tool currently returns the complete path list in one response. I tested local pagination with a sorted first page of up to 128 paths, a 16 KiB JSON size target, and complete: false plus next_after when more results are available. The caller can pass the cursor as after with the same pattern and working directory. The prototype bounds the response while still walking the authorized tree.
| Measurement | Before | With pagination |
|---|---|---|
| Same recorded match set of 1,580 paths, initial JSON payload | 132,366 B | 8,864 B (−93.3%) |
| Largest Glob tool record in the two live discovery runs | 264,923 B | 32,867 B (−87.6%) |
| Discovery-worker model requests | 12 | 28 |
| Discovery-worker input and output tokens | 1,579,515 | 2,223,287 |
The paginated run had three partial Glob pages, and the model requested no continuations. The two live runs followed different tool paths, including the Grep waits above, so their token totals cannot isolate the effect of pagination. The replay of the same 1,580 paths measures the first-page payload reduction directly. See #5597 for the earlier Glob completeness discussion. Native Glob implementation
How to reproduce
- On macOS, choose a large authorized directory tree with a rare identifier. Call
Grepwith that directory aspathand omitglob. Observe elapsed time and any repeated Code Modewaitcalls. Repeat with the same pattern in a known relevant subdirectory and compare the matching lines. - Run a recursive
Globin an authorized directory containing many matching paths. Measure the initial JSON payload. For the pagination prototype, also check that an incomplete page exposes a cursor and that later pages return the remaining paths.
Environment
- macOS 26.7.2, Apple Silicon. Maka Rust development build based on
c78b45d0c801, the feat(bot): add scheduled proactive discovery and quoted feedback #6730 head tested. - The Grep implementation and match collector were byte-for-byte identical to the corresponding files on
rust-previewwhen checked. - Native Grep benchmark timings came from a local harness using a read-only filesystem policy. The
waitand discovery-worker token counts came from the live discovery logs.
Logs, screenshots, or additional context
简体中文
在 #6730 的主动发现测试中,一个已授权的大目录树暴露了两个文件工具问题。大范围 Grep 只命中少数行,却耗时数分钟并触发模型反复等待。大范围 Glob 则一次性把很长的路径列表交给了模型。
Grep 的搜索范围、原生遍历和等待
在实际主动发现运行中,第一次在用户主目录下搜索一个很少出现的字面标识符,241.1 秒后取消。随后在 Documents 下搜索相同标识符,耗时 274.6 秒并返回 7 条匹配行。两次搜索期间,Agent 发起了 9 次只调用 wait 的模型请求,输入和输出合计 735,707 token,其中 732,416 是命中缓存的输入 token。
| 在真实目录树上执行同一查询 | 实际耗时 | 结果 |
|---|---|---|
原生 Grep 扫描整个 Documents |
281.7 秒 | 与原先的 7 条匹配逐条一致 |
原生 Grep 扫描整个 Documents,加文件类型过滤 |
60 秒时仍在运行 | 由测试程序取消 |
原生 Grep 扫描整个 Documents,设 30 秒截止时间 |
30.0 秒 | 取消,没有返回匹配 |
| 原生 Grep 只扫已知的子目录 | 0.77–0.90 秒 | 两次都返回相同的 7 条匹配 |
| 原生 Grep 只扫该子目录,并加文件类型过滤 | 0.65–0.71 秒 | 两次都返回相同的 7 条匹配 |
独立运行 ripgrep 15.2 扫描整个 Documents |
13.3–14.8 秒 | 两次都返回相同的 7 条匹配 |
较窄的目录根据先前的匹配结果选出。独立运行的 ripgrep 是本次查询的性能参照,使用它自己的权限和忽略规则处理方式。对原生测试程序的 5 秒采样显示,反复解析路径和打开文件是主要耗时环节之一。 原生 Grep 实现
保留 Grep 接口和完整搜索能力。主动发现已有相关目录线索时,优先传入较窄的已授权 path。原生遍历可减少重复解析路径和打开文件,同时保留文件系统权限和忽略规则。必须大范围查询时,若搜索在时限内无法完成,应明确报告超时。运行时可以在待处理的工具调用结束时通知 Agent,让模型收到结果或超时信息后继续。
我还用隔离原型测试了匹配条数上限。下表耗时为每个场景运行三次的中位数。
| 合成查询 | 当前 Grep | 最多返回 100 条的原型 |
|---|---|---|
| 零匹配 | 259 毫秒 | 256 毫秒,结果完整 |
| 在大量无关文件中找到 7 条匹配 | 247 毫秒 | 264 毫秒,结果完整 |
| 20,000 条匹配行 | 103.4 毫秒,JSON 为 3.55 MB | 1.4 毫秒,JSON 为 17.8 KB,complete: false |
| 恰好 100 条匹配行 | 返回全部 100 条 | 返回全部 100 条,complete: true |
条数上限改善了高命中场景。设为默认行为会让现有的完整搜索测试失败,因此适合作为允许部分结果的调用选项。
Glob 的返回体积与续读
当前 Rust 工具会一次返回完整路径列表。本地分页试验将首页按路径排序,最多返回 128 条路径,JSON 目标大小为 16 KiB。有剩余结果时返回 complete: false 和 next_after,调用方以同一匹配模式和工作目录将游标传给 after。试验限制了响应体积,每页仍会遍历已授权的目录树。
| 指标 | 分页前 | 分页后 |
|---|---|---|
| 对同一批 1,580 条路径,首次返回的 JSON | 132,366 B | 8,864 B(−93.3%) |
| 两次真实主动发现中最大的 Glob 工具记录 | 264,923 B | 32,867 B(−87.6%) |
| 调查 Worker 的模型请求 | 12 次 | 28 次 |
| 调查 Worker 的输入和输出 token 合计 | 1,579,515 | 2,223,287 |
分页后的一轮返回了三个不完整的首页,模型没有请求续页。两次实跑调用工具的过程不同,包含上面的 Grep 等待,因此整轮 token 差异无法单独归因于分页。同一批 1,580 条路径的回放直接测出了首页返回体积的变化。此前关于 Glob 结果完整性的讨论见 #5597。 原生 Glob 实现
如何复现
- 在 macOS 上选择一个包含少见标识符的大目录树,确认已授权访问。把它作为
path调用Grep,省略glob,观察耗时和 Code Mode 的wait调用次数。再对已知相关的子目录执行同一查询,比较匹配行。 - 在包含大量匹配路径的已授权目录中运行递归
Glob,测量初次返回的 JSON。使用分页原型时,同时验证不完整的页面是否提供游标,以及后续页面是否返回剩余路径。
环境
- macOS 26.7.2,Apple Silicon。Maka Rust 开发版基于测试时 feat(bot): add scheduled proactive discovery and quoted feedback #6730 的提交
c78b45d0c801。 - 核对时,测试所用 Grep 实现和匹配结果收集代码与
rust-preview上对应文件逐字节一致。 - 原生 Grep 对照耗时由使用只读文件系统权限的本地测试程序测得。
wait次数和调查 Worker 的 token 用量来自实际主动发现记录。
AI assistance — OpenAI Codex helped inspect the local traces, run the benchmarks, and draft this report.
Activity
priyaamore commentedon Nov 12, 2026
i would like to solve this bug can you assign to me?
sunrioa commentedon Nov 12, 2026
Thanks for offering to help, @priyaamore! I’d like to keep this issue open for investigation and hold off on assigning it for now.
The measurements so far cover a few unusually large workloads. Since
GrepandGlobare core tools used across many workflows, I’d like to check how often these issues occur in everyday use and how a proposed change would affect existing behavior before deciding whether a change is warranted.简体中文
感谢你愿意帮忙,@priyaamore!这条 issue 我想先保留,继续排查,暂时不指派实现。
目前的实测集中在少数负载特别大的场景。
Grep和Glob是许多工作流都会用到的基础工具。我想先验证这些问题在日常使用中的出现频率,以及改动会对现有行为产生什么影响,再决定是否有必要调整。priyaamore commentedon Nov 12, 2026
Thank you for the clarification! I understand. I'll hold off on implementation for now. I'll continue investigating the issue and share any useful findings that could help determine whether a change is needed