Skip to content

feat: add adaptive rate-limit tracking and backoff for metadata agent - #2487

Merged
ashleyshaw merged 7 commits into
developfrom
copilot/reporting-agent-v2-rate-limiting
Sep 3, 2026
Merged

feat: add adaptive rate-limit tracking and backoff for metadata agent#2487
ashleyshaw merged 7 commits into
developfrom
copilot/reporting-agent-v2-rate-limiting

Conversation

Copilot AI commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

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 defaults
  • agents/metadata-agent/lib/rate-limit/rate-limit-tracker.js — Independent tracking for core, GraphQL, search quotas with header updates and recovery estimates
  • agents/metadata-agent/lib/rate-limit/backoff-calculator.js — Adaptive exponential backoff with jitter and Retry-After header support
  • agents/metadata-agent/lib/rate-limit/quota-monitor.js — Quota health states and global bottleneck reporting
  • Comprehensive test suite under agents/metadata-agent/__tests__/rate-limit/

Changed

  • agents/metadata-agent/lib/api/rate-limiter.js — Now extends RateLimitTracker, updates limits from GitHub responses while preserving threshold behaviour
  • agents/metadata-agent/lib/api/retry-strategy.js — Delegates delay calculation to BackoffCalculator, adapts retries by rate-limit resource context
  • agents/metadata-agent/__tests__/api/retry-strategy.test.js — Added adaptive rate-limit delay test coverage
  • agents/metadata-agent/README.md — Updated with Phase 2.4 module documentation

Key Features

// Adaptive backoff based on rate-limit type and pressure
const delay = backoffCalculator.calculateDelay({
  attemptNumber: 1,
  error, // 429 or rate-limit message
  rateLimitType: "search",
  quotaRemainingPercent: 5,
});

// Quota health monitoring
const status = quotaMonitor.getStatus("search");
// Returns: { state: 'warning'|'critical'|'exhausted', percentage, recoveryInMs, ... }

// Global bottleneck detection
const global = quotaMonitor.getGlobalStatus();
// { bottleneck: 'search', core: {...}, graphql: {...}, search: {...} }

Fixed

  • Numeric parsing edge case in quota normalisation where valid zero values could be overwritten
  • Global status aggregation now avoids mutable in-place sort side effects
  • Proper handling of nullable/undefined rate-limit headers

Testing

  • 24+ unit tests for rate-limit tracking, backoff calculation, and quota monitoring
  • Tests cover edge cases: zero values, missing headers, recovery estimates
  • Adaptive delay testing with different quota pressure scenarios

Linked Issue

Resolves #2034


🤖 Generated with Claude Code

Copilot AI changed the title [WIP] Implement GitHub API rate limit compliance with adaptive backoff feat: add adaptive rate-limit tracking and backoff for metadata agent Aug 29, 2026
Copilot AI requested a review from ashleyshaw August 29, 2026 15:27
@ashleyshaw
ashleyshaw requested a lite review from Copilot August 29, 2026 16:15

Copilot AI left a comment

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.

🟡 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.

Comment thread agents/metadata-agent/lib/rate-limit/rate-limit-tracker.js
@ashleyshaw
ashleyshaw marked this pull request as ready for review August 29, 2026 16:30
@github-actions

Copy link
Copy Markdown
Contributor

📄 README Validation

❌ One or more README checks failed.

Check Result
❌ Frontmatter Failed
✅ Structure Passed

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Reviewer Summary for PR #2487

CI Status:pending
Files changed: 11

Recommendations

  • CI checks not green

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Reviewer Summary for PR #2487

CI Status:pending
Files changed: 11

Recommendations

  • CI checks not green

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ash Shaw <ashley@lightspeedwp.agency>
@ashleyshaw
ashleyshaw enabled auto-merge (squash) August 29, 2026 16:50
@github-actions

github-actions Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

⚠️ A merged PR reached develop without passing the template content guardrail.

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.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Reviewer Summary for PR #2487

CI Status:pending
Files changed: 11

Recommendations

  • CI checks not green

@ashleyshaw ashleyshaw added this to the v1.1 milestone Aug 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Branch Naming Issue

This PR's branch name copilot/reporting-agent-v2-rate-limiting doesn't follow the standard pattern.

Standard pattern: {type}/{scope}-{title} (e.g., feat/something, fix/bug-name)

Based on linked issue type: task

Correct template should be: pr_feature.md

No action required — this is informational. Future PRs should use the correct branch name.

See Branching Strategy for more info.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Reviewer Summary for PR #2487

CI Status:pending
Files changed: 11

Recommendations

  • CI checks not green

@claude claude Bot added area:documentation Docs & guides area:tests Test suites & harnesses lang:js JavaScript/TypeScript lang:md Markdown content/docs labels Sep 2, 2026
@claude claude Bot added the type:bug Bug or defect label Sep 2, 2026
@ashleyshaw ashleyshaw added type:feature Feature or enhancement and removed type:bug Bug or defect area:documentation Docs & guides labels Sep 3, 2026 — with Claude
…nt nullish coalescing)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🔍 Reviewer Summary for PR #2487

CI Status:pending
Files changed: 11

Recommendations

  • CI checks not green

@ashleyshaw ashleyshaw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved

@ashleyshaw
ashleyshaw merged commit ae3497b into develop Sep 3, 2026
31 of 46 checks passed
@ashleyshaw
ashleyshaw deleted the copilot/reporting-agent-v2-rate-limiting branch September 3, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tests Test suites & harnesses lang:js JavaScript/TypeScript lang:md Markdown content/docs type:feature Feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reporting Agent v2 Phase 2.4: Rate Limiting & Backoff Strategy

4 participants