Skip to content

The agent that grows with you

fix(sessions): Ctrl-C at a sessions confirmation exits 130, not 0

Tekniumb9e5df60fd98
diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.py
index b269d679255..23a78065470 100644
--- a/hermes_cli/sessions_cmd.py
+++ b/hermes_cli/sessions_cmd.py
@@ -40,21 +40,24 @@ def _size_delta_label(saved_mb: float) -> str:
def _confirm_prompt(prompt: str) -> bool | None:
"""Prompt for y/N confirmation. ``None`` when no answer can be read (stdin is /dev/null or closed:
- cron, a wrapper, a backgrounded shell), which is not the same as the user saying no."""
+ cron, a wrapper, a backgrounded shell), which is not the same as the user saying no. Ctrl-C
+ propagates: an interrupt is neither a no nor a success."""
try:
return input(prompt).strip().lower() in {"y", "yes"}
except EOFError:
print()
return None
- except KeyboardInterrupt:
- return False
def _confirm_or_exit_code(prompt: str, *, declined: str = "Cancelled.", unattended: str | None = "--yes") -> int | None:
"""``None`` to proceed, else the exit code after saying why not. A decline exits 0; a run nobody could
answer exits 1, so a cron job or wrapper that forgot *unattended* does not read "nothing happened" as
success."""
- answer = _confirm_prompt(prompt)
+ try:
+ answer = _confirm_prompt(prompt)
+ except KeyboardInterrupt:
+ print("\nInterrupted; nothing was changed.")
+ return 130
if answer:
return None
if answer is None:
diff --git a/tests/hermes_cli/test_sessions_failure_exit_codes.py b/tests/hermes_cli/test_sessions_failure_exit_codes.py
index faa8a4c38cf..b9edb2b43c0 100644
--- a/tests/hermes_cli/test_sessions_failure_exit_codes.py
+++ b/tests/hermes_cli/test_sessions_failure_exit_codes.py
@@ -118,3 +118,9 @@ def test_confirmation_nobody_can_answer_exits_1_and_changes_nothing(monkeypatch,
assert _run_cli(monkeypatch, argv) == 1
assert "Pass --yes" in capsys.readouterr().out
assert snapshot() == before
+
+ def ctrl_c(_prompt=""):
+ raise KeyboardInterrupt
+ monkeypatch.setattr("builtins.input", ctrl_c) # an interrupt is not a decline either: `&& next` must not run
+ assert _run_cli(monkeypatch, argv) == 130
+ assert snapshot() == before