Repository navigation
fix(pr_agent/algo/utils.py): reporting an unreadable token budget instead of ignoring it - #2744
Conversation
…tead of ignoring it
…unreadable token budget
PR Summary by QodoReport non-numeric token budgets in clip_tokens (instead of silently ignoring)
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
|
Code review by qodo was updated up to the latest commit a8a487a |
…unreadable budget with empty text
|
Code review by qodo was updated up to the latest commit 7a0d880 |
|
Merged, thanks. Much better to hear about a bad budget than have it swallowed. |
Closes #2743.
Description
The whole body of
clip_tokensis wrapped inexcept Exception: warning; return text, so a non-integermax_tokensreturns the text unchanged.Root cause
max_tokensis used inside the broadtry, so aTypeErrorfrom the arithmetic is caught by thesame handler that exists to protect against encoder failures, and the warning it logs does not
name the budget as the cause.
The fix
Coerce
max_tokenstointbefore the broadtry. When it cannot be read as a number, log a warning that names the value and return the text — the previous outcome, but now with a signal.Behaviour change
clip_tokens(text, "50")returns the text unclipped with a generic warningFiles changed
Testing
New regression coverage in
tests/unittest/test_clip_tokens_invalid_budget.py— 4 tests, each written to failwithout the fix:
Proven to be a genuine regression test: with every changed
pr_agent/file reverted to itsorigin/mainversion and the new test file left in place, the suite fails. It only passeswith the fix applied.
Full pipeline, reproduced locally exactly as
.github/workflows/build-and-test.yamlruns it:on
python:3.12.13-slim— no failures.Also checked:
pytest tests/unittest— no new failures vsmainruff— no new findings vsmain;isort— clean on every file touchedRisk / compatibility
Numeric budgets are unaffected. The broad
exceptis left in place for genuine encoder failures.Checklist