fix(agent): honor protect_last_n (capped) as the compaction tail floor (salvages #39170) - #45259
Merged
Merged
Conversation
Contributor
🔎 Lint report:
|
23 tasks
8 tasks
yingliang-zhang
added a commit
to yingliang-zhang/hermes-agent
that referenced
this pull request
Aug 20, 2026
PR NousResearch#45259 hardened the compaction tail floor from a fixed 3 to min(protect_last_n, 8). The cap of 8 was chosen to avoid preserving a whole run of bulky tool outputs on every compaction, but it is not configurable — users with large context windows and light tails (e.g. 340K context, protect_last_n=20) cannot raise it beyond 8, causing recent assistant replies to be summarized away even when plenty of context budget remains. This adds a compression.max_tail_message_floor config key (default 0 = use the module-level default of 8, preserving backward compatibility). Set it higher (e.g. 20) to keep more recent messages verbatim during compaction at the cost of a smaller summarization window when tool outputs are bulky. Changes: - agent/context_compressor.py: rename _MAX_TAIL_MESSAGE_FLOOR to _DEFAULT_MAX_TAIL_MESSAGE_FLOOR, add max_tail_message_floor ctor param + _effective_max_tail_message_floor property, use it in _should_compact instead of the module-level constant. - agent/agent_init.py: read compression.max_tail_message_floor from config and pass it to ContextCompressor. - hermes_cli/config.py: add max_tail_message_floor to the compression config section. - tests/agent/test_context_compressor.py: test the configurable floor.
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 tail-protection floor during compaction is now
max(3, min(protect_last_n, 8))messages instead of a hard 3 — so a compaction can no longer shave the conversation down to just 3 verbatim recent messages when the user'sprotect_last_nconfig promised more (#39170).Changes
agent/context_compressor.py:_find_tail_cut_by_tokensmin_tail floor honorsprotect_last_nup to a_MAX_TAIL_MESSAGE_FLOOR = 8cap (full 20 would resurrect the oversized-tool-output "nothing compactable" case); short transcripts keep ≥2 compressible non-head messages so compression never runs as a no-optests/agent/test_context_compressor.py: +34 lines of floor/cap regression testsToken budget remains primary: the 1.5x soft ceiling still wins, and the cut still falls back to right-after-head when even the floor exceeds it. Composes cleanly with the just-merged #45249 assistant-tail anchor (anchors run after this and only grow the tail).
Validation
protect_last_n: 20(default), heavy compaction*4 pre-existing SSL-socket env flakes in test_context_compressor.py reproduce identically on clean origin/main; not introduced here.
Attribution
Salvages #39170 by @konsisumer — cherry-picked with authorship preserved; rebase-merge to keep per-commit credit.
Infographic