fix(code-exec): preserve interrupt cancellation source
This commit is contained in:
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user