fix(compression): 3-line fix for infinite compression loop (#29335) - #31730
Closed
someaka wants to merge 1 commit into
Closed
fix(compression): 3-line fix for infinite compression loop (#29335)#31730someaka wants to merge 1 commit into
someaka wants to merge 1 commit into
Conversation
…rch#29335) Three compounding root causes: A) run_conversation() result dict missing session_id — gateway's dead-code guard at gateway/run.py:8700 never triggers B) preflight compression bypasses should_compress() anti-thrashing — re-triggers every turn when tool schemas dominate token budget C) gateway updates session_entry.session_id in memory but doesn't persist via session_store._save() Fixes: NousResearch#29335
Collaborator
|
Competing with open PRs #29505 (3-part fix: should_compress() + session_id + _save()), #26204, and #26088 — all fix #29335 (infinite compression loop due to session_id not propagated after compression). Clean replacement of stacked #31725. This PR addresses issues A (session_id not in result dict), B (preflight bypasses anti-thrashing), and C (gateway doesn't persist session_id update). |
Contributor
|
Merged via #31930 — your commit was cherry-picked onto current main with authorship preserved (3914089d5). Thanks for the fix and the clean root-cause writeup! Follow-up commit (11c40d6a4) on top:
Closes #29335. |
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 context compression fires, three compounding issues cause an infinite compression loop:
Issue A — session_id not propagated
_compress_context()updatesself.session_idto the new session, butrun_conversation()never includessession_idin its return dict. The gateway atgateway/run.py:8700has a guard but it's dead code — the agent never sendssession_id.Issue B — preflight bypasses anti-thrashing
Preflight compression uses a raw threshold comparison, bypassing
should_compress()which has anti-thrashing logic. When system prompt + tool schemas dominate token count, compressing messages doesn't bring total below threshold — preflight re-triggers every turn despite saving <10%.Issue C — gateway doesn't persist session_id update
Gateway updates
session_entry.session_idin memory but doesn't callsession_store._save(). Two other compression paths in the same file DO persist — this one was missed.Fix — 4 lines, 2 files
Fixes: #29335