fix(tools): filter compaction summaries from session_search bookends and cap content length - #43184
Closed
liuhao1024 wants to merge 1 commit into
Closed
liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
…and cap content length Context-compaction handoff summaries (prefixed with [CONTEXT COMPACTION]) were being returned as normal bookend_start/bookend_end messages in session_search discovery mode. A single compaction handoff could be 57K+ chars, immediately bloating a fresh session prompt to 73K+ chars from one search hit. Changes: - Add _COMPACTION_PREFIXES and _is_compaction_summary() helper - Filter compaction summaries from bookend_start and bookend_end in _discover() - Cap bookend content to 1200 chars and window content to 4000 chars - Add content_truncated/original_content_chars metadata when truncation occurs - Add 6 regression tests covering prefix detection, bookend filtering, content capping, and legacy [CONTEXT SUMMARY] prefix Fixes NousResearch#43175
19 tasks
19 tasks
teknium1
reviewed
Jul 14, 2026
teknium1
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for targeting a real current-main retrieval bloat path: _discover() still returns unbounded bookends and windows at tools/session_search_tool.py:599-601.
Problems
- The new prefix-only predicate misses merged handoffs. Current compaction explicitly recognizes summaries after
_MERGED_SUMMARY_DELIMITERinagent/context_compressor.py:2261-2270; those messages would still enter bookends. - Current title-match discovery has a separate response construction at
tools/session_search_tool.py:487-489, using unbounded_shape_message()calls. The proposed_discover()change does not cover that path.
Suggested changes
- Centralize bounded, compaction-aware shaping and use it for both normal and title-match discovery results.
- Add tests for merged-summary bookends and a title query resolving to a session with a long handoff.
Automated hermes-sweeper review.
|
|
||
| def _is_compaction_summary(content: str) -> bool: | ||
| """Return True if *content* looks like a generated compaction handoff.""" | ||
| if not content: |
Collaborator
There was a problem hiding this comment.
This only detects a handoff when the prefix begins the message. Current compaction also recognizes merged summaries whose handoff starts after _MERGED_SUMMARY_DELIMITER (agent/context_compressor.py:2261-2270); those can still be returned in bookends. Please cover that merged form as well.
Collaborator
This was referenced Sep 17, 2026
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.
What does this PR do?
Filters context-compaction handoff summaries from
session_searchdiscovery bookends and caps message content length to prevent prompt bloat.Related Issue
Fixes #43175
Type of Change
Changes Made
tools/session_search_tool.py: Add_COMPACTION_PREFIXESconstant and_is_compaction_summary()helper to detect compaction handoff messages. Filter these frombookend_startandbookend_endin_discover(). Cap bookend content to 1200 chars and window message content to 4000 chars via newmax_content_lenparameter on_shape_message(). Addcontent_truncatedandoriginal_content_charsmetadata when truncation occurs.tests/tools/test_session_search.py: Add 6 regression tests — prefix detection, bookend_start filtering, bookend_end filtering, bookend content capping, window content capping, and legacy[CONTEXT SUMMARY]prefix handling.How to Test
pytest tests/tools/test_session_search.py -v— all 52 tests should pass (46 existing + 6 new)[CONTEXT COMPACTION — REFERENCE ONLY]message as the first user message, followed by normal messagessession_search(query=<term in later message>)— the compaction summary should NOT appear inbookend_startcontent_truncated: truemetadataChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/tools/test_session_search.py -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
tools/session_search_tool.py(_discover,_shape_message,_is_compaction_summary)hermes_state.py(get_anchored_view— bookend SQL queries)session_searchscroll mode's existingreadtruncation