mirror of
https://github.com/turnstonelabs/turnstone.git
synced 2026-08-23 20:34:49 -06:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user