feat: make context compaction preserve recent turns - #7682
Conversation
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the detailed compaction work. The title-level recent-turn problem has since been addressed on current main by aec38855b5792e4a912d527b64df1a43cbf09c90 (fix(agent): preserve recent turns during compression), which added a bounded preserved tail and regression coverage in tests/agent/test_context_compressor.py:2517.
Problems
- The proposed per-request
_prepare_messages_for_request()call (run_agent.py, diff RIGHT line 7793) prunes retained history before every API request. That mutates the cached prefix outside the current full-compaction path (agent/conversation_loop.py:1007-1058), conflicting with the prompt-cache invariant inAGENTS.md:19-23. compression.protect_recent_nis added (hermes_cli/config.py, diff RIGHT line 357) without corresponding tests or documentation, despite compression settings being documented inwebsite/docs/user-guide/configuration.md:737-745.
Suggested changes
- Use the merged bounded-tail behavior as the baseline and scope any remaining micro/heavy-compaction idea as a cache-safe compression design on current main.
- Add end-to-end coverage for config propagation and user/assistant/tool-group preservation before introducing a separate floor.
Automated hermes-sweeper review.
| @@ -7741,6 +7793,11 @@ def run_conversation( | |||
| # Note: Reasoning is embedded in content via <think> tags for trajectory storage. | |||
There was a problem hiding this comment.
This runs a history-mutating tool-result prune before every model request, not only at an explicit compression boundary. That invalidates the cached conversation prefix during the tool loop; please keep retained-message mutation within the full compaction path, with its session/cache bookkeeping.
|
Thanks @BestLemoon — this PR correctly identified the preserve-recent-turns gap before it was fixed on main. Where each piece stands now:
Closing as superseded — credit for early identification of the recent-turn loss problem. Thanks for the contribution! |
Summary
protect_recent_nfloor so the newest turns stay verbatim during compactionTesting