From dd1cd1157b963d68a33b44179ea7e67166814d4c Mon Sep 17 00:00:00 2001 From: ex-takashima Date: Thu, 26 Feb 2026 20:29:09 +0900 Subject: [PATCH] fix(line): log loading refresh errors, skip typing without recorder Address review feedback from @alexhoshina and Codex: - Log sendLoading errors in ticker goroutine instead of discarding - Only start typing indicator when PlaceholderRecorder is available to avoid wasted API calls and unnecessary goroutine creation Co-Authored-By: Claude Opus 4.6 --- pkg/channels/line/line.go | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/pkg/channels/line/line.go b/pkg/channels/line/line.go index 91ebc7f72..50914f751 100644 --- a/pkg/channels/line/line.go +++ b/pkg/channels/line/line.go @@ -380,25 +380,23 @@ func (c *LINEChannel) processEvent(event lineEvent) { // Thinking indicator (LINE loading animation is 1:1 only). // For group/room chats, LINE provides no equivalent API. + // Only start if PlaceholderRecorder is available to avoid wasted API calls. if !isGroup { - typingCtx, typingCancel := context.WithTimeout(c.ctx, 5*time.Minute) - stop, err := c.StartTyping(typingCtx, chatID) - if err == nil { - var stopOnce sync.Once - stopFn := func() { - stopOnce.Do(func() { - stop() - typingCancel() - }) - } - if rec := c.GetPlaceholderRecorder(); rec != nil { + if rec := c.GetPlaceholderRecorder(); rec != nil { + typingCtx, typingCancel := context.WithTimeout(c.ctx, 5*time.Minute) + stop, err := c.StartTyping(typingCtx, chatID) + if err == nil { + var stopOnce sync.Once + stopFn := func() { + stopOnce.Do(func() { + stop() + typingCancel() + }) + } rec.RecordTypingStop("line", chatID, stopFn) } else { - // No recorder — stop immediately to avoid goroutine leaks. - stopFn() + typingCancel() } - } else { - typingCancel() } } @@ -627,7 +625,11 @@ func (c *LINEChannel) StartTyping(ctx context.Context, chatID string) (func(), e case <-typingCtx.Done(): return case <-ticker.C: - _ = c.sendLoading(typingCtx, chatID) + if err := c.sendLoading(typingCtx, chatID); err != nil { + logger.DebugCF("line", "Failed to refresh loading indicator", map[string]any{ + "error": err.Error(), + }) + } } } }()