fix(execute_code): report in-script tool errors the script ignored

A script that calls hermes_tools.write_file/patch and never prints the
returned {"error": ...} got status=success with empty output, so the
model believed the write happened. In a cross-agent bench this cost 3 of
18 Opus runs 4-6 extra turns (write_file refused by the read-before-write
guard, then re-probing and re-emitting whole files). The result now
carries tool_errors for that cell, and the in-script write_file doc says
existing files must be read first.
This commit is contained in:
teknium1
2026-09-28 01:51:01 -07:00
committed by Teknium
parent 1b91b8eaa5
commit 3e1bfb2935
5 changed files with 60 additions and 8 deletions

View File

@@ -366,6 +366,7 @@ def execute_in_remote_kernel(
def _run_attached_cell(kernel: RemoteKernel, key: Tuple, code: str, *, env, task_env_id: str,
sandbox_tools: frozenset, timeout: int, max_tool_calls: int,
reused: bool, state_reset: bool, state_lost: bool) -> Dict[str, Any]:
from tools.code_execution_rpc import tool_errors_since
from tools.code_execution_tool import _rpc_poll_loop
from tools.thread_context import propagate_context_to_thread
# Clean stale tool-RPC requests from a previous cell before arming this cell's poll loop, so
@@ -375,12 +376,12 @@ def _run_attached_cell(kernel: RemoteKernel, key: Tuple, code: str, *, env, task
kernel.sh(f"rm -f {q_rpc}/req_* {q_rpc}/res_*", timeout=10)
except Exception:
pass
tool_call_counter, stop_event = [0], threading.Event()
tool_call_counter, tool_call_log, stop_event = [0], [], threading.Event()
# Per-cell RPC thread carrying THIS call's approval/session context — the remote analogue
# of CellAuthority: authority lives exactly as long as the cell's poll loop.
rpc_thread = threading.Thread(
target=propagate_context_to_thread(_rpc_poll_loop), daemon=True,
args=(env, f"{kernel.kernel_dir}/rpc", task_env_id, [], tool_call_counter,
args=(env, f"{kernel.kernel_dir}/rpc", task_env_id, tool_call_log, tool_call_counter,
max_tool_calls, sandbox_tools, stop_event, kernel.rpc_token))
rpc_thread.start()
cell_status, cell_payload = "no-result", {}
@@ -401,6 +402,7 @@ def _run_attached_cell(kernel: RemoteKernel, key: Tuple, code: str, *, env, task
result: Dict[str, Any] = {
"status": "error", "stdout": cell_payload.get("stdout", ""), "stderr": cell_payload.get("stderr", ""),
"traceback": cell_payload.get("traceback", ""), "tool_calls_made": tool_call_counter[0], "kernel": kernel_info,
"tool_errors": tool_errors_since(tool_call_log),
}
if cell_status in ("timeout", "protocol-error", "no-result"):
# No safe way to interrupt one cell in place (same contract as local): kill, report, respawn.