fix: preserve session history when a turn crashes

This commit is contained in:
Brooklyn Nicholson
2026-08-06 23:08:23 -05:00
parent aacd3194c9
commit fc05247be8
8 changed files with 100 additions and 30 deletions
+3 -16
View File
@@ -49,6 +49,7 @@ _IS_WINDOWS = platform.system() == "Windows"
from typing import Any, Dict, List, Optional, Tuple
from tools.thread_context import propagate_context_to_thread
from agent.thread_scoped_output import thread_scoped_silence
# Availability gate. On Windows we fall back to loopback TCP for the
# sandbox RPC transport (AF_UNIX is unreliable on Windows Python) — see
@@ -741,17 +742,10 @@ def _rpc_server_loop(
# Suppress stdout/stderr from internal tool handlers so
# their status prints don't leak into the CLI spinner.
try:
_real_stdout, _real_stderr = sys.stdout, sys.stderr
devnull = open(os.devnull, "w", encoding="utf-8")
try:
sys.stdout = devnull
sys.stderr = devnull
with thread_scoped_silence():
result = handle_function_call(
tool_name, tool_args, task_id=task_id
)
finally:
sys.stdout, sys.stderr = _real_stdout, _real_stderr
devnull.close()
except Exception as exc:
logger.error("Tool call failed in sandbox: %s", exc, exc_info=True)
result = tool_error(str(exc))
@@ -1023,17 +1017,10 @@ def _rpc_poll_loop(
# Dispatch through the standard tool handler
try:
_real_stdout, _real_stderr = sys.stdout, sys.stderr
devnull = open(os.devnull, "w", encoding="utf-8")
try:
sys.stdout = devnull
sys.stderr = devnull
with thread_scoped_silence():
tool_result = handle_function_call(
tool_name, tool_args, task_id=task_id
)
finally:
sys.stdout, sys.stderr = _real_stdout, _real_stderr
devnull.close()
except Exception as exc:
logger.error("Tool call failed in remote sandbox: %s",
exc, exc_info=True)