fix(agent): prevent infinite compression loop when aux model context is too small (#53008) - #57102
Closed
bone-bone-bone wants to merge 1 commit into
Closed
Conversation
…is too small (NousResearch#53008) When the auxiliary compression model's context window is smaller than the main model's compression threshold, the threshold is unconditionally set to aux_context. If the session has already grown beyond that size, compression becomes nearly worthless yet triggers every turn, creating an infinite loop. Two changes: 1. conversation_compression.py: apply 80% safety margin on aux_context (the summarisation prompt template consumes part of the context) 2. turn_context.py: after the 3-pass preflight compression loop, check actual token reduction. If <10% and tokens still exceed threshold, auto-raise threshold to break the cycle. See NousResearch#53008 for full analysis.
Collaborator
Competing with #53235 for the same issue (#53008). This PR is a 2-file subset (conversation_compression.py 80% margin + turn_context.py anti-loop threshold guard); #53235 is broader (adds a proactive main-model fallback in context_compressor.py plus tests) and appears canonical. Same goal, different mechanism — flagging for a maintainer to pick. |
3 tasks
Contributor
|
Thanks for investigating the compression-loop failure mode. This is an automated hermes-sweeper review. Current
The member discussion identified #53235 as the broader competing approach; its current-main anti-thrash guarantee now supersedes this PR's threshold-escape guard. |
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 #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.