fix(agent): prevent infinite compression loop when aux model context is too small (#53008) - #885
Open
hashbender wants to merge 1 commit into
Open
fix(agent): prevent infinite compression loop when aux model context is too small (#53008)#885hashbender wants to merge 1 commit into
hashbender wants to merge 1 commit into
Conversation
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.
Problem
When the auxiliary compression model has a context window smaller than the
main model's compression threshold,
check_compression_model_feasibility()unconditionally lowers
threshold_tokenstoaux_context— the aux model'sraw context size. This causes an infinite compression loop when:
205K tokens vs 131K aux context)
effective (205K → 204K)
_compression_made_progress()sees "2 fewer messages" as progress,letting the 3-pass loop continue
User-facing symptoms:
See NousResearch#53008 for full analysis and reproduction details.
Fix (2 files, +32/−7)
1.
agent/conversation_compression.py— safety marginReplace
new_threshold = aux_contextwithint(aux_context * 0.8).The summarisation prompt template consumes part of the aux model's
context window, so using the raw context size can overflow it.
2.
agent/turn_context.py— anti-loop guardAfter the 3-pass compression loop, check if token reduction was
material. If reduction < 10% and tokens still exceed the threshold,
auto-raise the threshold to break the cycle:
This is a last-resort guard: if compression is so ineffective that
every turn re-triggers it without making progress, the threshold
self-corrects.
Verification
A standalone reproduction script simulates the exact threshold-adjustment,
progress-check, and preflight-loop logic from the codebase:
Checklist
aux_context * 0.8stays aboveMINIMUM_CONTEXT_LENGTH(64K)for any aux model ≥ 80K context. Lower models already fail the hard
floor check earlier.
length (implicit via
should_compress→context_lengthcomparison).aux_context >= threshold→ no code path entered.Mirror-of: NousResearch#57102
NousResearch#57102