feat(config): make per-file token limit configurable - #716
Conversation
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 5 selected item(s). |
lizhengfeng101
left a comment
There was a problem hiding this comment.
Hey, nice work — tests and docs are solid. Two things I'd like to discuss:
1. MaxTokens shouldn't also control LLM output length
Right now Template.MaxTokens is passed directly into ChatRequest.MaxTokens, which maps to the API's max_completion_tokens. That means when a user sets max_tokens 200000 to accommodate a model with a larger context window, they're also telling the model it can produce up to 200,000 output tokens per response — that's not the intent.
This field currently serves two roles: the compression/pre-flight threshold baseline (context window ceiling) and the max output passed to the API. These should be independent. I'd suggest this PR only let the configurable value affect compression thresholds and the pre-flight gate, and leave the LLM call's max output at its existing default (or split them into two fields).
2. Need ocr config unset max_tokens
Once a user runs ocr config set max_tokens 200000, there's no way to revert to the template default — ocr config set max_tokens 0 is rejected by validation, and ocr config unset only supports provider, custom_providers.<name>, and mcp_servers.<name>.
Suggest extending ocr config unset to handle scalar keys by zeroing the field and saving — omitempty will drop it from the JSON automatically:
case "max_tokens":
cfg.MaxTokens = 0
return saveConfig(configPath, cfg)|
Addressed both points in 3a2a0ac.
Verification: focused config/flag tests pass; |
Description
Expose the per-file prompt token ceiling as a saved
max_tokenssetting and a per-run--max-tokensoverride. The resolved value now follows--max-tokens> saved configuration > embedded task-template default for bothocr reviewandocr scan.This keeps the per-file ceiling independent from
--max-tokens-budget, which caps aggregate usage across a run. Invalid persisted values and negative CLI values fail with actionable errors.Type of Change
How Has This Been Tested?
make testpasses locallyAutomated verification on Windows with Go 1.25.5:
go test -count=1 ./...go vet ./...git diff --checkChecklist
go fmt,go vet)Related Issues
Closes #707
AI Assistance Disclosure
AI assistance was used during implementation. I reviewed the complete diff and verified the tests locally.