Skip to content

code_search: 100-match cap is count-only — minified single-line files produce multi-MB tool results that exceed the context limit #1827

Open

Description

@AaronPasi

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_search tool result measured 7.2 MB (39 lines, longest line 1.58M chars). Another 3.3 MB result did include the Note: Showing the first 100 matches across 16 matching files truncation note — the count cap was in effect, it just doesn't bound size.
  • The accumulated llm_request then 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>, stopping and is reported as failed (classification unknown/budget). With several such files the whole review degrades to partial.

Steps to Reproduce

  1. Use a repo that contains a committed minified bundle, e.g. dist/assets/index-*.js with megabytes of code on a single line (common in embedded/Android monorepos where web build output is committed).
  2. Run ocr review on any nearby change. Following the standard prompt guidance ("confirm by searching with code_search"), the agent searches broad tokens such as publicPath|baseUrl|base: that also appear in the bundle.
  3. Inspect the session JSONL under ~/.opencodereview/sessions/: one tool_call event for code_search carries a multi-MB result, followed by a 400 context-limit error and Context 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.go on current main: same behavior (gitGrepMaxCount = 100 hard-coded, no per-line or total byte cap, tools config JSON has no knob for it either).
  • file_read already truncates (500 lines) and find_file caps at 100 paths; only code_search result content is unbounded.
  • Happy to send a PR adding per-line + total byte truncation if the approach sounds good.

Activity

  1. added
    bug
    on Oct 26, 2026
  2. added theissue type on Oct 26, 2026
  3. added a commit that references this issue on Oct 26, 2026
    5c28697
  4. RichardoMrMu commented on Oct 26, 2026

    @RichardoMrMu

    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).

  5. added a commit that references this issue on Nov 9, 2026
    5eb9657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions