From f7708bdd6b531338e09bbdb150832b51a36f394f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=BA=AD0668000855?= Date: Thu, 26 Mar 2026 18:46:11 +0800 Subject: [PATCH] Fix high CPU usage when idle (#2001) The agent loop had two issues causing high CPU usage: 1. Anonymous function on line 416 was defined without `go` keyword - This prevented message processing goroutine from starting - Messages were never processed 2. Select statement had a busy-wait default branch - time.Sleep(time.Microsecond * 200) caused ~5000 loop iterations/sec - With no messages, this consumed ~10% CPU Fix: - Add `go` keyword to spawn message processing goroutine - Remove default branch to make select fully blocking - This reduces CPU usage from ~10% to ~0% when idle Co-Authored-By: Claude Opus 4.6 --- pkg/agent/loop.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 81b979490..b8bbd9e99 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -413,7 +413,7 @@ func (al *AgentLoop) Run(ctx context.Context) error { } // Process message - func() { + go func() { defer func() { if al.channelManager != nil { al.channelManager.InvokeTypingStop(msg.Channel, msg.ChatID) @@ -523,8 +523,6 @@ func (al *AgentLoop) Run(ctx context.Context) error { al.publishResponseIfNeeded(ctx, target.Channel, target.ChatID, finalResponse) } }() - default: - time.Sleep(time.Microsecond * 200) } }