fix: distinguish user cancel from crash in bash tool results (#235)

* fix: distinguish user cancel from crash in bash tool results

When a user cancels a running bash command, the process is killed
with SIGKILL (exit code -9).  Previously this showed as an error,
causing the model to retry.  Now checks cancel.is_set() after proc
exit and returns "Cancelled by user." as a non-error result so the
model knows to stop rather than retry.

* fix: use -signal.SIGKILL instead of magic -9

Copilot review: replace hard-coded -9 with -signal.SIGKILL for
clarity.  Popen.returncode is negative of signal number when killed.
This commit is contained in:
Patrick Buckley
2026-03-29 17:09:44 -07:00
committed by GitHub
parent e95b8f5ca1
commit 2ace8cccc8
+7
View File
@@ -4301,6 +4301,13 @@ class ChatSession:
if timed_out.is_set():
raise subprocess.TimeoutExpired(cmd="bash", timeout=timeout)
# Distinguish user cancel from unexpected SIGKILL.
# Popen.returncode is negative of the signal number when killed.
if cancel.is_set() and proc.returncode == -signal.SIGKILL:
msg = "Cancelled by user."
self._report_tool_result(call_id, "bash", msg)
return call_id, msg
output = "".join(stdout_parts)
if stderr_lines:
tagged = "".join(f"[stderr] {line}" for line in stderr_lines)