← Back to Pull requests

fix(kiro): count active bonus credits as their own quota window #21811

Open
unknown opened this pull request with 291 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 30, 2026 15:10 UTC
Author

Summary


  • Kiro grants one-off bonus credits next to the monthly limit, such as the FIRST_UPGRADE_TRIAL 500 credits of a first Pro upgrade, valid for a year. GetUsageLimits lists them under the breakdown's bonuses, and Kiro spends them after the monthly credits run out, so an account whose monthly limit is spent still serves requests.

  • buildKiroUsageResult() ignored bonuses. Such an account reported only the spent credit window, and quota-aware selection skipped it as exhausted while it still had hundreds of credits. When it was the last Kiro account with balance for a paid model, every request for that model failed.

  • Active, unexpired bonuses are now summed into a <resource>_bonus window (e.g. credit_bonus) that resets at the earliest expiry. Quota-aware selection treats an account as exhausted only when every window is spent, so the account stays routable while its bonus lasts. Accounts without bonuses are unchanged.
  • Related Issues


  • None found.
  • Target Branch


  • Base is the active release/v3.8.55 branch

  • New feature? (no, bug fix)
  • Validation


  • Change type: provider / usage

  • Failing-then-passing test: 4 of the 6 new cases fail on the base and pass with the fix

  • Every unit file that imports buildKiroUsageResult or the Kiro usage fetcher rerun (48 tests, all pass); npm run typecheck:core clean; eslint and prettier clean on the changed files

  • npm run lint (full run left to CI)

  • Production-code changes include a new automated test

  • Live: on my own instance a Pro account with its monthly credits spent and a trial bonus left was skipped by quota-aware selection; after the change its credit_bonus window showed the remaining balance and a paid-model request was served by it.
  • Tests Added Or Updated


  • tests/unit/kiro-bonus-credits-usage.test.ts (new)
  • Coverage Notes


  • The new test covers the bonus window (single and multiple bonuses, earliest expiry), the cases that add no window (expired, inactive, zero limit, no bonuses list), a fully spent bonus, and that isExhausted(normalizeQuotas(...)) is false with bonus balance and true without.
  • Reviewer Notes


  • expiresAt is epoch seconds in GetUsageLimits; milliseconds are accepted too.

  • The dashboard shows the new window as an extra quota row next to credit.
  • Diff: 291 lines (+218 / -73) across 3 files Reviewer: coderabbitai[bot] Review duration: 7m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 291 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.340
    Real PR Conversation Timeline
    1 comments
    "Review active on #21811"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.9% (MEDIUM) · Higher = larger blast radius
    39.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.3% · Safe to merge
    21.3%