fix(agent): focus automatic compression on recent user turns#38155
Closed
konsisumer wants to merge 1 commit into
Closed
fix(agent): focus automatic compression on recent user turns#38155konsisumer wants to merge 1 commit into
konsisumer wants to merge 1 commit into
Conversation
alaamohanad169-ship-it
approved these changes
Jun 3, 2026
alaamohanad169-ship-it
left a comment
Contributor
There was a problem hiding this comment.
Nice approach — auto-deriving focus from recent user turns instead of requiring explicit /compress focus is a solid DX improvement. Particularly useful for terminal-heavy workflows where most of the session is tool output but the active task is usually captured in the last 2-3 user messages.
The 260/700/3 constants seem like sensible defaults for catching the active task without pulling in stale context. If the user runs long complex sessions they can increase them.
One nit: the tail_start parameter is reserved but unused — consider removing it from the signature since compress() already has the boundary knowledge.
Contributor
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?
Automatic context compression now derives a compact focus hint from the latest real user turns when no manual focus topic is supplied. That hint is passed into the existing summary prompt so iterative compactions preserve the current task/topic more strongly and demote stale completed topics.
Related Issue
Fixes #9631
Addressing maintainer feedback
#10088 - maintainer-referenced partial mitigation/template work. The current branch already contains the described template improvements (
Completed Actions,Active State, and stronger iterative-summary instructions); this PR builds on that by adding the missing automatic focus derivation path for ordinary auto-compactions.Type of Change
Changes Made
agent/context_compressor.py: derives an automaticRecent user focushint from the latest real user turns, skips persisted summary handoff messages, redacts sensitive text, and passes the hint into summary generation when no explicit focus topic is provided.tests/agent/test_compress_focus.py: updates default-focus expectations and covers skipping stale context-summary handoff content.How to Test
pytest tests/agent/test_compress_focus.py -q- passes (5 passed).pytest tests/agent/test_context_compressor_summary_continuity.py -q- passes (3 passed).ruff check agent/context_compressor.py tests/agent/test_compress_focus.py- passes.python scripts/check-windows-footguns.py agent/context_compressor.py tests/agent/test_compress_focus.py- passes.git diff --check- passes.scripts/run_tests.sh- ran the broad suite, but exited non-zero locally with unrelated sandbox/environment failures across other modules (27375 passed,781 failed). Representative failures include restricted socket binds, denied writes under~/.hermes, live-system guard blocks around process-signal tests, and optional SDK import timeouts.Checklist
scripts/check-windows-footguns.pypassed for changed files)Screenshots / Logs
N/A - agent compression behavior change only.