fix(agent): reserve output tokens in compression threshold - #45351
fix(agent): reserve output tokens in compression threshold#45351lEWFkRAD wants to merge 1 commit into
Conversation
|
Verified — clean. Reviewed the full diff across What was checked:
Why this matters: Without output reservation, proactive compression triggers at 50% of context_length (e.g. 64K of 128K). If the model reserves 32K for output, the effective input budget is only 96K — compression should trigger at 48K, not 64K. This fix prevents context overflow on models with large output caps. Good change. No issues found. |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Clean, well-scoped fix/feature with comprehensive tests. No issues found.
- Logic is correct and focused
- Tests cover the new behavior
- No security concerns
- Good error handling
Reviewed by Hermes Agent
|
Flagged as duplicate of #43651 by @alt-glitch. Closing this one in favor of the earlier PR. |
|
Closing in favor of #43651 which contains the same fix. |
What does this PR do?
Makes proactive context compression reserve the response-token budget that the outgoing request will send. When a provider/profile default like
provider: customreservesmax_tokens=65536, the compressor now compares prompt estimates against(context_length - output_reservation) * compression.thresholdinstead of the raw context window.Fixes #43547
Type of Change
Changes Made
agent/context_compressor.pyderives threshold/tail budgets from an output-reservation-aware input budget when a response cap is known.run_agent.pyresolves the same output cap precedence used by request construction: request overrides, ephemeral retry caps, usermodel.max_tokens, Anthropic defaults, provider profile defaults, and Claude aggregator defaults.agent/agent_init.py,agent/turn_context.py,agent/agent_runtime_helpers.py, andagent/chat_completion_helpers.pysync the reservation at init, preflight, model switch, and fallback activation.tests/test_ctx_halving_fix.pyadds regression coverage for the custom provider65536default against a131072context window.How to Test
scripts/run_tests.sh tests/test_ctx_halving_fix.pyscripts/run_tests.sh tests/agent/test_context_compressor.pyscripts/run_tests.sh tests/run_agent/test_switch_model_context.py tests/run_agent/test_compressor_fallback_update.pyruff check agent/context_compressor.py run_agent.py agent/agent_init.py agent/turn_context.py agent/agent_runtime_helpers.py agent/chat_completion_helpers.py tests/test_ctx_halving_fix.pygit diff --checkChecklist
scripts/run_tests.shDocumentation / Housekeeping
For New Skills
Screenshots / Logs
N/A