fix(agent): close tool-call sequence on all interrupt aborts (#48879 follow-up) - #52592
Merged
Merged
Conversation
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-assignment |
1 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
✅ Fixed issues (2):
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
run_agent.py:2989: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
Unchanged: 5941 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
…t finalize_turn #48879 closed the tool-call sequence on interrupt inside finalize_turn so a /stop after a tool no longer persists a `tool` tail that the next user message turns into a `tool -> user` role-alternation violation (which strict providers like Gemini/Claude react to by hallucinating a continuation and ignoring prior context — what users see as "lost context after stop"). But the retry-wait, error-handling, and post-error retry-wait interrupt aborts in conversation_loop return early and never reach finalize_turn, so they still persisted and returned a raw `tool` tail. Interrupting during provider backoff/rate-limiting (common under heavy work) hit exactly this path. Extract the close into a shared close_interrupted_tool_sequence helper and apply it at every interrupt abort (finalize_turn + the three early returns) so the whole bug class is fixed, not just the one site.
OutThisLife
force-pushed
the
bb/close-interrupt-tool-seq-sibling-paths
branch
from
June 25, 2026 17:24
2eb9e03 to
2d286a6
Compare
OutThisLife
enabled auto-merge
June 25, 2026 17:25
2 tasks
waefrebeorn
pushed a commit
to waefrebeorn/slermes
that referenced
this pull request
Jul 2, 2026
…rrupt-tool-seq-sibling-paths fix(agent): close tool-call sequence on all interrupt aborts (NousResearch#48879 follow-up)
habarmc1223-sudo
pushed a commit
to habarmc1223-sudo/hermes-agent-fluxmem
that referenced
this pull request
Jul 8, 2026
…rrupt-tool-seq-sibling-paths fix(agent): close tool-call sequence on all interrupt aborts (NousResearch#48879 follow-up)
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
…rrupt-tool-seq-sibling-paths fix(agent): close tool-call sequence on all interrupt aborts (NousResearch#48879 follow-up)
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
…rrupt-tool-seq-sibling-paths fix(agent): close tool-call sequence on all interrupt aborts (NousResearch#48879 follow-up)
13 tasks
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
…rrupt-tool-seq-sibling-paths fix(agent): close tool-call sequence on all interrupt aborts (NousResearch#48879 follow-up)
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.
Summary
Bug report: "in profiles, if I send a message, it starts working, I hit stop, and send a new one — it seems to lose context frequently." The attached screenshot shows the agent replying "i dont have context on what 'they' refers 2 or what timing 2 increase" and falling back to a Session Search to recover what it was just doing — classic lost-context-after-stop.
Root cause
This is the #48879 failure mode on sibling code paths. #48879 ("close tool-call sequence on interrupt") added a synthetic assistant turn in
finalize_turnso a/stopafter a tool no longer persists a rawtooltail. Without it, the next user message lands as… tool → user, a role-alternation violation that strict providers (Gemini, Claude) react to by hallucinating a continuation of the user's message and ignoring prior context.But
finalize_turnis not the only interrupt exit. The retry-wait, error-handling, and post-error retry-wait interrupt aborts inagent/conversation_loop.pyreturnearly and never reachfinalize_turn, so they still persisted and returned an unclosedtooltail. Interrupting during provider backoff / rate-limiting (common under heavy work like the CI-timing session in the report) hits exactly these paths — hence "frequently".Fix
close_interrupted_tool_sequence(messages, final_response)inagent/message_sanitization.py.finalize_turn(now delegates to the helper) and the three earlyreturns inconversation_loop.This fixes the whole bug class rather than the one site, per the contribution rubric ("fix the whole bug class — sibling call paths included").
Test plan
tests/agent/test_close_interrupted_tool_sequence.py— pins the helper contract (tool tail closed with placeholder / preserved interrupt text / blank falls back) and the alternation-safety guarantee (appending a next user turn never yieldstool → user); no-ops on assistant/user/empty tails.tests/agent/test_turn_finalizer_interrupt_alternation.pystill green (finalize_turn now routes through the helper).test_stream_interrupt_retry,test_interrupt_propagation,test_turn_finalizer_cleanup_guard,test_message_sequence_repair,test_empty_response_recovery_persistence.