fix(cli): invoke on_session_end hook on Ctrl+C exit - #3930
Closed
kelsia14 wants to merge 1 commit into
Closed
Conversation
The on_session_end plugin hook was only called when run_conversation() completed naturally, but NOT when the user pressed Ctrl+C to exit. This meant plugins doing cleanup, flushing, or indexing would miss the session end event on interrupt. Now we explicitly invoke on_session_end in the finally block of the CLI's KeyboardInterrupt handler, with interrupted=True and completed=False to signal the abrupt exit. Closes NousResearch#3929 (reopened as clean PR)
Contributor
Author
|
Superseded by #4038 which includes this fix plus additional signal handling improvements (SIGHUP, SIGTERM, BrokenPipeError). |
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.
PR Description
Summary
Fix: Invoke
on_session_endplugin hook on Ctrl+C exitProblem
The
on_session_endplugin hook was only called whenrun_conversation()completed naturally, but not when the user pressed Ctrl+C to exit the CLI. This caused plugins that rely on session lifecycle events (cleanup, flushing, indexing, session verification) to miss the session termination signal on interrupt.Specifically affected scenarios:
on_session_endwas skipped for abrupt exitsRoot Cause
In
cli.py, thefinallyblock afterKeyboardInterruptperformed several cleanup actions:_session_db.end_session()But it did not invoke the
on_session_endplugin hook, which is only called at the end ofrun_conversation()inrun_agent.py.Solution
Add explicit invocation of
on_session_endin the CLI'sKeyboardInterrupthandler (cli.py:7478-7492), with:interrupted=True- signals the session was aborted by usercompleted=False- signals the conversation did not finish naturallyrun_agent.pyChanges
Testing
on_session_end:interrupted=True, completed=FalseImpact
on_session_endinterrupted=TrueRelated
run_agent.py:8069-8083at the end ofrun_conversation()d6b78362(update session_log_file during compression)Checklist