From daf655dff8221e68650c64dfe84798baccfa6ce9 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Mon, 27 Jul 2026 18:54:56 +0100 Subject: [PATCH] fix(coderd/x/chatd/chaterror): classify aibridge 403 as ChatErrorKindUsageLimit (#27538) Adds the string `ai budget` to the classifier for `ChatErrorKindUsageLimit`. Screenshot 2026-07-27 at 18 27 13 Testing notes: - I set the group limit by running `insert into group_ai_budgets values ('', 1, NOW(), NOW());` > Created by a human, trimmed down by a Coder agent. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- coderd/x/chatd/chaterror/classify_test.go | 2 ++ coderd/x/chatd/chaterror/signals.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/coderd/x/chatd/chaterror/classify_test.go b/coderd/x/chatd/chaterror/classify_test.go index 2ab7549e59..2db9ab5a1a 100644 --- a/coderd/x/chatd/chaterror/classify_test.go +++ b/coderd/x/chatd/chaterror/classify_test.go @@ -503,6 +503,8 @@ func TestClassify_PatternCoverage(t *testing.T) { {name: "QuotaLiteral", err: "quota", wantKind: codersdk.ChatErrorKindUsageLimit, wantRetry: false}, {name: "BillingLiteral", err: "billing", wantKind: codersdk.ChatErrorKindUsageLimit, wantRetry: false}, {name: "InsufficientQuotaLiteral", err: "insufficient_quota", wantKind: codersdk.ChatErrorKindUsageLimit, wantRetry: false}, + {name: "AIBudgetExceededLiteral", err: "status 403: AI budget of US$10.00 exceeded", wantKind: codersdk.ChatErrorKindUsageLimit, wantRetry: false}, + {name: "AIBudgetCheckFailedLiteral", err: "status 500: internal server error checking user AI budget", wantKind: codersdk.ChatErrorKindGeneric, wantRetry: true}, {name: "PaymentRequiredLiteral", err: "payment required", wantKind: codersdk.ChatErrorKindUsageLimit, wantRetry: false}, {name: "ForbiddenLiteral", err: "forbidden", wantKind: codersdk.ChatErrorKindAuth, wantRetry: false}, {name: "InvalidModelLiteral", err: "invalid model", wantKind: codersdk.ChatErrorKindConfig, wantRetry: false}, diff --git a/coderd/x/chatd/chaterror/signals.go b/coderd/x/chatd/chaterror/signals.go index 4f004e150b..15f439df3e 100644 --- a/coderd/x/chatd/chaterror/signals.go +++ b/coderd/x/chatd/chaterror/signals.go @@ -73,7 +73,7 @@ var ( } // Hard usage exhaustion codes that fire at any HTTP status, // including 429. - usageLimitAnyStatusPatterns = []string{"insufficient_quota"} + usageLimitAnyStatusPatterns = []string{"insufficient_quota", "ai budget of"} configPatterns = []string{ "invalid model", "model not found",