feat: Capture Anthropic rate limit headers for heartbeat throttling #5

Closed
wylab wants to merge 1 commits from feat/rate-limit-tracking into main
Owner

Summary

Implements Task 1 of the rate limit monitoring plan: captures Anthropic's weekly usage headers on every API call and writes them to /root/.nanobot/workspace/memory/rate_limits.json.

Changes

  • Modified AnthropicOAuthProvider._make_request() to parse 7 rate limit headers from API responses
  • Headers captured: weekly all-models utilization, Sonnet utilization, 5h session utilization, reset times, binding limit, fallback status
  • State file updated atomically on every API call (wrapped in try/except to never break requests)

Verification

Tested in-place: rate_limits.json correctly populated after API call with:

{
  "weekly_all_models": 0.84,
  "session_5h": 0.23,
  "binding_limit": "seven_day",
  ...
}

Next Steps

  • Task 2: Update HEARTBEAT.md to read this file and gate heartbeat frequency based on weekly_all_models threshold

Part of /root/.nanobot/workspace/docs/plans/2026-02-14-rate-limit-monitoring.md

## Summary Implements Task 1 of the rate limit monitoring plan: captures Anthropic's weekly usage headers on every API call and writes them to `/root/.nanobot/workspace/memory/rate_limits.json`. ## Changes - Modified `AnthropicOAuthProvider._make_request()` to parse 7 rate limit headers from API responses - Headers captured: weekly all-models utilization, Sonnet utilization, 5h session utilization, reset times, binding limit, fallback status - State file updated atomically on every API call (wrapped in try/except to never break requests) ## Verification Tested in-place: `rate_limits.json` correctly populated after API call with: ```json { "weekly_all_models": 0.84, "session_5h": 0.23, "binding_limit": "seven_day", ... } ``` ## Next Steps - [ ] Task 2: Update `HEARTBEAT.md` to read this file and gate heartbeat frequency based on `weekly_all_models` threshold ## Related Part of `/root/.nanobot/workspace/docs/plans/2026-02-14-rate-limit-monitoring.md`
wylab added 1 commit 2026-02-14 22:52:41 +01:00
feat: capture Anthropic rate limit headers for heartbeat throttling
All checks were successful
Build Nanobot OAuth / build (pull_request) Successful in 5m40s
Build Nanobot OAuth / cleanup (pull_request) Has been skipped
1d940cb4f2
Adds rate limit state capture to _make_request():
- Parses 7 Anthropic rate limit headers from every API response
- Writes to memory/rate_limits.json with utilization, reset times, binding limit
- Enables HEARTBEAT.md to throttle based on weekly_all_models budget

Part of rate limit monitoring implementation plan.
Author
Owner

Closing this PR in favor of #6.

Why: This PR implemented the wrong approach - it throttles heartbeat frequency, but heartbeats already use Sonnet (separate budget pool). The real problem is Opus overuse in main conversation turns.

Solution: PR #6 implements dynamic model switching for the main agent based on rolling weekly quota. When burn rate exceeds target, main agent switches to Sonnet. When under quota, switches back to Opus.

The rate limit header capture from this PR is still valuable and will be used by #6.

Closing this PR in favor of #6. **Why:** This PR implemented the wrong approach - it throttles heartbeat frequency, but heartbeats already use Sonnet (separate budget pool). The real problem is Opus overuse in main conversation turns. **Solution:** PR #6 implements dynamic model switching for the main agent based on rolling weekly quota. When burn rate exceeds target, main agent switches to Sonnet. When under quota, switches back to Opus. The rate limit header capture from this PR is still valuable and will be used by #6.
wylab closed this pull request 2026-02-14 23:52:00 +01:00
All checks were successful
Build Nanobot OAuth / build (pull_request) Successful in 5m40s
Required
Details
Build Nanobot OAuth / cleanup (pull_request) Has been skipped

Pull request closed

Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wylab/nanobot#5