Fix auto compression for tool-heavy sessions - #36626
Closed
franksong2702 wants to merge 1 commit into
Closed
Conversation
13 tasks
teknium1
pushed a commit
that referenced
this pull request
Jul 1, 2026
A context-compaction handoff banner is inserted with role="user" when the protected head ends in an assistant/tool message. On a resumed or multi-compaction session, _find_last_user_message_idx would return that banner as the latest user turn, so _ensure_last_user_message_in_tail anchored the tail to the summary and rolled the genuine last user message into the next compaction — the exact active-task loss the anchor exists to prevent (#10896/#22523). Reuse the existing _is_context_summary_content helper to skip summary banners when locating the last real user message. Salvaged from #36626 by Frank Song (issue #36624). The PR's other two changes (demoting completed tool results inside the protected tail; a preflight compression_exhausted result) are superseded on current main by the min_tail floor (#39170), the no-op compression counting (#40803), and the existing 413/disabled terminal-error paths.
Contributor
|
Merged via #56165 — #56165 (commit Salvaged the core fix from this PR: The PR's other two changes were dropped as superseded by work that landed after you opened this:
Thanks for the fix and the clear repro in #36624! |
waefrebeorn
pushed a commit
to waefrebeorn/slermes
that referenced
this pull request
Jul 2, 2026
A context-compaction handoff banner is inserted with role="user" when the protected head ends in an assistant/tool message. On a resumed or multi-compaction session, _find_last_user_message_idx would return that banner as the latest user turn, so _ensure_last_user_message_in_tail anchored the tail to the summary and rolled the genuine last user message into the next compaction — the exact active-task loss the anchor exists to prevent (NousResearch#10896/NousResearch#22523). Reuse the existing _is_context_summary_content helper to skip summary banners when locating the last real user message. Salvaged from NousResearch#36626 by Frank Song (issue NousResearch#36624). The PR's other two changes (demoting completed tool results inside the protected tail; a preflight compression_exhausted result) are superseded on current main by the min_tail floor (NousResearch#39170), the no-op compression counting (NousResearch#40803), and the existing 413/disabled terminal-error paths.
Jasper6439
pushed a commit
to Jasper6439/hermes-agent
that referenced
this pull request
Jul 5, 2026
A context-compaction handoff banner is inserted with role="user" when the protected head ends in an assistant/tool message. On a resumed or multi-compaction session, _find_last_user_message_idx would return that banner as the latest user turn, so _ensure_last_user_message_in_tail anchored the tail to the summary and rolled the genuine last user message into the next compaction — the exact active-task loss the anchor exists to prevent (NousResearch#10896/NousResearch#22523). Reuse the existing _is_context_summary_content helper to skip summary banners when locating the last real user message. Salvaged from NousResearch#36626 by Frank Song (issue NousResearch#36624). The PR's other two changes (demoting completed tool results inside the protected tail; a preflight compression_exhausted result) are superseded on current main by the min_tail floor (NousResearch#39170), the no-op compression counting (NousResearch#40803), and the existing 413/disabled terminal-error paths.
habarmc1223-sudo
pushed a commit
to habarmc1223-sudo/hermes-agent-fluxmem
that referenced
this pull request
Jul 8, 2026
A context-compaction handoff banner is inserted with role="user" when the protected head ends in an assistant/tool message. On a resumed or multi-compaction session, _find_last_user_message_idx would return that banner as the latest user turn, so _ensure_last_user_message_in_tail anchored the tail to the summary and rolled the genuine last user message into the next compaction — the exact active-task loss the anchor exists to prevent (NousResearch#10896/NousResearch#22523). Reuse the existing _is_context_summary_content helper to skip summary banners when locating the last real user message. Salvaged from NousResearch#36626 by Frank Song (issue NousResearch#36624). The PR's other two changes (demoting completed tool results inside the protected tail; a preflight compression_exhausted result) are superseded on current main by the min_tail floor (NousResearch#39170), the no-op compression counting (NousResearch#40803), and the existing 413/disabled terminal-error paths.
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
A context-compaction handoff banner is inserted with role="user" when the protected head ends in an assistant/tool message. On a resumed or multi-compaction session, _find_last_user_message_idx would return that banner as the latest user turn, so _ensure_last_user_message_in_tail anchored the tail to the summary and rolled the genuine last user message into the next compaction — the exact active-task loss the anchor exists to prevent (NousResearch#10896/NousResearch#22523). Reuse the existing _is_context_summary_content helper to skip summary banners when locating the last real user message. Salvaged from NousResearch#36626 by Frank Song (issue NousResearch#36624). The PR's other two changes (demoting completed tool results inside the protected tail; a preflight compression_exhausted result) are superseded on current main by the min_tail floor (NousResearch#39170), the no-op compression counting (NousResearch#40803), and the existing 413/disabled terminal-error paths.
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
A context-compaction handoff banner is inserted with role="user" when the protected head ends in an assistant/tool message. On a resumed or multi-compaction session, _find_last_user_message_idx would return that banner as the latest user turn, so _ensure_last_user_message_in_tail anchored the tail to the summary and rolled the genuine last user message into the next compaction — the exact active-task loss the anchor exists to prevent (NousResearch#10896/NousResearch#22523). Reuse the existing _is_context_summary_content helper to skip summary banners when locating the last real user message. Salvaged from NousResearch#36626 by Frank Song (issue NousResearch#36624). The PR's other two changes (demoting completed tool results inside the protected tail; a preflight compression_exhausted result) are superseded on current main by the min_tail floor (NousResearch#39170), the no-op compression counting (NousResearch#40803), and the existing 413/disabled terminal-error paths.
waym0reom3ga
pushed a commit
to waym0reom3ga/autolycus-agent
that referenced
this pull request
Jul 23, 2026
A context-compaction handoff banner is inserted with role="user" when the protected head ends in an assistant/tool message. On a resumed or multi-compaction session, _find_last_user_message_idx would return that banner as the latest user turn, so _ensure_last_user_message_in_tail anchored the tail to the summary and rolled the genuine last user message into the next compaction — the exact active-task loss the anchor exists to prevent (NousResearch#10896/NousResearch#22523). Reuse the existing _is_context_summary_content helper to skip summary banners when locating the last real user message. Salvaged from NousResearch#36626 by Frank Song (issue NousResearch#36624). The PR's other two changes (demoting completed tool results inside the protected tail; a preflight compression_exhausted result) are superseded on current main by the min_tail floor (NousResearch#39170), the no-op compression counting (NousResearch#40803), and the existing 413/disabled terminal-error paths.
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
A context-compaction handoff banner is inserted with role="user" when the protected head ends in an assistant/tool message. On a resumed or multi-compaction session, _find_last_user_message_idx would return that banner as the latest user turn, so _ensure_last_user_message_in_tail anchored the tail to the summary and rolled the genuine last user message into the next compaction — the exact active-task loss the anchor exists to prevent (NousResearch#10896/NousResearch#22523). Reuse the existing _is_context_summary_content helper to skip summary banners when locating the last real user message. Salvaged from NousResearch#36626 by Frank Song (issue NousResearch#36624). The PR's other two changes (demoting completed tool results inside the protected tail; a preflight compression_exhausted result) are superseded on current main by the min_tail floor (NousResearch#39170), the no-op compression counting (NousResearch#40803), and the existing 413/disabled terminal-error paths.
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
Long single-turn, tool-heavy sessions could repeatedly auto-compress without materially reducing context. Completed tool results in the protected tail could remain large, internal context-compaction markers could be treated like real user anchors, and repeated no-op compression could continue until the provider rejected the oversized context.
This PR makes auto compression fail explicitly when it is exhausted and demotes completed tool results to concise evidence summaries, including completed tool results at the current tail before the next LLM call.
Changes
toolresult bodies to concise evidence summaries even when they sit in the current protected tail.compression_exhausted.Verification
python -m pytest tests/test_auto_compression_tool_heavy_tail.py tests/run_agent/test_1630_context_overflow_loop.py tests/run_agent/test_compression_trigger_excludes_reasoning.py tests/test_ctx_halving_fix.py tests/run_agent/test_compression_persistence.py tests/run_agent/test_compressor_fallback_update.py tests/run_agent/test_compression_boundary.py -qgit diff --checkRelated
Risks / Follow-ups
mainby one commit; no rebase was performed before publishing to avoid changing the already-validated branch state.role=toolmessages; running tools have no result row to summarize.Model Used
AI-assisted implementation with OpenAI GPT-5 Codex in a local coding workflow. The assistant inspected repository code, wrote regression tests, implemented the fix, and ran the verification commands above.