From 6b040ef85393b74eacdbec283d6c651b85c85fe4 Mon Sep 17 00:00:00 2001 From: stevef Date: Mon, 13 Apr 2026 08:26:45 +0200 Subject: [PATCH] fix(agent): defer InvokeTypingStop until runTurn completion --- pkg/agent/loop.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 189334f01..e9aaa4f9b 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -530,9 +530,8 @@ func (al *AgentLoop) Run(ctx context.Context) error { // Process message func() { defer func() { - if al.channelManager != nil { - al.channelManager.InvokeTypingStop(msg.Channel, msg.ChatID) - } + // We've moved InvokeTypingStop to the end of the turn (runTurn) + // to ensure terminal signals match the actual turn completion. }() // TODO: Re-enable media cleanup after inbound media is properly consumed by the agent. // Currently disabled because files are deleted before the LLM can access their content. @@ -1870,6 +1869,9 @@ func (al *AgentLoop) runTurn(ctx context.Context, ts *turnState) (turnResult, er FinalContentLen: ts.finalContentLen(), }, ) + if al.channelManager != nil { + al.channelManager.InvokeTypingStop(ts.channel, ts.chatID) + } }() al.emitEvent(