From 8886e6ec069c746da69fb4daf9d0945fa20552ce Mon Sep 17 00:00:00 2001 From: can1357 Date: Mon, 13 Apr 2026 13:03:59 +0200 Subject: [PATCH] fix(coding-agent-find-tool): corrected find glob ordering by mtime - Propagated `combinedSignal` into `doGlob` so cancellation is honored during glob execution. - Skipped fallback `doGlob(false)` when `timeoutSignal` was aborted to avoid redundant work. - Sorted `result.matches` by descending `mtime` in JS to return the most recent hits first. --- packages/coding-agent/src/tools/find.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/coding-agent/src/tools/find.ts b/packages/coding-agent/src/tools/find.ts index 2f011349b..c26f4df62 100644 --- a/packages/coding-agent/src/tools/find.ts +++ b/packages/coding-agent/src/tools/find.ts @@ -244,6 +244,7 @@ export class FindTool implements AgentTool { maxResults: effectiveLimit, sortByMtime: true, gitignore: useGitignore, + signal: combinedSignal, }, onMatch, this.session.searchDb, @@ -252,9 +253,12 @@ export class FindTool implements AgentTool { try { let result = await doGlob(true); - if (result.matches.length === 0) { + if (result.matches.length === 0 && !timeoutSignal.aborted) { result = await doGlob(false); } + // Sort by mtime descending (most recent first) in JS instead of native. + // This allows native glob to early-terminate at maxResults. + result.matches.sort((a, b) => (b.mtime ?? 0) - (a.mtime ?? 0)); matches = result.matches; } catch (error) { if (error instanceof Error && error.name === "AbortError") {