fix(cli): flush conversation messages to SQLite on Ctrl+C exit - #44344
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(cli): flush conversation messages to SQLite on Ctrl+C exit#44344liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
When the user presses Ctrl+C at the idle prompt (or any exit path that bypasses run_conversation's _persist_session), the session row is closed via end_session() but the conversation messages are never flushed to the SQLite messages table. This leaves the session with 0 messages even though message_count may be non-zero, and hermes --resume shows an empty session. Add a _flush_messages_to_session_db() call in the finally block before end_session() to ensure all conversation history is persisted regardless of exit path. Fixes NousResearch#44281
Contributor
|
Thanks for this! It's a duplicate of the same bug fixed in #50004 (CLI session lost on SIGHUP/SIGTERM/window-close, issue #6481). We went with the implementation salvaged from #26894 (submitted earlier, May 16) because it uses Closing in favor of #50004. Appreciate the contribution. |
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 using
hermes chat(CLI mode), pressing Ctrl+C at the idle prompt exits without persisting conversation messages to the SQLite session database. The session row is created andend_session()setsended_at/end_reason, but themessagestable remains empty.This means:
hermes --resume <session_id>shows 0 messagesmessage_countin the sessions table can be non-zero while actual messages are 0Root Cause
The
finallyblock inHermesCLI.run()(cli.py) callsend_session()to close the session row, but never calls_flush_messages_to_session_db()to persist the conversation history. The flush only happens during normal conversation flow viarun_agent.py::_persist_session(), which is never invoked when the user exits at the idle prompt.Fix
Add a
_flush_messages_to_session_db()call in thefinallyblock beforeend_session(), guarded by:conversation_historyis non-emptyagentexists and has the flush methodThe flush is wrapped in
try/exceptso failures don't block the rest of the cleanup (session close, plugin hooks, etc.).Testing
4 unit tests covering:
end_session()Fixes #44281