fix(ask-line): enforce conversation history token budget - #2862
Conversation
PR Summary by QodoEnforce per-model token budgets for /ask_line history
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1.
|
| from pr_agent.algo.pr_processing import (OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD, | ||
| get_pr_diff, | ||
| retry_with_fallback_models) |
|
Code review by qodo was updated up to the latest commit 6abfafe |
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Merging, thanks. Qodo's pass did real work here, the completion reserve and the non-GPT counting both came from it, and all four findings are resolved.
Coverage checked the hard way: reverting both source files with your tests kept turns three of the four red. I also confirmed the two quiet risks are not risks. select_autoescape(default_for_string=False) renders byte-identically to the old environment, and bypassing the class-level encoder cache for a fallback model costs nothing, because tiktoken caches internally.
Summary
/ask_lineafter loading review-thread historyFixes #2861
Root cause
PR_LineQuestionsloads GitHub review-thread history inrun(), but_get_prediction()sent the rendered prompt without a final token-budget check. TheTokenHandlerwas initialized before that history was loaded, so it could not protect the final request. Fallback attempts could also use the primary model's cached tokenizer.Changes
TokenEncodercallers to request a fallback-model encoder without replacing the primary cached encoderTests
pytest -q -p no:cacheprovider tests/unittestgit diff origin/main...HEAD --check