From 230942d23487429ff8d2e191a9e338e5b9e2b297 Mon Sep 17 00:00:00 2001 From: Mauro Date: Sat, 28 Mar 2026 09:36:06 +0100 Subject: [PATCH] fix(loop): polling (#2103) --- pkg/agent/loop.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 48932b10b..db476c212 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -387,10 +387,17 @@ func (al *AgentLoop) Run(ctx context.Context) error { return err } - for al.running.Load() { + idleTicker := time.NewTicker(100 * time.Millisecond) + defer idleTicker.Stop() + + for { select { case <-ctx.Done(): return nil + case <-idleTicker.C: + if !al.running.Load() { + return nil + } case msg, ok := <-al.bus.InboundChan(): if !ok { return nil @@ -517,12 +524,8 @@ func (al *AgentLoop) Run(ctx context.Context) error { al.publishResponseIfNeeded(ctx, target.Channel, target.ChatID, finalResponse) } }() - default: - time.Sleep(time.Microsecond * 200) } } - - return nil } // drainBusToSteering consumes inbound messages and redirects messages from the