fix(agent): keep compaction summaries as user role (#42768) - #42830
fix(agent): keep compaction summaries as user role (#42768)#42830Tranquil-Flow wants to merge 1 commit into
Conversation
dd374ad to
7b29a5b
Compare
|
✅ Verified — Compaction summary role simplification looks solid Reviewed the full diff across Changes verified:
No issues found. The simplification removes ~40 lines of complex role-collision logic while making the behavior more predictable. Clean contribution. |
|
Thanks for the thorough writeup and competitor comparison, Evi — the root-cause analysis on both bugs was correct. Closing this as superseded / already fixed on
Really appreciate the contribution and the honest scoring of the competing PRs — the diagnosis here directly matches what shipped. 🙏 |
What changed
Fixes #42768 by making context compaction handoff summaries consistently behave as user-provided background context instead of assistant output.
role="user".--- END OF CONTEXT SUMMARY ... ---marker, closing the assistant-role path left uncovered by fix(compaction): mark end of context summary in role=user fallback (salvage #17121) #20169.Why
The issue reports sessions where compaction summaries leaked into chat as visible assistant responses. The root cause is that the old role-alternation logic could select or merge the handoff into an assistant message. Some models then treated that handoff as their own prior output and echoed it verbatim, causing repeated compaction loops.
The safer invariant is: compaction handoffs are background context from the user side, never assistant output. Consecutive same-role user messages are tolerated by supported providers and are less dangerous than representing the handoff as an assistant response.
Competitor check
Open competing PRs were reviewed before publication:
agent/context_compressor.pyand attempts both production changes, but has no regression tests and still merges summaries into the tail when the head isuser, which can place summary text inside an assistant tail message. Score: 5/10.This PR covers both reported layers with regression tests.
Verification
Run locally from the worktree with Python 3.11:
/Users/evinova-self/.hermes/hermes-agent/venv/bin/python3 -m pytest tests/agent/test_context_compressor.py -v -o "addopts=" --tb=shortResult:
97 passed, 1 warning in 3.77s.Auto-published by Moonsong via Path B automated pipeline.