Skip to content

Commit e4033b2

Browse files
authored
fix(cli): catch KeyboardInterrupt during flush_memories on exit (NousResearch#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 NousResearch#2855 by RufusLin (dropped unrelated bundled changes).
1 parent 94e3d9a commit e4033b2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,7 @@ def new_session(self, silent=False):
28812881
if self.agent and self.conversation_history:
28822882
try:
28832883
self.agent.flush_memories(self.conversation_history)
2884-
except Exception:
2884+
except (Exception, KeyboardInterrupt):
28852885
pass
28862886

28872887
old_session_id = self.session_id
@@ -7206,7 +7206,7 @@ def _restart_recording():
72067206
if self.agent and self.conversation_history:
72077207
try:
72087208
self.agent.flush_memories(self.conversation_history)
7209-
except Exception:
7209+
except (Exception, KeyboardInterrupt):
72107210
pass
72117211
# Shut down voice recorder (release persistent audio stream)
72127212
if hasattr(self, '_voice_recorder') and self._voice_recorder:

0 commit comments

Comments
 (0)