fix(search): emit the search_files truncation notice once and stop walking#2979
Open
Tatlatat wants to merge 1 commit into
Open
fix(search): emit the search_files truncation notice once and stop walking#2979Tatlatat wants to merge 1 commit into
Tatlatat wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
searchFilespushes[… search truncated — refine pattern …]andreturnswhen the byte budget is exceeded. But
returnonly unwinds the currentrecursive
walkframe — the parent loop keeps visiting sibling entries andother 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
searchContentin the same file already guards this with atruncatedflag.Repro
A workspace where matches span multiple directories and
maxListBytesis smallenough to truncate after the first directory → output contains the truncation
notice twice.
Fix
Mirror
searchContent: add atruncatedflag, bail at the top ofwalkandbefore 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_filescase asserting the truncation notice appears exactly onceacross 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 checkclean on the changed files.