From c15f9dd7a61ae60c4b154962e2efd828721afe13 Mon Sep 17 00:00:00 2001 From: dj-oyu <68707227+dj-oyu@users.noreply.github.com> Date: Fri, 20 Mar 2026 20:21:04 +0900 Subject: [PATCH] fix: wait for in-flight LLM requests in Close() Add activeRequests.Wait() at the start of Close() so graceful shutdown waits for any running llmWorkerNormal to finish before releasing resources (sessions, MCP, stats). Co-Authored-By: Claude Opus 4.6 (1M context) --- pkg/agent/loop.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 6ffbc89f1..a737bd43b 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -619,6 +619,9 @@ func (al *AgentLoop) Stop() { // and dirty session data). Should be called during graceful shutdown. func (al *AgentLoop) Close() { + // Wait for in-flight LLM requests to finish before releasing resources. + al.activeRequests.Wait() + al.closeExt() mcpManager := al.mcp.takeManager()