fix(agent): lower compression retry threshold from 5% to any positive reduction (#59587) - #59605
Open
webtecnica wants to merge 1 commit into
Open
webtecnica wants to merge 1 commit into
webtecnica wants to merge 1 commit into
Conversation
… reduction (NousResearch#59587) The 413 payload-too-large and context-overflow handlers both require ≥5% estimated token reduction before retrying after a compression attempt (original_tokens * 0.95 gate). A genuine 3–4% reduction may be exactly what is needed to fit within the provider's limit, and the current gate causes a terminal failure that sends the user to /new or /compress unnecessarily. The 5% threshold existed as a loop-progress guard, but max_compression_attempts = 3 already provides an absolute upper bound on iterations, making the percentage gate redundant: even without it, at most 3 retries happen. Fix: remove the * 0.95 multiplier on all three sites (lines 3369, 3592, 3595), accepting any positive token reduction. The new_tokens > 0 and new_tokens < original_tokens check prevents zero-estimate or failed compressions from triggering a retry with a broken message list. Implementation note: the len(messages) < original_len branch (message-count reduction) was already unconditional and is unchanged. Only the token-reduction path is relaxed.
13 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The 413 payload-too-large and context-overflow handlers in
conversation_loop.pyboth require ≥5% estimated token reduction before retrying after compression. A genuine 3–4% reduction may be exactly what is needed to fit within the provider's limit, and the current gate causes a terminal failure unnecessarily.Root cause
The 5% threshold (
original_tokens * 0.95) existed as a loop-progress guard, butmax_compression_attempts = 3(line 1087) already provides an absolute upper bound, making the percentage gate redundant.Fix
Remove the
* 0.95multiplier on all three sites (lines 3369, 3592, 3595), accepting any positive token reduction. Thenew_tokens > 0 and new_tokens < original_tokenscheck prevents zero-estimate or failed compressions from triggering a retry with a broken message list.The
len(messages) < original_lenbranch (message-count reduction) was already unconditional and is unchanged.Safety
max_compression_attempts = 3bounds the retry loop absolutelynew_tokens > 0check)Changes
agent/conversation_loop.py* 0.95at lines 3369, 3592, 3595)Tests
tests/run_agent/test_infinite_compaction_loop.py: 14/14 passed ✅Closes #59587