fix(agent+gateway): break infinite context compression loop by persis… - #29505
Closed
LifeJiggy wants to merge 1 commit into
Closed
fix(agent+gateway): break infinite context compression loop by persis…#29505LifeJiggy wants to merge 1 commit into
LifeJiggy wants to merge 1 commit into
Conversation
LifeJiggy
force-pushed
the
fix/context-compression-loop
branch
from
May 21, 2026 02:20
1495303 to
096d0c7
Compare
zombi3butt
pushed a commit
to zombi3butt/hermes-agent
that referenced
this pull request
May 21, 2026
…onversation (issue NousResearch#29926) When auto-compression rotates the session mid-run, result["messages"] contains the inflated post-turn list (compressed baseline + this turn's growth). The CLI was overwriting conversation_history with this inflated list, causing the next turn to start from 130K+ tokens instead of the compressed ~24K baseline — wasting VRAM and API time. Fix: detect session rotation via _cli_last_run_old_session_id (captured before run_conversation in the agent thread) and use agent._session_messages instead of result["messages"] when rotation occurred. Falls back to result["messages"] for normal (non-rotated) runs. Mirrors the gateway path fix in PR NousResearch#29505.
zombi3butt
pushed a commit
to zombi3butt/hermes-agent
that referenced
this pull request
May 21, 2026
…onversation (issue NousResearch#29926) When auto-compression rotates the session mid-run, result["messages"] contains the inflated post-turn list (compressed baseline + this turn's growth). The CLI was overwriting conversation_history with this inflated list, causing the next turn to start from 130K+ tokens instead of the compressed ~24K baseline — wasting VRAM and API time. Fix: detect session rotation via _cli_last_run_old_session_id (captured before run_conversation in the agent thread) and use agent._session_messages instead of result["messages"] when rotation occurred. Falls back to result["messages"] for normal (non-rotated) runs. Mirrors the gateway path fix in PR NousResearch#29505.
This was referenced May 25, 2026
LifeJiggy
force-pushed
the
fix/context-compression-loop
branch
from
May 26, 2026 12:54
096d0c7 to
2660d3a
Compare
Contributor
Author
|
@teknium1 PTAL |
…urability Tests (24 new): - Anti-thrashing protection blocks after 2 ineffective compressions - session_id and compression_loop_count in result dict - Gateway session_store._save() and Telegram topic binding sync - Preflight pass limit and savings tracking Enhancements: 1. compression_loop_count in result dict — observability metric showing how many preflight compression passes ran this turn 2. Configurable compression.max_preflight_passes (default 3) — replaces hardcoded range(3) in preflight loop 3. Anti-thrashing warning dedup — _anti_thrash_warning_emitted flag prevents repeated warnings within a turn; resets on good compression
LifeJiggy
force-pushed
the
fix/context-compression-loop
branch
from
June 9, 2026 05:19
2660d3a to
ce162c9
Compare
Contributor
Author
|
Tests added (tests/agent/test_compression_loop_fix.py — 24 tests):
3 Enhancements:
|
Contributor
|
Closing as superseded by the compression split fix that landed in PR #45529: That merged change now syncs compression-created session IDs before failed/no-final-response paths can return, resets the history offset for split failures, and refreshes the Telegram topic binding on the rotated child session. Thanks for the fix/report — the payload here is now covered on current main. |
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.
Title: fix(agent+gateway): break infinite context compression loop by persisting rotated session ID
Summary
Three-part fix for the infinite context compression loop that occurs when
compression creates a new session but the gateway never learns about it:
Preflight anti-thrashing (
agent/conversation_loop.py): Useshould_compress()in preflight check instead of raw>= threshold_tokenscomparison, so the ineffective-compression guard prevents repeated
compression passes when system prompt overhead dominates.
Session ID return (
agent/conversation_loop.py): Includesession_idin therun_conversation()result dict so the gatewaycan detect when compression rotated the session.
Persist rotation (
gateway/run.py): Callsession_store._save()after updating
session_entry.session_idso the change survivesgateway restarts and session reloads.
Changes
agent/conversation_loop.py:442should_compress()guard to preflightagent/conversation_loop.py:3999session_idto result dictgateway/run.py:8512-8513_save()Fixes #29335