Skip to content

fix(compressor): skip context-summary markers as last-user tail anchor - #56165

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-e6f6b24d
Jul 1, 2026
Merged

fix(compressor): skip context-summary markers as last-user tail anchor#56165
teknium1 merged 1 commit into
mainfrom
hermes/hermes-e6f6b24d

Conversation

@teknium1

@teknium1 teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Context compaction no longer mistakes its own handoff banner for the latest user turn. A [CONTEXT COMPACTION — REFERENCE ONLY] summary 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 returned that banner as the "latest user message", so _ensure_last_user_message_in_tail anchored the tail to the summary and rolled the genuine last user turn into the next compaction — the exact active-task loss the anchor exists to prevent (#10896 / #22523).

Root cause: _find_last_user_message_idx returned any role="user" message. The fix reuses the existing _is_context_summary_content helper (already used by _find_latest_context_summary and the summarizer serialization) to skip summary banners.

Changes

  • agent/context_compressor.py: _find_last_user_message_idx skips context-summary markers when locating the last real user turn.
  • tests/agent/test_compressor_assistant_tail_anchor.py: adds TestFindLastUserMessageIdxSkipsSummaryMarker (skips user-role summary; returns real user when no summary; -1 when all user messages are summaries).

Validation

Before After
last-user anchor with a user-role summary banner present anchors to the summary → real user rolled into compaction (task loss) anchors to the real user turn → protected in tail
targeted tests 24/24 test_compressor_assistant_tail_anchor.py green
compression suites 139/139 (test_context_compressor.py + test_compression_boundary.py) green
E2E fixed path anchors real user (idx 2); simulated old path anchors summary (idx 4)

Salvage note

Salvaged from #36626 by Frank Song (issue #36624), authorship preserved. The PR's other two proposed changes are superseded on current main and were intentionally dropped:

Infographic

Context compaction tail-anchor fix

— Nous Research

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.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P1 High — major feature broken, no workaround labels Jul 1, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Salvage of #36626 (issue #36624) by Frank Song — related, not a duplicate. Related to the compaction tail-anchor family: merged #45249 and closed #29862.

@teknium1
teknium1 merged commit ee710db into main Jul 1, 2026
31 checks passed
@teknium1
teknium1 deleted the hermes/hermes-e6f6b24d branch July 1, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P1 High — major feature broken, no workaround sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants