From 999a28062d1f99ea72f15c9b5a7e5ded2c93e8dc Mon Sep 17 00:00:00 2001 From: teknium Date: Tue, 10 Feb 2026 22:53:44 +0000 Subject: [PATCH] Implement graceful exit cleanup for terminal tool - Added a new `_atexit_cleanup` function to handle cleanup of active environments and stop the cleanup thread upon program exit. - Enhanced logging to inform users about the number of remaining sandboxes being shut down during cleanup. --- tools/terminal_tool.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/terminal_tool.py b/tools/terminal_tool.py index db3b8c63..7e4f960b 100644 --- a/tools/terminal_tool.py +++ b/tools/terminal_tool.py @@ -1365,7 +1365,15 @@ def cleanup_vm(task_id: str): print(f"[Terminal Cleanup] Error cleaning up environment for task {task_id}: {e}") -atexit.register(_stop_cleanup_thread) +def _atexit_cleanup(): + """Stop cleanup thread and shut down all remaining sandboxes on exit.""" + _stop_cleanup_thread() + if _active_environments: + count = len(_active_environments) + print(f"\n[Terminal Cleanup] Shutting down {count} remaining sandbox(es)...") + cleanup_all_environments() + +atexit.register(_atexit_cleanup) def terminal_tool(