fix(tui): close AIAgent on session teardown to prevent FD leak

session.close only closed the slash_worker subprocess but never called
agent.close() on the AIAgent instance.  In the long-lived TUI gateway
process, this left httpx clients for GC to finalize.  When the OS
recycled a closed FD number for a new active connection, the stale
finalizer would close the live socket, causing intermittent
[Errno 9] Bad file descriptor on subsequent LLM API calls.

Call agent.close() (which properly shuts down the httpx transport pool
and TCP sockets) before closing the slash_worker.
This commit is contained in:
analista
2026-04-26 00:13:21 +09:00
committed by Teknium
parent 4e2b20b705
commit 6da970f15d

View File

@@ -2439,6 +2439,12 @@ def _(rid, params: dict) -> dict:
unregister_gateway_notify(session["session_key"])
except Exception:
pass
try:
agent = session.get("agent")
if agent and hasattr(agent, "close"):
agent.close()
except Exception:
pass
try:
worker = session.get("slash_worker")
if worker: