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
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
## 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`
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.
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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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
AnthropicOAuthProvider._make_request()to parse 7 rate limit headers from API responsesVerification
Tested in-place:
rate_limits.jsoncorrectly populated after API call with:Next Steps
HEARTBEAT.mdto read this file and gate heartbeat frequency based onweekly_all_modelsthresholdRelated
Part of
/root/.nanobot/workspace/docs/plans/2026-02-14-rate-limit-monitoring.mdClosing 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.
Pull request closed