From ed23705af1fa2179b850abd1493afbc4df12e42d Mon Sep 17 00:00:00 2001 From: dj-oyu <68707227+dj-oyu@users.noreply.github.com> Date: Thu, 26 Mar 2026 01:20:13 +0900 Subject: [PATCH] fix: use non-cancellable context for reasoning goroutine The reasoning content goroutine was using the turn-scoped context which gets cancelled when the turn ends, racing with the publish. Use context.WithoutCancel to ensure reasoning is delivered. Also fix gci field alignment and golines indentation. Co-Authored-By: Claude Opus 4.6 (1M context) --- pkg/agent/loop_run.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/agent/loop_run.go b/pkg/agent/loop_run.go index af4124b2a..2299bcc9b 100644 --- a/pkg/agent/loop_run.go +++ b/pkg/agent/loop_run.go @@ -444,9 +444,9 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, agent *AgentInstance, opt Iteration: iteration, } al.emitEvent(EventKindTurnEnd, abortMeta, TurnEndPayload{ - Status: TurnEndStatusAborted, - Duration: time.Since(turnStart), - }) + Status: TurnEndStatusAborted, + Duration: time.Since(turnStart), + }) return "", nil } return "", err @@ -1068,7 +1068,12 @@ func (al *AgentLoop) runLLMIteration( if reasoningText == "" { reasoningText = response.ReasoningContent } - go al.handleReasoning(ctx, reasoningText, opts.Channel, al.targetReasoningChannelID(opts.Channel)) + go al.handleReasoning( + context.WithoutCancel(ctx), + reasoningText, + opts.Channel, + al.targetReasoningChannelID(opts.Channel), + ) logger.DebugCF("agent", "LLM response", map[string]any{