Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion daemon/cc_info_timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ func (s *CCInfoTimerService) fetchRateLimit(ctx context.Context) {
s.rateLimitCache.mu.Unlock()

// Send usage data to server for push notification scheduling (fire-and-forget)
go s.sendAnthropicUsageToServer(ctx, usage)
// Use a separate context so the goroutine isn't canceled when the caller returns.
go func() {
bgCtx, bgCancel := context.WithTimeout(context.Background(), 10*time.Second)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve readability and maintainability, it's best to avoid using magic numbers. Consider defining 10 * time.Second as a named constant at the package level, for example sendAnthropicUsageTimeout. This makes the purpose of the timeout clearer and easier to change in the future.

defer bgCancel()
s.sendAnthropicUsageToServer(bgCtx, usage)
}()

slog.Debug("Anthropic rate limit updated",
slog.Float64("5h", usage.FiveHourUtilization),
Expand Down