feat: add adaptive rate-limit tracking and backoff for metadata agent - #2487
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Rate limit normalisation currently coerces missing/non-numeric remaining values to 0 (and may clear reset), which can incorrectly mark quotas as exhausted and trigger unnecessary backoff.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR introduces Phase 2.4 rate-limit infrastructure for the metadata agent, adding independent quota tracking (core/GraphQL/search) and an adaptive backoff strategy (including Retry-After support), then wiring that into the existing API rate limiter and retry strategy.
Changes:
- Added new rate-limit modules (
RateLimitTracker,BackoffCalculator,QuotaMonitor, and canonical types/defaults). - Updated retry delay logic to delegate to
BackoffCalculator, with rate-limit resource awareness. - Updated documentation and expanded test coverage for the new rate-limit behaviour.
File summaries
| File | Description |
|---|---|
| agents/metadata-agent/README.md | Documents Phase 2.4 rate limit modules in the agent README. |
| agents/metadata-agent/lib/rate-limit/rate-limit-types.js | Defines canonical rate limit type constants plus defaults/thresholds. |
| agents/metadata-agent/lib/rate-limit/rate-limit-tracker.js | Implements per-resource quota tracking, header updates, bottleneck detection, and recovery estimates. |
| agents/metadata-agent/lib/rate-limit/quota-monitor.js | Provides quota health states and a global bottleneck summary derived from the tracker. |
| agents/metadata-agent/lib/rate-limit/backoff-calculator.js | Implements adaptive exponential backoff with jitter and Retry-After support. |
| agents/metadata-agent/lib/api/retry-strategy.js | Switches retry delays to use BackoffCalculator and detects rate-limit resource context. |
| agents/metadata-agent/lib/api/rate-limiter.js | Refactors the rate limiter to extend and reuse RateLimitTracker. |
| agents/metadata-agent/tests/rate-limit/rate-limit-tracker.test.js | Adds unit tests for tracker updates, quota recovery, and bottleneck detection. |
| agents/metadata-agent/tests/rate-limit/quota-monitor.test.js | Adds unit tests for quota health state classification and global bottleneck reporting. |
| agents/metadata-agent/tests/rate-limit/backoff-calculator.test.js | Adds unit tests for jitter, Retry-After precedence, and pressure-based delay adaptation. |
| agents/metadata-agent/tests/api/retry-strategy.test.js | Expands retry strategy tests to cover adaptive delay under search rate limit pressure. |
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
📄 README Validation❌ One or more README checks failed.
|
🔍 Reviewer Summary for PR #2487CI Status: ❌ Recommendations
|
1 similar comment
🔍 Reviewer Summary for PR #2487CI Status: ❌ Recommendations
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Ash Shaw <ashley@lightspeedwp.agency>
|
Missing required section(s): Linked issues, Changelog, Global DoD checklist This is a post-merge backstop for admin bypasses. Please review branch protection for develop. |
🔍 Reviewer Summary for PR #2487CI Status: ❌ Recommendations
|
|
This PR's branch name Standard pattern: Based on linked issue type: Correct template should be: No action required — this is informational. Future PRs should use the correct branch name. See Branching Strategy for more info. |
🔍 Reviewer Summary for PR #2487CI Status: ❌ Recommendations
|
…nt nullish coalescing) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
🔍 Reviewer Summary for PR #2487CI Status: ❌ Recommendations
|
Summary
Adds comprehensive GitHub API quota tracking and adaptive retry behaviour for Reporting Agent v2 Phase 2.4, including independent core/GraphQL/search limit monitoring, exponential backoff with jitter, recovery estimation, and quota health reporting.
Changes Made
Added
agents/metadata-agent/lib/rate-limit/rate-limit-types.js— Canonical rate-limit type definitions and defaultsagents/metadata-agent/lib/rate-limit/rate-limit-tracker.js— Independent tracking for core, GraphQL, search quotas with header updates and recovery estimatesagents/metadata-agent/lib/rate-limit/backoff-calculator.js— Adaptive exponential backoff with jitter andRetry-Afterheader supportagents/metadata-agent/lib/rate-limit/quota-monitor.js— Quota health states and global bottleneck reportingagents/metadata-agent/__tests__/rate-limit/Changed
agents/metadata-agent/lib/api/rate-limiter.js— Now extendsRateLimitTracker, updates limits from GitHub responses while preserving threshold behaviouragents/metadata-agent/lib/api/retry-strategy.js— Delegates delay calculation toBackoffCalculator, adapts retries by rate-limit resource contextagents/metadata-agent/__tests__/api/retry-strategy.test.js— Added adaptive rate-limit delay test coverageagents/metadata-agent/README.md— Updated with Phase 2.4 module documentationKey Features
Fixed
Testing
Linked Issue
Resolves #2034
🤖 Generated with Claude Code