Skip to content

Fix azure cost rate limiting#1766

Open
taylorak wants to merge 3 commits intomicrosoft:mainfrom
taylorak:taylorak/fix-azure-cost-rate-limiting
Open

Fix azure cost rate limiting#1766
taylorak wants to merge 3 commits intomicrosoft:mainfrom
taylorak:taylorak/fix-azure-cost-rate-limiting

Conversation

@taylorak
Copy link
Copy Markdown
Collaborator

@taylorak taylorak commented Apr 7, 2026

Description

Addresses three issues with the azure-cost skill across 11 files:

  1. Rate-Limit Retry Handling — AB#37441409

The skill had a 40% integration test failure rate caused by Cost Management API 429 responses. The agent was not properly waiting between requests,
violating the per-scope limit of 4 requests/minute.

Changes:

  • Added rate-limit threshold tables to cost-query/guardrails.md and cost-forecast/guardrails.md documenting all five tiers (per-user, per-scope,
    per-tenant, per-client-type)
  • Added 429 handling sections instructing the agent to read all three x-ms-ratelimit-microsoft.costmanagement-*-retry-after headers and wait for the
    longest value
  • Updated error-handling.md in both cost-query and cost-forecast to reference all three retry-after headers
  • Expanded rate-limit guidance in cost-query/workflow.md and cost-optimization/workflow.md
  • Added rate-limit best practice to SKILL.md
  • Reduced test RUNS_PER_PROMPT from 5→3 and invocationRateThreshold from
    0.8→0.6 to stay within per-scope limits
  1. ClientType Request Header

Added --headers "ClientType=GitHubCopilotForAzure" to all az rest commands in cost-query, cost-forecast, and cost-optimization workflows. This enables
per-client-type rate-limit bucketing (2,000 req/min) and telemetry attribution for requests originating from GitHub Copilot.

  1. Filter Schema Casing — AB#37400748

Fixed filter JSON property names from PascalCase → lowercase to match the official Query API docs (
https://learn.microsoft.com/en-us/rest/api/cost-management/query/usage?view=rest-cost-management-2023-11-01):

  • And→and, Or→or, Not→not
  • Dimensions→dimensions, Tags→tags
  • Name→name, Operator→operator, Values→values

Updated in request-body-schema.md, examples.md, and guardrails.md.

Checklist

  • Tests pass locally — 441 tests ✅
  • If modifying skill descriptions: verified routing correctness
  • If modifying USE FOR/DO NOT USE FOR/PREFER OVER: confirmed no routing regressions
  • Version bumped in skill frontmatter (1.0.0 →
    1.1.0)

Related Issues

taylorak and others added 2 commits April 7, 2026 13:55
Update skill documentation to teach the agent proper 429 retry-after
header handling across all three Cost Management rate-limit headers:
- x-ms-ratelimit-microsoft.costmanagement-qpu-retry-after
- x-ms-ratelimit-microsoft.costmanagement-entity-retry-after
- x-ms-ratelimit-microsoft.costmanagement-tenant-retry-after

The agent must check whichever headers are present, take the maximum
retry-after value, and not retry until that duration has elapsed.

Skill doc changes:
- Add rate limit thresholds table to cost-query and cost-forecast guardrails
- Add 'Handling 429 Responses' section with all-headers guidance
- Fix 429 retry rows in error-handling.md to reference all 3 headers
- Add per-scope rate limit warnings in workflow files
- Add rate-limit best practice to SKILL.md, bump version to 1.1.0

Test changes:
- Reduce RUNS_PER_PROMPT from 5 to 3 to lower rate limit pressure
- Lower invocationRateThreshold from 0.8 to 0.6 (2/3 must pass)
- Add new 429 response-quality test for rate limit handling

Resolves AB#37441409

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 7, 2026 23:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the azure-cost skill documentation and tests to reduce Cost Management API rate-limit flakiness (429s), ensure requests use a ClientType header for improved throttling bucketing/telemetry, and correct filter schema casing to match the Cost Query API.

Changes:

  • Document improved 429 handling: read all x-ms-ratelimit-microsoft.costmanagement-*-retry-after headers and wait for the maximum.
  • Add --headers "ClientType=GitHubCopilotForAzure" to az rest examples and reinforce the requirement in workflows/skill guidance.
  • Update filter JSON schema/examples from PascalCase to lowercase, and reduce integration test repetitions/thresholds to stay under per-scope limits.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/azure-cost/integration.test.ts Lowers runs/thresholds to reduce rate-limit-driven integration test flakiness.
plugin/skills/azure-cost/SKILL.md Bumps skill version and adds best-practice guidance for ClientType + 429 retry headers.
plugin/skills/azure-cost/cost-query/workflow.md Adds ClientType header to az rest examples and expands 429 guidance.
plugin/skills/azure-cost/cost-query/request-body-schema.md Fixes filter schema casing to lowercase keys per API docs.
plugin/skills/azure-cost/cost-query/guardrails.md Adds rate-limit threshold table and clarifies 429 handling / header semantics.
plugin/skills/azure-cost/cost-query/examples.md Updates example filter JSON casing (tags/name/operator/values).
plugin/skills/azure-cost/cost-query/error-handling.md Updates 429 retry strategy to check all retry-after headers.
plugin/skills/azure-cost/cost-optimization/workflow.md Adds explicit guidance to include ClientType header and respect per-scope throttling.
plugin/skills/azure-cost/cost-forecast/workflow.md Adds ClientType header to az rest example.
plugin/skills/azure-cost/cost-forecast/guardrails.md Adds rate-limit thresholds and 429 handling guidance for Forecast API.
plugin/skills/azure-cost/cost-forecast/error-handling.md Updates 429 retry strategy to check all retry-after headers.

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.

2 participants