Skip to content

feat(daemon): send Anthropic usage data to server#241

Merged
AnnatarHe merged 1 commit intomainfrom
feat/anthropic-usage-reset-push-notifications
Feb 24, 2026
Merged

feat(daemon): send Anthropic usage data to server#241
AnnatarHe merged 1 commit intomainfrom
feat/anthropic-usage-reset-push-notifications

Conversation

@AnnatarHe
Copy link
Copy Markdown
Contributor

@AnnatarHe AnnatarHe commented Feb 24, 2026

Summary

  • After fetching Anthropic rate limit data, fire-and-forget POST to /api/v1/anthropic-usage on the ShellTime server
  • Server uses this to schedule push notifications when rate limits reset
  • Uses existing SendHTTPRequestJSON pattern with CLI token auth

Related PRs

Test plan

  • Build daemon, verify it POSTs to /api/v1/anthropic-usage on rate limit fetch
  • Verify fire-and-forget — failure should only log a warning, not block

🤖 Generated with Claude Code


Open with Devin

After fetching rate limit data from Anthropic, fire-and-forget POST to
/api/v1/anthropic-usage so the server can schedule push notifications
when rate limits reset.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @AnnatarHe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new feature to send Anthropic usage data to the ShellTime server. This allows the server to schedule push notifications related to rate limit resets. The implementation uses existing patterns for sending HTTP requests and includes error handling to prevent blocking the daemon.

Highlights

  • Feature: Implements sending Anthropic usage data to the ShellTime server after fetching rate limit information.
  • Purpose: The server uses this data to schedule push notifications when rate limits reset, enhancing user experience.
  • Implementation: Utilizes the existing SendHTTPRequestJSON pattern with CLI token authentication for sending the usage data.
  • Error Handling: Implements fire-and-forget mechanism, logging a warning without blocking the daemon on failure.
Changelog
  • daemon/cc_info_timer.go
    • Implemented sending Anthropic usage data to the server for push notification scheduling.
Activity
  • The PR introduces a new function sendAnthropicUsageToServer to handle sending the data.
  • The PR description includes a test plan to verify the functionality and error handling.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread daemon/cc_info_timer.go
s.rateLimitCache.mu.Unlock()

// Send usage data to server for push notification scheduling (fire-and-forget)
go s.sendAnthropicUsageToServer(ctx, usage)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Fire-and-forget goroutine uses a context that is cancelled immediately after spawning

The sendAnthropicUsageToServer goroutine is spawned at line 436 with the same ctx that was passed to fetchRateLimit. However, the callers of fetchRateLimit (at lines 171-173 and 194-196) create a timeout context with defer cancel() in the enclosing anonymous function. When fetchRateLimit returns synchronously, cancel() fires, cancelling the context. The newly spawned goroutine then tries to make an HTTP request with this already-cancelled context, which will fail immediately.

Root Cause and Impact

The call chain is:

  1. timerLoop spawns an anonymous goroutine (line 166-174)
  2. Inside it: ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) then defer cancel()
  3. s.fetchRateLimit(ctx) is called synchronously
  4. Inside fetchRateLimit, at line 436: go s.sendAnthropicUsageToServer(ctx, usage) — this spawns a goroutine with the same ctx
  5. fetchRateLimit returns → defer cancel() fires → ctx is cancelled
  6. sendAnthropicUsageToServer calls model.SendHTTPRequestJSON which uses http.NewRequestWithContext(ctx, ...) at model/api.base.go:50 — this request will fail immediately with context canceled

Impact: The usage data will never be successfully sent to the server. The fire-and-forget feature is completely non-functional. Every attempt will log "Failed to send anthropic usage to server" with a context cancellation error.

Suggested change
go s.sendAnthropicUsageToServer(ctx, usage)
go s.sendAnthropicUsageToServer(context.Background(), usage)
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@AnnatarHe AnnatarHe merged commit b9b7a9e into main Feb 24, 2026
4 checks passed
@AnnatarHe AnnatarHe deleted the feat/anthropic-usage-reset-push-notifications branch February 24, 2026 17:27
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new feature to send Anthropic usage data to the server for push notification scheduling. It adds a new function sendAnthropicUsageToServer to handle the data sending logic and calls it after fetching rate limit data. The changes include creating data structures for the payload and using the existing SendHTTPRequestJSON function. The test plan includes verifying the POST request and ensuring it's fire-and-forget.

Comment thread daemon/cc_info_timer.go
Comment on lines +478 to +519
// sendAnthropicUsageToServer sends the Anthropic usage data to the ShellTime server
// for scheduling push notifications when rate limits reset.
func (s *CCInfoTimerService) sendAnthropicUsageToServer(ctx context.Context, usage *AnthropicRateLimitData) {
if s.config.Token == "" {
return
}

type usageBucket struct {
Utilization float64 `json:"utilization"`
ResetsAt string `json:"resets_at"`
}
type usagePayload struct {
FiveHour usageBucket `json:"five_hour"`
SevenDay usageBucket `json:"seven_day"`
}

payload := usagePayload{
FiveHour: usageBucket{
Utilization: usage.FiveHourUtilization,
ResetsAt: usage.FiveHourResetsAt,
},
SevenDay: usageBucket{
Utilization: usage.SevenDayUtilization,
ResetsAt: usage.SevenDayResetsAt,
},
}

err := model.SendHTTPRequestJSON(model.HTTPRequestOptions[usagePayload, any]{
Context: ctx,
Endpoint: model.Endpoint{
Token: s.config.Token,
APIEndpoint: s.config.APIEndpoint,
},
Method: "POST",
Path: "/api/v1/anthropic-usage",
Payload: payload,
Timeout: 5 * time.Second,
})
if err != nil {
slog.Warn("Failed to send anthropic usage to server", slog.Any("err", err))
}
}
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

Consider adding more robust error handling. While the current implementation logs a warning if sending usage data fails, it might be beneficial to implement a retry mechanism with exponential backoff to handle transient network issues. This would improve the reliability of sending usage data to the server.

Comment thread daemon/cc_info_timer.go

// sendAnthropicUsageToServer sends the Anthropic usage data to the ShellTime server
// for scheduling push notifications when rate limits reset.
func (s *CCInfoTimerService) sendAnthropicUsageToServer(ctx context.Context, usage *AnthropicRateLimitData) {
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

The function sendAnthropicUsageToServer could benefit from input validation. Before sending the data, validate the usage parameter to ensure that the FiveHourUtilization, SevenDayUtilization, FiveHourResetsAt, and SevenDayResetsAt fields contain valid data. This can prevent unexpected errors or incorrect data being sent to the server.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 0% with 32 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
daemon/cc_info_timer.go 0.00% 32 Missing ⚠️
Flag Coverage Δ
unittests 37.46% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
daemon/cc_info_timer.go 74.74% <0.00%> (-9.31%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant