fix(whatsapp_native,agent): address PR #884 review feedback

- Use c.runCtx for GetQRChannel so the QR producer is canceled on Stop()
- Add atomic stopping guard to prevent wg.Add/wg.Wait race in eventHandler
- Make Stop() context-aware: disconnect client before waiting, respect ctx deadline
- Reduce reasoning publish log noise: use debug level for expected ctx errors
- Add test for handleReasoning when outbound bus is full (timeout path)
This commit is contained in:
Hoshina
2026-02-28 03:05:19 +08:00
parent 1d0220f9fd
commit 9b80fdf885
3 changed files with 98 additions and 11 deletions
+13 -4
View File
@@ -585,10 +585,19 @@ func (al *AgentLoop) handleReasoning(ctx context.Context, reasoningContent, chan
ChatID: channelID,
Content: reasoningContent,
}); err != nil {
logger.WarnCF("agent", "Failed to publish reasoning (best-effort)", map[string]any{
"channel": channelName,
"error": err.Error(),
})
// Only log unexpected errors; context deadline/cancel are expected when
// the bus is full under load and would be too noisy to warn about.
if ctx.Err() == nil {
logger.WarnCF("agent", "Failed to publish reasoning (best-effort)", map[string]any{
"channel": channelName,
"error": err.Error(),
})
} else {
logger.DebugCF("agent", "Reasoning publish skipped (context done)", map[string]any{
"channel": channelName,
"error": err.Error(),
})
}
}
}