fix(agent): prevent reasoning goroutine accumulation on full bus
Add a 5-second timeout to handleReasoning's PublishOutbound call so fire-and-forget goroutines do not block indefinitely when the outbound bus channel is full. Reasoning output is best-effort; on timeout the publish is abandoned with a warning log instead of holding the goroutine alive. Fixes goroutine leak introduced in #802.
This commit is contained in:
parent
c7d75a18f8
commit
1d0220f9fd
1 changed files with 13 additions and 2 deletions
|
|
@ -574,11 +574,22 @@ func (al *AgentLoop) handleReasoning(ctx context.Context, reasoningContent, chan
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
al.bus.PublishOutbound(ctx, bus.OutboundMessage{
|
// Use a short timeout so the goroutine does not block indefinitely when
|
||||||
|
// the outbound bus is full. Reasoning output is best-effort; dropping it
|
||||||
|
// is acceptable to avoid goroutine accumulation.
|
||||||
|
pubCtx, pubCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
|
defer pubCancel()
|
||||||
|
|
||||||
|
if err := al.bus.PublishOutbound(pubCtx, bus.OutboundMessage{
|
||||||
Channel: channelName,
|
Channel: channelName,
|
||||||
ChatID: channelID,
|
ChatID: channelID,
|
||||||
Content: reasoningContent,
|
Content: reasoningContent,
|
||||||
|
}); err != nil {
|
||||||
|
logger.WarnCF("agent", "Failed to publish reasoning (best-effort)", map[string]any{
|
||||||
|
"channel": channelName,
|
||||||
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// runLLMIteration executes the LLM call loop with tool handling.
|
// runLLMIteration executes the LLM call loop with tool handling.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue