← Back to PRs

#23502: fix: Anthropic insufficient_quota HTTP 400 does not trigger failover (#23440)

by stakeswky open 2026-02-22 11:04 View on GitHub →
app: web-ui size: XS
## Summary Fixes #23440. Anthropic returns HTTP 400 (not 402/429) when an account runs out of credits, with an `insufficient_quota` error code in the message. Two bugs prevented failover from triggering: ### Root cause 1 — HTTP 400 masking in `resolveFailoverReasonFromError` ```ts // before if (status === 400) return "format"; // after if (status === 400 && !classifyFailoverReason(getErrorMessage(err))) return "format"; ``` The hardcoded early-return meant the message was never inspected. Now HTTP 400 only resolves to `"format"` when the message doesn't match any known failover pattern. ### Root cause 2 — Missing keywords in `ERROR_PATTERNS.billing` Added `"insufficient_quota"` and `"insufficient quota"` to the billing pattern list so `isBillingErrorMessage()` correctly identifies Anthropic quota errors. ## Tests - Added `isBillingErrorMessage` test cases for `insufficient_quota` / `insufficient quota` variants - Added `resolveFailoverReasonFromError` test cases asserting HTTP 400 + quota message → `"billing"`, and plain HTTP 400 still → `"format"` - All 40 tests pass (`vitest.e2e.config.ts`) <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR fixes a data loss issue when editing agent configurations through the dashboard. Previously, using `saveConfig()` with `config.set` would replace the entire agents array, silently removing any agents that were added or modified externally (via CLI or file edits) between page load and save. The fix introduces `patchAgentsConfig()` which uses `config.patch` with array merging by ID, preserving external changes while updating only the agents visible in the dashboard. <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with low risk of issues - The implementation is straightforward and well-tested (existing e2e tests verify `config.patch` behavior with agent merging). The change is scoped to only agent-related save operations, leaving other config saves unchanged. The server-side `config.patch` method already has validation and proper error handling. - No files require special attention <sub>Last reviewed commit: 2b47641</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs