Skip to content

Fix AI credits throughput rate-limit errors being silently swallowed - #49360

Merged
pelikhan merged 3 commits into
mainfrom
copilot/fix-copilot-issue
Jul 31, 2026
Merged

Fix AI credits throughput rate-limit errors being silently swallowed#49360
pelikhan merged 3 commits into
mainfrom
copilot/fix-copilot-issue

Conversation

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

shouldReportAICreditsRateLimitError gated on aiCredits >= maxAICredits, so a real Copilot API 429 throughput throttle (credits below budget) was suppressed and fell through to the generic "engine terminated unexpectedly" path instead of surfacing a meaningful error.

Changes

  • ai_credits_context.cjs — Removed the aiCredits >= maxAICredits guard; shouldReportAICreditsRateLimitError now returns hasRateLimitSignal unconditionally.

  • handle_agent_failure.cjs — Added isBudgetExceeded param to buildAICreditsRateLimitErrorContext to select the correct template at both call sites. When false, renders the new throughput throttle template; when true, renders the existing budget-exhaustion template.

  • ai_credits_rate_limit_throttle.md (new) — Separate error template for throughput 429s. Omits the "Increase the limit" guidance that only applies to budget exhaustion.

  • Tests — Updated existing tests to pass isBudgetExceeded=true; added new tests covering the under-budget throughput throttle case.

Before / After

// Before: 236 AIC used, max 1000 → suppressed
shouldReportAICreditsRateLimitError(true, "236", "1000") // → false ❌

// After: signal present → always reported
shouldReportAICreditsRateLimitError(true) // → true ✅

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.19 AIC · ⊞ 8.1K ·
Comment /souschef to run again


Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.88 AIC · ⊞ 8.1K ·
Comment /souschef to run again


Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.62 AIC · ⊞ 8.1K ·
Comment /souschef to run again


Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Run: https://github.com/github/gh-aw/actions/runs/30660114445

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.2 AIC · ⊞ 5.7K ·
Comment /souschef to run again

…ately from budget exhaustion

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with Copilot integration Fix AI credits throughput rate-limit errors being silently swallowed Jul 31, 2026
Copilot AI requested a review from pelikhan July 31, 2026 15:58
@pelikhan
pelikhan marked this pull request as ready for review July 31, 2026 16:35
Copilot AI review requested due to automatic review settings July 31, 2026 16:35
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #49360 does not have the 'implementation' label and has 0 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

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.

Pull request overview

Fixes under-budget Copilot API throughput throttles so they produce actionable AI credits errors.

Changes:

  • Reports all detected AI credits rate-limit signals.
  • Selects separate budget-exhaustion and throughput-throttle templates.
  • Adds regression coverage for under-budget throttling.
Show a summary per file
File Description
actions/setup/md/ai_credits_rate_limit_throttle.md Adds throughput-throttle guidance.
actions/setup/js/handle_agent_failure.cjs Selects the appropriate rate-limit template.
actions/setup/js/handle_agent_failure_max_ai_credits_exceeded.test.cjs Updates budget-exhaustion tests.
actions/setup/js/handle_agent_failure_ai_credits_rate_limit.test.cjs Tests throughput rendering.
actions/setup/js/ai_credits_context.test.cjs Covers under-budget signals.
actions/setup/js/ai_credits_context.cjs Reports rate-limit signals unconditionally.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 6/6 changed files
  • Comments generated: 2
  • Review effort level: Balanced

> [!WARNING]
> **AI Credits Rate Limit**
>
> The Copilot API returned a rate limit response (HTTP 429) before the workflow's AI credits budget was exhausted.{metrics_summary}
Comment on lines +62 to +63
function shouldReportAICreditsRateLimitError(hasRateLimitSignal) {
return hasRateLimitSignal;

@github-actions github-actions Bot 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.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

The fix is correct and well-tested.

  • shouldReportAICreditsRateLimitError simplification is sound — removing the aiCredits >= maxAICredits guard means any genuine 429 signal is now surfaced regardless of budget position.
  • The isBudgetExceeded discriminator at both call sites correctly uses maxAICreditsExceeded to select the right template.
  • The new ai_credits_rate_limit_throttle.md template appropriately omits the "Increase the limit" guidance that only applies to budget exhaustion.
  • Tests cover both the under-budget throttle scenario and the existing budget-exceeded paths.

One minor observation: suggestedCredits is computed even when isBudgetExceeded=false (throttle path), though it is unused in that template. The code comment acknowledges this as harmless — no action needed.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 14.9 AIC · ⊞ 5.3K

@github-actions

Copy link
Copy Markdown
Contributor

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🧪 Test Quality Sentinel Report

Test Quality Score: 90/100 — Excellent

Analyzed 4 test(s): 4 design, 0 implementation, 0 violation(s).

📊 Metrics (4 tests)
Metric Value
Analyzed 4 (Go: 0, JS: 4)
✅ Design 4 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 4 (100%)
Duplicate clusters 0
Inflation YES (ai_credits_context.test.cjs +22 vs prod +3, ratio 7.3:1)
🚨 Violations 0
Test File Classification Issues
reports aiCreditsRateLimitError when rate-limit signal present but under budget ai_credits_context.test.cjs design_test / behavioral_contract / high_value none
reports aiCreditsRateLimitError from env signal combined with env AIC evidence when under budget ai_credits_context.test.cjs design_test / behavioral_contract / high_value none
shows throughput rate-limit message when under budget (isBudgetExceeded=false) handle_agent_failure_ai_credits_rate_limit.test.cjs design_test / behavioral_contract / high_value none
defaults to throughput template when isBudgetExceeded is omitted handle_agent_failure_ai_credits_rate_limit.test.cjs design_test / behavioral_contract / high_value none
i️ Inflation Note

ai_credits_context.test.cjs added 22 lines against 3 production-side additions (7.3:1 ratio), triggering the mechanical inflation flag and costing 10 points. This is not a real quality concern — the production fix was a surgical condition change; the tests intentionally add thorough coverage of the newly separated code path.

Verdict

passed. 0% implementation tests (threshold: 30%). All 4 new tests directly cover the behavioral fix: throughput rate-limit errors are no longer silently swallowed when the agent is under budget.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 42.8 AIC · ⊞ 8.4K ·
Comment /review to run again

@github-actions github-actions Bot 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.

✅ Test Quality Sentinel: 90/100. 0% implementation tests (threshold: 30%). All 4 new tests are behavioral contracts directly covering the throughput rate-limit fix.

@github-actions github-actions Bot 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.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — approving with minor suggestions.

📋 Key Themes & Highlights

Key Themes

  • Root cause addressed cleanly: the faulty aiCredits >= maxAICredits gate was doing double-duty as a budget check when it should only gate on the presence of the signal itself. The fix is correct and minimal.
  • Good dual-template split: separating throughput vs. budget-exhaustion messages prevents confusing "Increase the limit" advice from appearing in the wrong context.
  • Minor gaps: suggestedCredits is still computed when unused (throughput path), and the new throttle template has an edge-case wording issue when no budget is configured. Both are low risk.

Positive Highlights

  • ✅ Excellent regression test added at the exact scenario from the failing run (236/1000 AIC)
  • ✅ Both call sites in main() updated consistently — no risk of one path lagging behind
  • ✅ Existing tests updated to be explicit about isBudgetExceeded=true intent (see the comment added in handle_agent_failure_max_ai_credits_exceeded.test.cjs)
  • ✅ Simplification of shouldReportAICreditsRateLimitError is welcome — the function is now a pure signal passthrough, removing hidden coupling to credit accounting

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 37 AIC · ⊞ 7K
Comment /matt to run again

throw new Error(`failed to resolve template path for ${templateName} (${getErrorMessage(error)}); ensure RUNNER_TEMP or GH_AW_PROMPTS_DIR is set and the template file exists`, { cause: error });
}

// Suggest a new limit: 2x current max, or 2x actual usage if max is unknown, or a reasonable default

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.

[/diagnosing-bugs] suggestedCredits is computed unconditionally but is only consumed by the budget-exceeded template — the new throughput template does not use it. This is harmless today, but obscures the intent and could mislead future maintainers.

💡 Suggested fix

Guard the computation inside the budget-exceeded branch:

const suggestedCredits = isBudgetExceeded
  ? (baseForSuggestion > 0 ? Math.ceil(baseForSuggestion * 2) : 2000)
  : undefined;

This makes it explicit that suggestedCredits belongs to the budget-exceeded path only.

@copilot please address this.


expect(rendered).toContain("AI Credits Rate Limit");
expect(rendered).not.toContain("AI Credits Budget Exceeded");
// inline metrics show usage without an overage

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.

