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 <noreply@anthropic.com>
This commit is contained in:
parent
9d6a445bb1
commit
f7708bdd6b
1 changed files with 1 additions and 3 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue