mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-07-30 03:24:34 +00:00
|
Some checks are pending
CI / test (push) Waiting to run
CI / cross-compile (amd64, darwin) (push) Waiting to run
CI / cross-compile (amd64, windows) (push) Waiting to run
CI / cross-compile (arm64, darwin) (push) Waiting to run
CI / cross-compile (arm64, linux) (push) Waiting to run
CI / cross-compile (arm64, windows) (push) Waiting to run
Add a runtime token-budget guardrail to the diff-review path so a large MR stops itself before runaway cost (issue #409: ~90.4M tokens in one failed attempt), instead of timing out and losing all structured output. New `ocr review` flag (mirror scan's proven --max-tokens-budget): - --max-tokens-budget N : cap aggregate token usage; dispatch stops once the running total + a per-file look-ahead would exceed it (0 = unlimited). Mechanism mirrors scan/agent.go's dispatchBatch gate exactly: read the existing atomic Runner counters (no duplicate counter — a second one would be a drift bug) before acquiring the semaphore, and break the dispatch loop on exceed. In-flight workers are allowed to finish (overrun bounded by the in-flight count, <= concurrency), matching scan's documented contract. Budget exhaustion returns the partial comments already produced with a nil error (not a Go error — the failure path suppresses output), and signals budget-exceeded out-of-band so the output layer sets a typed `budget_exceeded` status distinct from success / completed_with_warnings / completed_with_errors. Additional changes tied to the invariants: - Pre-review scale warning (files, diff tokens, configured budget) printed before any model spend; non-blocking, warn-only. - Structured usage emitted on the failure path (stderr) so the cost of a failed attempt is never lost. Carries only token/tool tallies — no credentials or prompts. Reports the agent's actual BudgetExceeded() state so the residual budget-trip + all-dispatched-fail edge can never contradict the typed status. - summary.budget_exceeded JSON field (additive, omitempty) so old parsers are unaffected; default 0/unlimited restores prior behavior. Internal/scan gains only the BudgetExceeded() accessor (returns false) so the shared ResultProvider interface compiles; scan keeps its own token budget and its JSON output is unchanged. Tests mirror internal/scan/budget_test.go: token-budget gate stops dispatch early and sets BudgetExceeded(); unlimited default runs all files; estimate helpers project sane values (with a humanTokens parity table so the two copies cannot diverge); JSON output asserts the typed status and the failure-path usage record. Full `make test` (-race) green. |
||
|---|---|---|
| .. | ||
| background_file.go | ||
| background_file_test.go | ||
| budget_output_test.go | ||
| config_cmd.go | ||
| config_cmd_test.go | ||
| config_dispatch_test.go | ||
| delegate_cmd.go | ||
| emit_run_result_test.go | ||
| flags.go | ||
| flags_test.go | ||
| git.go | ||
| git_test.go | ||
| llm_cmd.go | ||
| main.go | ||
| output.go | ||
| output_helpers_test.go | ||
| output_test.go | ||
| procattr_unix.go | ||
| procattr_windows.go | ||
| provider_cmd.go | ||
| provider_cmd_test.go | ||
| provider_tui.go | ||
| provider_tui_funcs_test.go | ||
| provider_tui_test.go | ||
| review_cmd.go | ||
| review_cmd_test.go | ||
| rules_cmd.go | ||
| scan_cmd.go | ||
| scan_cmd_test.go | ||
| session_cmd.go | ||
| session_cmd_test.go | ||
| shared.go | ||
| shared_test.go | ||
| shell_unix.go | ||
| shell_windows.go | ||
| smallfiles_test.go | ||
| version.go | ||
| viewer_cmd.go | ||