From 63d6b9e6375733df5665732462c60d59668d4030 Mon Sep 17 00:00:00 2001 From: ygd58 Date: Mon, 25 May 2026 03:53:52 -0700 Subject: [PATCH] fix(cli): catch KeyboardInterrupt during slash commands to prevent session exit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Ctrl+C during a slow slash command (e.g. /skills browse on a large skill tree, /sessions list against a multi-GB SQLite DB) used to unwind past self.process_command() to the outer prompt_toolkit event loop, which killed the entire session — losing all conversation state. Fix: wrap the slash-command dispatch in try/except KeyboardInterrupt so Ctrl+C aborts the command but the prompt loop continues. Other exceptions still propagate so real bugs aren't silently swallowed. Surgical reapply of PR #5189. Original branch was many months stale (3764 files / 1M+ LOC of unrelated reverts); the substantive ~6 LOC change in cli.py was reapplied by hand onto current main with the contributor's authorship preserved via --author. --- cli.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cli.py b/cli.py index 9bfe55da95b..ce4f8eb43ec 100644 --- a/cli.py +++ b/cli.py @@ -14235,11 +14235,19 @@ class HermesCLI: if not _file_drop and isinstance(user_input, str) and _looks_like_slash_command(user_input): _cprint(f"\n⚙️ {user_input}") - if not self.process_command(user_input): - self._should_exit = True - # Schedule app exit - if app.is_running: - app.exit() + try: + if not self.process_command(user_input): + self._should_exit = True + # Schedule app exit + if app.is_running: + app.exit() + except KeyboardInterrupt: + # Ctrl+C during a slow slash command (e.g. /skills browse, + # /sessions list with a large DB) should interrupt the + # command and return to the prompt, NOT exit the entire + # session. Without this guard a KeyboardInterrupt unwinds + # to the outer prompt_toolkit loop and the session dies. + _cprint("\n[dim]Command interrupted.[/dim]") continue # Expand paste references back to full content