From c86dbc9f45e4467d54ec0a56ce5597219071d8ee Mon Sep 17 00:00:00 2001 From: Nikolas de Hor Date: Thu, 19 Feb 2026 10:27:11 -0300 Subject: [PATCH] fix: wait for killed process after shell timeout to prevent fd leaks When a shell command times out, process.kill() is called but the process object was never awaited after that. This leaves subprocess pipes undrained and file descriptors open. If many commands time out, fd leaks accumulate. Add a bounded wait (5s) after kill to let the process fully terminate and release its resources. --- nanobot/agent/tools/shell.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nanobot/agent/tools/shell.py b/nanobot/agent/tools/shell.py index 18eff64..ceac6b7 100644 --- a/nanobot/agent/tools/shell.py +++ b/nanobot/agent/tools/shell.py @@ -81,6 +81,12 @@ class ExecTool(Tool): ) except asyncio.TimeoutError: process.kill() + # Wait for the process to fully terminate so pipes are + # drained and file descriptors are released. + try: + await asyncio.wait_for(process.wait(), timeout=5.0) + except asyncio.TimeoutError: + pass return f"Error: Command timed out after {self.timeout} seconds" output_parts = []