#6014: Agents: improve quota exhaustion fallback detection
agents
Cluster:
Quota Management Improvements
## Summary
- expand failover classification to catch quota/capacity exhaustion variants and insufficient_quota
- add tests to cover the new classification paths
## Testing
- pnpm vitest src/agents/pi-embedded-helpers.classifyfailoverreason.test.ts --maxWorkers=1
- pnpm vitest src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts --maxWorkers=1
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR broadens the heuristic error classification in `src/agents/pi-embedded-helpers/errors.ts` to recognize more quota/capacity exhaustion phrases and to treat `insufficient_quota` as a billing signal. It also adds Vitest coverage to ensure `classifyFailoverReason` and `isBillingErrorMessage` exercise these new branches.
Overall the change fits the existing design: `classifyFailoverReason` is a thin wrapper over message-pattern matchers used to decide whether a failure should be treated as retryable/failoverable and why.
<h3>Confidence Score: 3/5</h3>
- This PR is likely safe to merge, but the expanded substring heuristics could cause some new misclassifications depending on upstream error text.
- Changes are localized to string-pattern matching plus targeted tests. Main risk is behavioral: newly added broad substrings (e.g., "quota reset") may match unrelated errors, and mapping `insufficient_quota` to billing may not align with how some providers use that code.
- src/agents/pi-embedded-helpers/errors.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#11170: fix: classify subscription quota limit errors as rate_limit for fai...
by Yida-Dev · 2026-02-07
82.1%
#23520: fix: trigger failover on Anthropic insufficient_quota (HTTP 400) (#...
by dissaozw · 2026-02-22
81.6%
#22359: fix(agents): classify overloaded service errors as timeout
by AIflow-Labs · 2026-02-21
79.4%
#12314: fix: treat HTTP 5xx server errors as failover-worthy
by hsssgdtc · 2026-02-09
79.0%
#23502: fix: Anthropic insufficient_quota HTTP 400 does not trigger failove...
by stakeswky · 2026-02-22
78.8%
#10178: fix: trigger fallback when model resolution fails with unknown model
by Yida-Dev · 2026-02-06
77.9%
#15109: fix: distinguish transient API errors from billing errors
by jwchmodx · 2026-02-13
77.8%
#16307: fix: surface billing/auth FailoverErrors as user-friendly messages
by petter-b · 2026-02-14
76.6%
#7229: fix: add network error resilience to agentic loop failover
by ai-fanatic · 2026-02-02
76.1%
#11174: Fix/fried chicken error
by jfgrissom · 2026-02-07
75.9%