fix: preserve session_db on UNIQUE conflict and add /resume CLI command - #3183
fix: preserve session_db on UNIQUE conflict and add /resume CLI command#3183Mibayy wants to merge 1 commit into
Conversation
Two bugs fixed: 1. run_agent.py: AIAgent.__init__ called create_session() even when the CLI had already created the row. This triggered a UNIQUE constraint, the exception handler set self._session_db = None, and all subsequent append_message() calls were silent no-ops. Messages accumulated in memory only — on --resume the session appeared empty. Fix: distinguish UNIQUE/already-exists errors (expected when the CLI pre-creates the session) from genuine failures. Only null out session_db for unexpected errors. 2. cli.py: /resume was listed in commands.py but had no handler in the CLI slash-command dispatcher, causing 'Unknown command: /resume'. Fix: add _handle_resume_command() and wire it to canonical == 'resume'. Supports /resume with no args (lists named sessions), /resume <id> (direct session ID), and /resume <title> (title lookup via resolve_session_by_title). Fixes NousResearch#3123
|
Thanks for this diagnosis and the clear write-up, @Mibayy! Both bugs you identified have since been fixed on Bug 1 — Bug 2 — Closing as implemented on main. This is an automated hermes-sweeper review. |
Fixes #3123 — two separate bugs in the
--resume//resumeflow.Bug 1: sessions not persisted (messages lost on --resume)
Root cause: The CLI creates the SQLite session row early in
__init__. ThenAIAgent.__init__callscreate_session()again for the same session ID, hits a UNIQUE constraint, and the exception handler setsself._session_db = None. From that point everyappend_message()call short-circuits — messages accumulate in memory only and are never written to the DB. On--resume, the session row exists but is empty ("found but has no messages").Fix (
run_agent.py): Distinguish UNIQUE/already-exists errors (expected when the caller pre-creates the session) from genuine failures. Only discardsession_dbfor unexpected errors; silently skip for UNIQUE conflicts.Bug 2:
/resumeunknown command in CLIRoot cause:
_handle_resume_commandexists only ingateway/run.py. The CLI slash-command dispatcher had no handler forresume, even though it's listed incommands.pywithoutgateway_only=True.Fix (
cli.py): Add_handle_resume_command()toHermesCLIand wire it tocanonical == "resume"in the dispatcher.The new CLI handler supports:
/resume— lists recent named sessions/resume <session-id>— switches to a session by its timestamp ID/resume <title>— resolves by title (viaresolve_session_by_title)Flushes memories and ends the current session in the DB before switching, mirroring the gateway behaviour.