fix(cli): catch KeyboardInterrupt during flush_memories on exit (#3025)

KeyboardInterrupt inherits from BaseException, not Exception, so the
except Exception: clauses wrapping flush_memories() on exit paths
silently skipped the flush when the user pressed Ctrl+C. This could
lose conversation memory.

Change both call sites to except (Exception, KeyboardInterrupt): so
the memory flush is attempted even during interrupt.

Salvaged from PR #2855 by RufusLin (dropped unrelated bundled changes).
This commit is contained in:
Teknium
2026-03-25 12:47:51 -07:00
committed by GitHub
parent 94e3d9adbf
commit e4033b2baf

4
cli.py
View File

@@ -2881,7 +2881,7 @@ class HermesCLI:
if self.agent and self.conversation_history:
try:
self.agent.flush_memories(self.conversation_history)
except Exception:
except (Exception, KeyboardInterrupt):
pass
old_session_id = self.session_id
@@ -7206,7 +7206,7 @@ class HermesCLI:
if self.agent and self.conversation_history:
try:
self.agent.flush_memories(self.conversation_history)
except Exception:
except (Exception, KeyboardInterrupt):
pass
# Shut down voice recorder (release persistent audio stream)
if hasattr(self, '_voice_recorder') and self._voice_recorder: