Fix azure cost rate limiting - #1766
Conversation
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>
There was a problem hiding this comment.
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-afterheaders and wait for the maximum. - Add
--headers "ClientType=GitHubCopilotForAzure"toaz restexamples 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. |
Jon Gallant (jongio)
left a comment
There was a problem hiding this comment.
Two things to address:
-
cost-optimization/azure-aks-anomalies.md(line 12) has anaz restcall that's missing the newClientTypeheader. Since SKILL.md now requires it on all Cost Management API requests, this file should be updated too. (Not in this diff, so noting here.) -
The test invocation threshold drop (0.8 to 0.6) weakens the quality gate - see inline comment.
Everything else looks solid - the casing fix is consistent across all cost-query files, the 429 retry guidance is thorough, and the rate-limit threshold tables are a useful addition.
Jon Gallant (jongio)
left a comment
There was a problem hiding this comment.
The three fixes are solid and consistent:
- 429 retry handling now covers all three retry-after headers across every file that references rate limiting
- ClientType header is on all
az restcode blocks (including the azure-aks-anomalies.md that was missing before) - Filter schema casing is lowercase everywhere it needs to be
One thing still worth resolving: the threshold math on the test. With RUNS_PER_PROMPT=3 and invocationRateThreshold=0.8, the effective requirement is ceil(3 * 0.8) = 3 - all 3 runs must pass. Before, ceil(5 * 0.8) = 4, so 4/5 had to pass (one failure tolerated). The effective pass rate actually went up from 80% to 100%, which makes the test more brittle, not less.
If the rate-limit fix + ClientType bucketing are expected to eliminate 429 flakiness entirely, keeping 0.8 is fine - it just means zero tolerance. If there's still residual risk, threshold=0.67 would restore the previous one-failure tolerance with 3 runs.
Also: cost-query/workflow.md Key Guardrails table (line 102) still says "Filter AND/OR" - should be lowercase to match the rest of the casing changes. One-line fix.
|
casing issue and threshold fixed. approved |
* Fix azure-cost 40% failure rate from Cost Management API rate limiting 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> * fix casing for request body of forecast and query * fix PR comments * add headers and upgrade invocation rate threshold * update casing in guardrails --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Description
Addresses three issues with the azure-cost skill across 11 files:
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:
per-tenant, per-client-type)
longest value
0.8→0.6 to stay within per-scope limits
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.
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):
Updated in request-body-schema.md, examples.md, and guardrails.md.
Checklist
1.1.0)
Related Issues