Repository navigation
fix(tool): preserve binary matches in code_search - #2046
Conversation
git answers a binary hit with "Binary file <path> matches", a line with no line number that the result parser drops. A search whose hits are all binary therefore returned an empty string instead of the documented "No matches found", and the tool-use loop reads an empty result as a call that produced nothing, so three such rounds stopped the subtask with StopEmptyRounds. Pass -I so git excludes binary files from the match set. Ref mode then exits 1 and reuses the existing no-match path; text and mixed matches are unchanged.
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
|
Thanks for the detailed reproduction. The empty-result bug is real, but I don’t think -I is the right output contract. It turns “the search text exists in b.bin” into “No matches found”, discarding information that can be important when searching for embedded credentials, license text, resource names, or version strings. The model may then stop investigating instead of reporting or further examining the relevant artifact. Could we keep Git’s binary matches and parse Binary file matches explicitly instead? For example: text This fixes the root cause—the tool no longer returns an empty string—while preserving the path-level signal. It also avoids inventing line numbers or trying to decode binary content, and the same Git output is available in workspace, ref, and --no-index modes. The current parser already drops this line, so preserving it is a small output-contract improvement as well as a bug fix. I would prefer that over permanently excluding binary files. Please also update internal/behaviortask/search.go: it currently flushes a file only when it has numbered text matches, so a binary-only entry would otherwise be silently discarded on the analysis path. |
|
Thanks for the feedback, @chaojixinren. Here is the consolidated fix at
|
|
Thanks for preserving binary hits without inventing a line number. I checked the two path-format limitations noted in the PR against
|
|
Thanks for following up on the earlier feedback, @Bbbtt04. After reconsidering the trade-off, I reverted the binary-match reporting changes in There are cases where knowing that a binary file contains a search term is useful, but I think they’re too rare in code review to justify adding binary search support to Sorry for the back-and-forth, especially after I asked you to address the path-handling edge cases. This was a change in my judgment about what the tool should do, not a problem with how you responded to the review. |
@lizhengfeng101 Got it. That’s what I originally had in mind. I’m still getting familiar with the project, so thanks for your guidance! |
|
Description
code_searchcould return an empty result when every match was inside a binary file. Git emits a path-only message for a binary hit, which the parser normally skipped. The review loop treats empty tool content as a failed round, so repeated binary-only searches could stop a review early.The tool now preserves binary hits as file paths and omits their content and line numbers. A genuine no-match still returns
No matches found. The first 100 matches share a single limit in Git output order. Each text line or matching binary file counts as one result.The behavior analysis path retains binary entries for files in its authorized scope and applies the same shared limit across batches. Binary entries produce no line-level evidence. The tool documentation describes both output forms.
The parser still has known edge cases for paths containing
:<digits>:in workspace output and for Git-quoted paths in scoped analysis.Type of Change
How Has This Been Tested?
TestGitGrep_ResultLimitcovers binary-only and mixed matches in workspace, commit/ref, and plain-directory modes, including exact-limit and truncation cases.make checkpassed. The targetedmake coveragerun forinternal/toolandinternal/behaviortaskpassed with 93.7% combined coverage.The full local coverage run reported a Windows pipe-cancellation test failure in
internal/gitcmd. The local race run could not start without GCC.AI/LLM disclosure
The original patch used DeepSeek Harness (
deepseek-v4-flash). The follow-up used OpenAI Codex (GPT-6) and the OCR delegation skill for review.Fixes #2045