[/tdd] The test asserts toContain("Used \236.1` of `1K` max")— this implicitly tests the rounding/formatting logic that lives inhandle_agent_failure.cjs. A follow-on test covering the edge case where both aiCreditsandmaxAICredits` are empty strings (under the throughput path) would close the coverage gap left by the analogous budget-exceeded test at line 53 of the other test file.

💡 Suggested test
it("shows throughput message without metrics when no credit data is available", () => {
  const rendered = buildAICreditsRateLimitErrorContext(true, "", "", "", false);
  expect(rendered).toContain("AI Credits Rate Limit");
  expect(rendered).not.toContain("Used");
});

@copilot please address this.

@@ -0,0 +1,14 @@
> [!WARNING]
> **AI Credits Rate Limit**
>

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.

[/diagnosing-bugs] The template text says "before the workflow's AI credits budget was exhausted" — this is slightly misleading when maxAICredits is not configured (i.e. there is no budget). Consider phrasing it as "before the configured AI credits budget was reached (or no budget was set)" to handle the zero-budget case clearly.

@copilot please address this.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@copilot please run the pr-finisher skill on this PR, investigate the failing check agent (https://github.com/github/gh-aw/actions/runs/30647761131/job/91213895550), bring the branch up to date if GitHub allows it, and rerun the relevant checks once ready. Run details: https://github.com/github/gh-aw/actions/runs/30649242507

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.19 AIC · ⊞ 8.1K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

[!WARNING]
threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding....

Addressed the follow-up review findings in e767884: removed the dead helper, limited suggestedCredits to the budget-exceeded path, clarified the throughput-throttle template wording, and added the missing no-metrics throughput test. I investigated the failed agent check and it was failing on actionable review feedback rather than an infra error. The branch already contains origin/main, so there was nothing to update. Local validation passed (npm run test:js -- --run handle_agent_failure_ai_credits_rate_limit.test.cjs ai_credits_context.test.cjs, npm run lint:cjs, make check-cjs-syntax, make agent-report-progress). I can’t rerun GitHub Actions from this Copilot cloud agent, so CI on the new head still needs a maintainer-triggered rerun.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@copilot please run the pr-finisher skill on this PR.

Unresolved review threads remain, newest first:

The latest branch update is requested via GitHub. Please confirm the branch is current, address the remaining review feedback, and then run the pr-finisher skill handoff with any validation results you can complete locally. Latest sous-chef run: https://github.com/github/gh-aw/actions/runs/30654786429

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.62 AIC · ⊞ 8.1K ·
Comment /souschef to run again

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

[!WARNING]
threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding....

Verified the branch is current with main and the unresolved feedback is already satisfied on e767884. In this pass I unshallowed the checkout/fetched origin/main so repo validation could run correctly, then revalidated the PR head locally: make agent-report-progress ✅, make test ✅, targeted JS tests for the AI-credits paths ✅, npm run lint:cjs ✅, and make check-cjs-syntax ✅. The earlier agent failure was review-feedback driven rather than a new product/test failure. I can’t re-trigger GitHub Actions or resolve the stale review threads from this Copilot cloud agent, so CI on the current head still needs a maintainer-triggered rerun.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Triage

Category: bug | Risk: medium | Score: 78/100 (impact 35, urgency 25, quality 18)

Recommended action: fast_track

Real bug fix — a genuine 429 throughput throttle was being silently swallowed and surfaced as a generic engine-terminated error. Non-draft, 3 automated approvals, CI in progress. High-value fix; worth expediting human review once CI completes.

Generated by 🔧 PR Triage Agent · auto · 43.6 AIC · ⌖ 5.01 AIC · ⊞ 7.9K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@copilot please run the pr-finisher skill on this PR.

Unresolved review threads remain, newest first:

The latest branch update was requested via GitHub. Please confirm the branch is current, address the remaining review feedback, and then run the pr-finisher skill handoff with any validation results you can complete locally. Latest sous-chef run: https://github.com/github/gh-aw/actions/runs/30660114445

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.2 AIC · ⊞ 5.7K ·
Comment /souschef to run again

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

[!WARNING]
threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding....

Confirmed the branch is still current with main and the latest sous-chef run (30660114445) is not a failing PR check on this branch; it is a successful scheduled PR Sous Chef run on main. The current PR head is still e767884, three commits ahead of main, and local validation is green again on that head: targeted AI-credits JS tests ✅, npm run lint:cjs ✅, make check-cjs-syntax ✅, make agent-report-progress ✅, and make test ✅. The remaining blocker is still the same stale unresolved review-thread state; I don’t have a tool in this cloud-agent environment to resolve those existing threads or re-trigger GitHub Actions.

@pelikhan
pelikhan merged commit 498f17f into main Jul 31, 2026
10 checks passed
@pelikhan
pelikhan deleted the copilot/fix-copilot-issue branch July 31, 2026 20:52
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.84.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants