Skip to content

fix(agent): stop reference-only compaction handoff from becoming the active turn - #80696

Closed
HexLab98 wants to merge 2 commits into
NousResearch:mainfrom
HexLab98:fix/80622-compaction-handoff-active-turn
Closed

fix(agent): stop reference-only compaction handoff from becoming the active turn#80696
HexLab98 wants to merge 2 commits into
NousResearch:mainfrom
HexLab98:fix/80622-compaction-handoff-active-turn

Conversation

@HexLab98

@HexLab98 HexLab98 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • After a completed assistant stop, a standalone [CONTEXT COMPACTION — REFERENCE ONLY] role=user handoff could become the sole active user turn and resume stale Historical Task Snapshot work with no new human ask (Regression: reference-only compaction handoff can become the active turn and resume completed work #80622).
  • Guard post-compaction loop continues so a reference-only handoff never drives the next model call by itself; restore a pending real user message when one exists; always hide standalone handoffs from retry/undo/session dispatch.
  • Harden SUMMARY_PREFIX for the empty-after-handoff case and freeze the prior prefix for resume renormalization.

Test plan

  • scripts/run_tests.sh tests/agent/test_reference_handoff_active_turn.py tests/agent/test_summary_prefix_semantics.py tests/agent/test_resume_stale_active_task.py tests/agent/test_summary_prefix_tool_use.py
  • scripts/run_tests.sh tests/agent/test_compressed_summary_metadata.py tests/agent/test_summary_role_template_alternation.py tests/run_agent/test_compression_boundary_hook.py tests/run_agent/test_compression_persistence.py
  • Reproduce locally: complete a long tool-calling turn (finish_reason=stop), trigger compaction with no follow-up user message, confirm no new tool-calling turn starts from the handoff alone
  • With a real user message pending across compaction, confirm that message remains outside the summary and drives the next response

Fixes #80622

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/tui Terminal UI (ui-tui/ + tui_gateway/) area/compression Context compression and continuation sessions sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Aug 7, 2026
…active turn

After a completed assistant stop, a standalone CONTEXT COMPACTION handoff
could occupy the sole user slot and resume stale Historical Task Snapshot
work with no new human ask. Guard post-compaction continues, hide
standalone handoffs from session dispatch, and harden SUMMARY_PREFIX for
the empty-after-handoff case (NousResearch#80622).
Pin NousResearch#80622 invariants: handoff alone must not drive a model call after
stop, pending real users are restored, and synthetic compaction rows are
never treated as user-originated turns. Also give micro-compaction
enough passes to pay back the longer SUMMARY_PREFIX marker overhead.
@HexLab98
HexLab98 force-pushed the fix/80622-compaction-handoff-active-turn branch from 226c14b to 8debae3 Compare August 7, 2026 01:40
kshitijk4poor added a commit that referenced this pull request Aug 7, 2026
…ordering, prompt carve-out, honest skip response

Follow-ups on top of the salvaged #80696 fix (review findings):

- Sibling sites: rollback.restore, gateway /retry, CLI /retry and /undo N,
  and both CLI resume turn counters now use is_user_originated_turn so
  legacy-persisted standalone handoffs (durable role=user, no display_kind)
  can never be truncation targets or counted as user turns (#80622
  suggested regression 4, dispatcher-wide).
- Site-1 guard: hoist the api_call_count decrement + iteration-budget
  refund above the break so a skipped turn no longer leaks a budget unit
  and finalize_turn logs the true call count (matches the ollama early-exit
  and the site-2 sibling).
- Site-2 guard: run the handoff guard BEFORE reanchoring so a restored
  user ask is what the anchor lands on, not a stale pre-restore index.
- SUMMARY_PREFIX: add the mid-tool-loop carve-out the code-side guard
  already implements, so a literal-minded model doesn't halt an in-flight
  exchange after in-place compaction.
- Skip path returns a short compaction status instead of replaying the
  previous turn's answer (finalize_turn would append it as a fresh
  assistant row — duplicate prose in transcript and delivery).
@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Merged via #81070 — both your commits were cherry-picked onto current main with your authorship preserved (rebase-merge), plus two follow-up commits from review: finishing the bug class at 5 more dispatcher sibling sites (rollback.restore, gateway /retry, CLI /retry + /undo, resume counters), refund ordering at guard site 1, a mid-tool-loop carve-out in the new SUMMARY_PREFIX clause, and DB-picker parity in list_recent_user_messages for legacy-persisted handoffs. Thanks for the thorough fix and the byte-frozen prefix generation — that mechanism made the prompt hardening safe to extend.

ma1138569845 pushed a commit to ma1138569845/dechnicAuditor-agent that referenced this pull request Aug 10, 2026
…tes, refund ordering, prompt carve-out, honest skip response

Follow-ups on top of the salvaged NousResearch#80696 fix (review findings):

- Sibling sites: rollback.restore, gateway /retry, CLI /retry and /undo N,
  and both CLI resume turn counters now use is_user_originated_turn so
  legacy-persisted standalone handoffs (durable role=user, no display_kind)
  can never be truncation targets or counted as user turns (NousResearch#80622
  suggested regression 4, dispatcher-wide).
- Site-1 guard: hoist the api_call_count decrement + iteration-budget
  refund above the break so a skipped turn no longer leaks a budget unit
  and finalize_turn logs the true call count (matches the ollama early-exit
  and the site-2 sibling).
- Site-2 guard: run the handoff guard BEFORE reanchoring so a restored
  user ask is what the anchor lands on, not a stale pre-restore index.
- SUMMARY_PREFIX: add the mid-tool-loop carve-out the code-side guard
  already implements, so a literal-minded model doesn't halt an in-flight
  exchange after in-place compaction.
- Skip path returns a short compaction status instead of replaying the
  previous turn's answer (finalize_turn would append it as a fresh
  assistant row — duplicate prose in transcript and delivery).
randlee pushed a commit to randlee/hermes-agent that referenced this pull request Aug 11, 2026
…tes, refund ordering, prompt carve-out, honest skip response

Follow-ups on top of the salvaged NousResearch#80696 fix (review findings):

- Sibling sites: rollback.restore, gateway /retry, CLI /retry and /undo N,
  and both CLI resume turn counters now use is_user_originated_turn so
  legacy-persisted standalone handoffs (durable role=user, no display_kind)
  can never be truncation targets or counted as user turns (NousResearch#80622
  suggested regression 4, dispatcher-wide).
- Site-1 guard: hoist the api_call_count decrement + iteration-budget
  refund above the break so a skipped turn no longer leaks a budget unit
  and finalize_turn logs the true call count (matches the ollama early-exit
  and the site-2 sibling).
- Site-2 guard: run the handoff guard BEFORE reanchoring so a restored
  user ask is what the anchor lands on, not a stale pre-restore index.
- SUMMARY_PREFIX: add the mid-tool-loop carve-out the code-side guard
  already implements, so a literal-minded model doesn't halt an in-flight
  exchange after in-place compaction.
- Skip path returns a short compaction status instead of replaying the
  previous turn's answer (finalize_turn would append it as a fresh
  assistant row — duplicate prose in transcript and delivery).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/compression Context compression and continuation sessions comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/tui Terminal UI (ui-tui/ + tui_gateway/) 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.

Regression: reference-only compaction handoff can become the active turn and resume completed work

3 participants