Skip to content

fix(search): emit the search_files truncation notice once and stop walking#2979

Open
Tatlatat wants to merge 1 commit into
esengine:v1from
Tatlatat:fix/search-files-truncate-once
Open

fix(search): emit the search_files truncation notice once and stop walking#2979
Tatlatat wants to merge 1 commit into
esengine:v1from
Tatlatat:fix/search-files-truncate-once

Conversation

@Tatlatat
Copy link
Copy Markdown
Contributor

@Tatlatat Tatlatat commented Jun 3, 2026

What

searchFiles pushes [… search truncated — refine pattern …] and returns
when the byte budget is exceeded. But return only unwinds the current
recursive walk frame — the parent loop keeps visiting sibling entries and
other directories. A later match while still over budget pushes the notice
again, so the output ends with duplicate truncation lines, and the walk
wastes I/O.

The sibling searchContent in the same file already guards this with a
truncated flag.

Repro

A workspace where matches span multiple directories and maxListBytes is small
enough to truncate after the first directory → output contains the truncation
notice twice.

Fix

Mirror searchContent: add a truncated flag, bail at the top of walk and
before each entry once it's set, and push the notice only on the first overflow.
Result: a single truncation notice and no wasted traversal.

Test

A search_files case asserting the truncation notice appears exactly once
across multiple directories. Verified it fails on the old code (two notices) and
passes on the fix.

Verification

npx vitest run tests/filesystem-tools.test.ts (123 passed); biome check
clean on the changed files.

…lking

searchFiles pushed "[… search truncated …]" and returned when the byte
budget was exceeded, but return only unwinds the current recursive walk
frame. The parent loop kept visiting sibling entries and other directories,
so a later match while still over budget pushed the notice again — the
output ended with duplicate truncation lines, and the walk wasted I/O. The
sibling searchContent in this file already guards this with a truncated
flag.

Mirror that: add a truncated flag, bail at the top of walk and before each
entry once set, and push the notice only on the first overflow. Result: a
single truncation notice and no wasted traversal. Add a search_files test
asserting the notice appears exactly once across multiple directories.
@github-actions github-actions Bot added the v1 Legacy TypeScript line (0.x) — v1 branch, maintenance only label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1 Legacy TypeScript line (0.x) — v1 branch, maintenance only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant