fix(agent): skip completion notification for killed processes (#36184) - #36210
Open
annguyenNous wants to merge 1 commit into
Open
fix(agent): skip completion notification for killed processes (#36184)#36210annguyenNous wants to merge 1 commit into
annguyenNous wants to merge 1 commit into
Conversation
When a user cancels a background process (says "no need" and the agent kills it), the process may still complete before the SIGTERM lands. The watcher then injects a completion notification, causing the agent to present results the user explicitly said they did not want. Add a _killed_sessions set to ProcessRegistry that tracks sessions explicitly killed via kill_process(). The completion watcher checks this set and skips the notification for killed sessions. Fixes NousResearch#36184
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for targeting a real cancellation race. The current gateway still injects an unconsumed agent-notify completion at gateway/run.py:15600, even though kill_process() records completion_reason = "killed" at tools/process_registry.py:1503-1507.
Problems
- The proposed post-kill marker does not cover the stated already-exited case: current
kill_process()returns attools/process_registry.py:1458-1462before the proposed marker would run. - The change only gates
gateway/run.py; the TUI completion poller independently delivers completion events while checking onlyis_completion_consumedattui_gateway/server.py:8745and8810. - Please add a regression test covering cancellation suppression. Existing tests cover kill metadata (
tests/tools/test_notify_on_complete.py:143-170) but not watcher suppression.
Suggested changes
- Salvage onto current kill metadata, cover the already-exited race, and use one shared suppression predicate in gateway and TUI delivery paths.
Automated hermes-sweeper review.
| @@ -1192,6 +1205,7 @@ def kill_process(self, session_id: str) -> dict: | |||
| } | |||
Contributor
There was a problem hiding this comment.
This marker is reached only after a non-exited session is successfully terminated. The current kill_process() returns already_exited before this point, so it does not cover the PR description's "process already exited" race; record explicit cancellation before that return as well.
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.
Problem
When a user cancels a background process (says "no need" and the agent kills it via
process(action='kill')), the process may still complete before the SIGTERM lands. The completion watcher then injects a[IMPORTANT: Background process proc_xxx completed]notification, causing the agent to present results the user explicitly said they did not want.Root cause: The watcher checks
_completion_consumed(set bywait/poll/log) but has no concept of "killed" sessions. When the agent kills a process, it doesn't poll the result, so_completion_consumedstays empty and the notification is still injected.Fix
Add a
_killed_sessionsset toProcessRegistrythat tracks sessions explicitly killed viakill_process(). The completion watcher checks this set and skips the notification for killed sessions.Changes
tools/process_registry.py:self._killed_sessions: set = set()in__init__mark_killed(session_id)andis_killed(session_id)methodsmark_killed()inkill_process()after successful kill_killed_sessionsin_gc_finished()alongside_completion_consumedgateway/run.py:not _pr_check.is_killed(session_id)check to the completion notification guardBefore vs After
wait/pollTests
The fix is minimal and self-contained:
_killed_sessionsfollows the same pattern as_completion_consumed(add on event, check before injection, cleanup on GC)is_completion_consumedbehavior is unchangedFixes #36184