From 672cc80915ce6621e978e0b47c8a752ef62370f5 Mon Sep 17 00:00:00 2001 From: pefontana Date: Fri, 10 Apr 2026 16:23:23 -0300 Subject: [PATCH] fix(delegate): close child agent after delegation completes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call child.close() in the _run_single_child finally block after unregistering the child from the parent's active children list. Previously child AIAgent instances were only removed from the tracking list but never had their resources released — the OpenAI/httpx client and any tool subprocesses relied entirely on garbage collection. Ref: #7131 --- tools/delegate_tool.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/delegate_tool.py b/tools/delegate_tool.py index b14833428e..7ec17264b7 100644 --- a/tools/delegate_tool.py +++ b/tools/delegate_tool.py @@ -578,6 +578,15 @@ def _run_single_child( except (ValueError, UnboundLocalError) as e: logger.debug("Could not remove child from active_children: %s", e) + # Close tool resources (terminal sandboxes, browser daemons, + # background processes, httpx clients) so subagent subprocesses + # don't outlive the delegation. + try: + if hasattr(child, 'close'): + child.close() + except Exception: + logger.debug("Failed to close child agent after delegation") + def delegate_task( goal: Optional[str] = None, context: Optional[str] = None,