Repository navigation
Description
OpenCodeReview Version
open-code-review v1.13.3 (375f64c) linux/amd64built at: 2026-10-22T04:27:25Z
Operating System
Linux (x86_64)
Installation Method
npm (global)
LLM Provider
Other OpenAI-compatible endpoint
Bug Description
code_search caps matches at 100 (gitGrepMaxCount in internal/tool/code_search.go), but the matched line content is passed through unbounded. In repositories that contain committed build artifacts (minified JS/CSS bundles), a single matched line can be megabytes long, so the count cap does not protect the context window.
Observed on a large (~12 GB) monorepo whose web build output is committed (single-line minified bundles; longest matched line observed ~2.1M chars):
- A single
code_searchtool result measured 7.2 MB (39 lines, longest line 1.58M chars). Another 3.3 MB result did include theNote: Showing the first 100 matches across 16 matching filestruncation note — the count cap was in effect, it just doesn't bound size. - The accumulated
llm_requestthen exceeded the model's 1,048,576-token context limit and was rejected with 400. - Context compression cannot digest megabyte-long lines, so the review item stops with
Context compression exceeded threshold for <file>, stoppingand is reported as failed (classificationunknown/budget). With several such files the whole review degrades to partial.
Steps to Reproduce
- Use a repo that contains a committed minified bundle, e.g.
dist/assets/index-*.jswith megabytes of code on a single line (common in embedded/Android monorepos where web build output is committed). - Run
ocr reviewon any nearby change. Following the standard prompt guidance ("confirm by searching withcode_search"), the agent searches broad tokens such aspublicPath|baseUrl|base:that also appear in the bundle. - Inspect the session JSONL under
~/.opencodereview/sessions/: onetool_callevent forcode_searchcarries a multi-MBresult, followed by a 400 context-limit error andContext compression exceeded threshold.
Expected Behavior
code_search should truncate matched lines (e.g. 1–2 KB per line with a [truncated] marker) and/or cap the total result size (e.g. 100–200 KB), keeping the existing "narrow file_patterns" note. This keeps search useful for normal source code while preventing minified artifacts from blowing the context window.
Side note: --exclude only affects which files are selected for review, not code_search's repo-wide scope, so there is currently no user-side way to keep the agent out of committed build artifacts.
Logs / Error Output
POST /v1/chat/completions: 400 Bad Request {"message":"Input exceeds the context limit (1048568 tokens). Please shorten the input."}
[ocr] Context compression exceeded threshold for src/.../foo.cpp, stopping.
Note: Showing the first 100 matches across 16 matching files. Some files are partially shown or omitted entirely. Narrow file_patterns to see the rest.
(lines taken from a session JSONL; provider is an OpenAI-compatible endpoint, sensitive paths redacted)AI/LLM Disclosure
- I didn't use AI/LLM to assist or generate the content above.
Additional Context
- Checked
internal/tool/code_search.goon current main: same behavior (gitGrepMaxCount = 100hard-coded, no per-line or total byte cap, tools config JSON has no knob for it either). file_readalready truncates (500 lines) andfind_filecaps at 100 paths; onlycode_searchresult content is unbounded.- Happy to send a PR adding per-line + total byte truncation if the approach sounds good.
Activity
fix(tool): truncate oversize code_search match lines
RichardoMrMu commentedon Oct 26, 2026
Fixed in PR #1833: git grep match lines are now truncated to 4096 runes with a marker carrying the true rune count, and a note is emitted when any rendered line was cut. Worst-case result is bounded (~410 KB at 100 matches) instead of multi-MB, and the truncation is rune-safe (UTF-8 regression test included).
fix(tool): bound code_search result size, not just match count