Repository navigation
Description
Description
max_tokens (the per-file-review-task prompt-size ceiling) is a hardcoded, model-agnostic constant compiled into the engine, with no CLI flag, config key, environment variable, or llm.extra_body override that reaches it. On the version we run (built 2026-08-03, postdating both #417 and #421) the literal value is:
"MAX_TOKENS": 58888
found twice in the compiled binary's embedded static task-config JSON blocks (the main review task and the fix-prompt-generation task), alongside other clearly-static engine defaults (batch size, dedup thresholds, tool-call limits) — not inside any per-model or per-provider metadata structure. context_window / contextWindow / context_length do not appear anywhere in the binary.
Why this matters
We route real, materially cheaper 1M-context models (e.g. GLM-5.2, 1,048,576-token context window) through this engine specifically to reduce review cost. The 58,888-token ceiling has nothing to do with what the routed model can actually hold — it is a flat cap applied identically regardless of provider/model, so a large real-context model gets throttled down to a fraction of a percent of its own window before it ever sees a file.
Concretely, on our repo, a single per-glob --rule file merging JIRA + Confluence + repository guidance + a knowledge-base tree already reaches ~65,500 tokens on its own, before any diff/file content is added. Every file matched by that rule glob blows the ceiling immediately: we observed a completed_with_errors run where two files hit the 80% warning ("prompt tokens (60361) exceed 80% of max_tokens(58888)", from the shared threshold #421 introduced) and the file actually carrying the review's substantive content never completed ("main_task did not complete before stopping").
We worked around this from our side by relevance-trimming our own rule-file content down to a smaller budget before invoking the engine — but this is a lossy mitigation for something the engine already computes and reports the exact number for in its own warnings; it should not require reverse-engineering the compiled binary to discover the ceiling exists, let alone that it cannot be changed.
What we checked (exhaustively) before concluding this is not user-configurable
- CLI flags (
ocr review --help): the only token-related flag is--max-tokens-budget— a different, unrelated total input+output budget for the whole review run (default0= unlimited). It does not touch the per-filemax_tokensceiling. - Config keys (
ocr config set <key> <value>rejects unknown keys against a full enumerated list:provider, model, providers.<name>.<field>, custom_providers.<name>.<field>, mcp_servers.<name>.<field>, llm.url, llm.auth_token, llm.auth_header, llm.model, llm.protocol, llm.use_anthropic, llm.extra_body, llm.extra_headers, language, telemetry.*):max_tokensandreview.max_tokensare both rejected as unknown. - Environment variables (complete
OCR_*list extracted from the binary):OCR_LLM_TIMEOUT, OCR_LLM_MODEL, OCR_LLM_URL, OCR_LLM_PROTOCOL, OCR_ENABLE_TELEMETRY, OCR_USE_ANTHROPIC, OCR_CONTENT_LOGGING, OCR_LLM_EXTRA_HEADERS, OCR_VIEWER_ALLOWED_HOSTS, OCR_LLM_AUTH_HEADER, OCR_CONFIG_PATH, OCR_LLM_TOKEN— none relate to a token/context ceiling. llm.extra_body(used elsewhere for provider-specific request tweaks): this is serialized into the outbound LLM API request body — it cannot reach an engine-side check that happens before the request is even built, comparing the assembled prompt against the compiled-in constant.
Suggested fix
Expose max_tokens (and/or the 80% warning threshold it already computes against, per #417/#421) as user-configurable — a --max-tokens-per-file CLI flag, a max_tokens/review.max_tokens config key, or an OCR_MAX_TOKENS env var would all resolve this cleanly, ideally with a documented interaction with --max-tokens-budget. Even better: derive a sane default from the configured model's own advertised context window when one is available, rather than one flat constant for every provider/model.
Environment
- Engine version: 1.8.6 (npm package
@alibaba-group/open-code-review), installed vianpm install -g @alibaba-group/[email protected] - Confirmed via direct extraction of the installed native binary (
opencodereview, Mach-O arm64) and its embedded strings - Related: refactor(agent): replace hardcoded
* 4 / 5token threshold with a named constant #417, refactor(agent,scan): share one 80% token threshold #421 (the 80% threshold refactor — confirms the mechanism, not the configurability), 大 MR 场景下 open-code-review 可能在超时前产生极高 token 成本 #409 (related large-MR cost/timeout pain point)
Activity
lizhengfeng101 commentedon Aug 4, 2026
Thanks for the thorough investigation and detailed write-up, @theo-chiu! The analysis is spot on —
MAX_TOKENSis indeed a hardcoded constant today with no user-facing override.I think a good approach here would be:
ocr config set max_tokens <value>— allow users to persistently override the per-file prompt ceiling via the config system.This would give power users like yourself a straightforward way to unlock the full context window of large-context models, while keeping the current default safe for everyone else.
We'd love to see community contributions on this! If anyone is interested in picking this up, the main touch points are in
cmd/opencodereview/shared_flags.go,internal/config/, andinternal/config/template/template.go. Happy to provide guidance on the implementation path.