fix(compression): break the protected-tail dead-end on oversized messages - #69830
Merged
Conversation
After multiple in-place compactions, short tool-heavy sessions can leave nearly every remaining message inside protect_last_n while those messages are huge completed file/tool outputs. The middle compress window then makes no material token progress and the turn dies with "Cannot compress further" (#61932). Cap the prune message floor at the same bound as tail-cut, and under pressure demote bulky protected-tail tool bodies (keeping a short recent floor) so preflight can reclaim headroom without wiping the active ask.
…ressible Regression test for the exact issue #61932 report: head + an 8-message protected tail made exclusively of oversized tool pairs. Pre-fix, compress_start >= compress_end made compress() a pure no-op and the retry loop ended in 'Cannot compress further'; post-fix the Phase-1 pressure demotion reclaims the tail in one pass while preserving tool_call/tool_result pairing.
Contributor
૮ >ﻌ< ა ci reviewran on 7cf254d all good! |
This was referenced Jul 23, 2026
fix(compaction): let tail token budget override the message-count floor on pathological tails
#67108
Closed
teknium1
added a commit
that referenced
this pull request
Jul 23, 2026
…oactive prune Follow-ups on top of the cherry-picked #62644 mechanism, porting it to current main and closing the salvage-review requirements: - proactive_prune_min_reclaim_tokens (default 4096): a prune only COMMITS when it reclaims a meaningful token batch, measured on the pruned output. A committed prune rewrites already-sent history and invalidates the provider prompt-cache prefix; this hysteresis gate keeps those breaks episodic/amortized (like a compression boundary) instead of firing every tool iteration. 0 disables the gate. (Design point credited to the #62389 review cycle's prune_minimum_tokens.) - Standard no-op caller contract: every skip path returns the INPUT list object; the loop commits only on 'result is not messages' + non-zero count. - Loop call is getattr+callable guarded (plugin engines predating the hook, SimpleNamespace test doubles) and exception-swallowed at debug level. - Config parse follows the compression.max_attempts hardened semantics: booleans rejected, fractional floats rejected, integral floats/numeric strings accepted; negative trigger = disabled. - cli-config.yaml.example documented (all three keys) and gateway _CACHE_BUSTING_CONFIG_KEYS extended so hot-reload rebuilds the agent. - Tests: min-reclaim gate both directions, input-object no-op contract, no-orphan tool_call_id pairing in BOTH directions (#69830 pin rule), default-off zero-behavior-change pin, config parse seam, and behavioral loop-wiring tests (consulted/commit/no-op/absent-method/raising).
teknium1
added a commit
that referenced
this pull request
Jul 23, 2026
…oactive prune Follow-ups on top of the cherry-picked #62644 mechanism, porting it to current main and closing the salvage-review requirements: - proactive_prune_min_reclaim_tokens (default 4096): a prune only COMMITS when it reclaims a meaningful token batch, measured on the pruned output. A committed prune rewrites already-sent history and invalidates the provider prompt-cache prefix; this hysteresis gate keeps those breaks episodic/amortized (like a compression boundary) instead of firing every tool iteration. 0 disables the gate. (Design point credited to the #62389 review cycle's prune_minimum_tokens.) - Standard no-op caller contract: every skip path returns the INPUT list object; the loop commits only on 'result is not messages' + non-zero count. - Loop call is getattr+callable guarded (plugin engines predating the hook, SimpleNamespace test doubles) and exception-swallowed at debug level. - Config parse follows the compression.max_attempts hardened semantics: booleans rejected, fractional floats rejected, integral floats/numeric strings accepted; negative trigger = disabled. - cli-config.yaml.example documented (all three keys) and gateway _CACHE_BUSTING_CONFIG_KEYS extended so hot-reload rebuilds the agent. - Tests: min-reclaim gate both directions, input-object no-op contract, no-orphan tool_call_id pairing in BOTH directions (#69830 pin rule), default-off zero-behavior-change pin, config parse seam, and behavioral loop-wiring tests (consulted/commit/no-op/absent-method/raising).
teknium1
added a commit
that referenced
this pull request
Jul 23, 2026
…oactive prune Follow-ups on top of the cherry-picked #62644 mechanism, porting it to current main and closing the salvage-review requirements: - proactive_prune_min_reclaim_tokens (default 4096): a prune only COMMITS when it reclaims a meaningful token batch, measured on the pruned output. A committed prune rewrites already-sent history and invalidates the provider prompt-cache prefix; this hysteresis gate keeps those breaks episodic/amortized (like a compression boundary) instead of firing every tool iteration. 0 disables the gate. (Design point credited to the #62389 review cycle's prune_minimum_tokens.) - Standard no-op caller contract: every skip path returns the INPUT list object; the loop commits only on 'result is not messages' + non-zero count. - Loop call is getattr+callable guarded (plugin engines predating the hook, SimpleNamespace test doubles) and exception-swallowed at debug level. - Config parse follows the compression.max_attempts hardened semantics: booleans rejected, fractional floats rejected, integral floats/numeric strings accepted; negative trigger = disabled. - cli-config.yaml.example documented (all three keys) and gateway _CACHE_BUSTING_CONFIG_KEYS extended so hot-reload rebuilds the agent. - Tests: min-reclaim gate both directions, input-object no-op contract, no-orphan tool_call_id pairing in BOTH directions (#69830 pin rule), default-off zero-behavior-change pin, config parse seam, and behavioral loop-wiring tests (consulted/commit/no-op/absent-method/raising).
This was referenced Aug 9, 2026
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
…oactive prune Follow-ups on top of the cherry-picked NousResearch#62644 mechanism, porting it to current main and closing the salvage-review requirements: - proactive_prune_min_reclaim_tokens (default 4096): a prune only COMMITS when it reclaims a meaningful token batch, measured on the pruned output. A committed prune rewrites already-sent history and invalidates the provider prompt-cache prefix; this hysteresis gate keeps those breaks episodic/amortized (like a compression boundary) instead of firing every tool iteration. 0 disables the gate. (Design point credited to the NousResearch#62389 review cycle's prune_minimum_tokens.) - Standard no-op caller contract: every skip path returns the INPUT list object; the loop commits only on 'result is not messages' + non-zero count. - Loop call is getattr+callable guarded (plugin engines predating the hook, SimpleNamespace test doubles) and exception-swallowed at debug level. - Config parse follows the compression.max_attempts hardened semantics: booleans rejected, fractional floats rejected, integral floats/numeric strings accepted; negative trigger = disabled. - cli-config.yaml.example documented (all three keys) and gateway _CACHE_BUSTING_CONFIG_KEYS extended so hot-reload rebuilds the agent. - Tests: min-reclaim gate both directions, input-object no-op contract, no-orphan tool_call_id pairing in BOTH directions (NousResearch#69830 pin rule), default-off zero-behavior-change pin, config parse seam, and behavioral loop-wiring tests (consulted/commit/no-op/absent-method/raising).
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
Breaks the #61932 "Cannot compress further" dead-end: when the protected tail (token budget + the 8-message floor) alone holds oversized recent messages,
compress_start >= compress_endmade every compression pass a pure no-op — the transcript stayed over the context window and the retry loop exhausted. Root cause:_prune_old_tool_resultspassed the uncappedprotect_last_n(default 20) into the prune boundary while tail-cut already bounds it at_MAX_TAIL_MESSAGE_FLOOR, and there was no path at all that could shrink oversized tool bodies inside the protected region.Changes
agent/context_compressor.py:_MAX_TAIL_MESSAGE_FLOOR(same bound tail-cut already uses at_find_tail_cut_by_tokens), so a defaultprotect_last_n=20cannot freeze a bulky recent tool run against pruning.tail_token_budget * 1.5), demote large completed tool/file bodies inside that region — oldest first, keeping a_PRESSURE_KEEP_RECENT_MESSAGES=3recent floor and the active user ask verbatim. Escalation demotes everything except the single newest tool body; absolute last resort summarizes even that (one 200KB read can exceed the soft budget alone). Demotion rewritescontentin place and never touchestool_call_ids, so tool_call/tool_result pairing is preserved._demote_tool_result_at/_truncate_tool_call_args_athelpers reused by the pressure pass (behavior unchanged outside pressure).tests/agent/test_protected_tail_pressure_61932.py: contributor's 5 tests (pressure demotion, last-resort branch incl. the sweeper-requestedtool_call_idassertion, full-compress escape, light-tail no-op) + a new regression test pinning the exact [Regression]: auto-compression still reaches Cannot compress further when protected recent tail is large (Desktop/openai-codex) #61932 dead-end shape: head + an 8-message all-oversized tail that previously returned unchanged now compresses below the context window in one pass, with no orphaned tool calls/results.Validation
bash scripts/run_tests.sh tests/agent/ -q -k 'tail or oversized'tests/agent/test_protected_tail_pressure_61932.pytests/agent/test_context_compressor.py+ tool-pruning siblingsCredit
Salvaged from #61952 by @giggling-ginger (first submitted Jul 10) — cherry-picked with authorship preserved. Independent approaches to the same bug class, credited: #68377 by @trac3r00 (hard head+tail char cap on tail tool results), #67108 by @Kenmege (tail token budget hard-ceiling override of the message-count floor), #43311 by @josenaicipa (pre-compaction tool-output truncation subsystem for huge tool logs). #61952 was chosen as the base for its correct scoping (targets the exact protected-tail no-op path, data-preserving summaries via
_summarize_tool_result, keeps the active ask verbatim) and its earliest submission.Fixes #61932.
Infographic