fix(code-exec): preserve interrupt cancellation source

This commit is contained in:
fangliquanflq
2026-08-24 01:38:06 +08:00
committed by Teknium
parent ee8a66233f
commit c1c0efa375
9 changed files with 175 additions and 18 deletions
+15 -4
View File
@@ -1060,6 +1060,19 @@ def _rpc_poll_loop(
stop_event.wait(poll_interval)
def _format_interrupted_output(stdout_text: str) -> str:
"""Append an interruption marker without guessing who caused it."""
from tools.interrupt import get_interrupt_reason
reason = get_interrupt_reason()
marker = (
f"[execution interrupted — {reason}]"
if reason
else "[execution interrupted]"
)
return f"{stdout_text}\n{marker}" if stdout_text else marker
def _execute_remote(
code: str,
task_id: Optional[str],
@@ -1238,9 +1251,7 @@ def _execute_remote(
duration, timeout, tool_call_counter[0],
)
elif status == "interrupted":
result["output"] = (
stdout_text + "\n[execution interrupted — user sent a new message]"
)
result["output"] = _format_interrupted_output(stdout_text)
elif exit_code != 0:
result["status"] = "error"
result["error"] = f"Script exited with code {exit_code}"
@@ -1710,7 +1721,7 @@ def execute_code(
duration, timeout, tool_call_counter[0],
)
elif status == "interrupted":
result["output"] = stdout_text + "\n[execution interrupted — user sent a new message]"
result["output"] = _format_interrupted_output(stdout_text)
elif exit_code != 0:
result["status"] = "error"
result["error"] = stderr_text or f"Script exited with code {exit_code}"