From 5353ed54fe2bdc1814e3fb22218d5e5e523e964d Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 30 Sep 2026 00:38:10 +0800 Subject: [PATCH] =?UTF-8?q?gateway:=20a=20vendor=20refusing=20the=20client?= =?UTF-8?q?=20outright=20(WorkBuddy's=20400=20"Illegal=20API=20invocation?= =?UTF-8?q?=20from=20an=20unapproved=20channel")=20hands=20a=20group's=20r?= =?UTF-8?q?equest=20to=20its=20next=20member=20(PR=20#232=20Y-C-Fan:=20a?= =?UTF-8?q?=20routing=20group=20stopped=20at=20a=20WorkBuddy=20member=20re?= =?UTF-8?q?fusing=20Claude=20Code's=20chats)=20=E2=80=94=20retryable=20let?= =?UTF-8?q?=20a=20400=20fall=20over=20only=20on=20quota=20or=20unserved-mo?= =?UTF-8?q?del=20words,=20so=20this=20refusal,=20which=20is=20of=20the=20p?= =?UTF-8?q?rovider=20and=20not=20the=20request,=20went=20back=20to=20the?= =?UTF-8?q?=20agent.=20A=20new=20refusedWords=20(unapproved=20channel,=20i?= =?UTF-8?q?llegal=20api=20invocation)=20joins=20them.=20The=20request=20bo?= =?UTF-8?q?dy=20is=20not=20changed:=20a=20chat=20opening=20with=20Claude?= =?UTF-8?q?=20Code's=20own=20system=20prompt=20is=20still=20sent=20as=20it?= =?UTF-8?q?=20came.=20Tested=20with=20a=20new=20case=20in=20TestGroupFails?= =?UTF-8?q?OverAnUnservedModel's=20retryable=20table=20(false=20before)=20?= =?UTF-8?q?and=20the=20gateway=20package.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gateway/fallback.go | 8 +++++++- internal/gateway/retry_test.go | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/gateway/fallback.go b/internal/gateway/fallback.go index 744f6aea0..f7e7868d9 100644 --- a/internal/gateway/fallback.go +++ b/internal/gateway/fallback.go @@ -411,6 +411,12 @@ var quotaWords = regexp.MustCompile(`(?i)quota|insufficient|balance|credit|billi // key, or this way — words another provider, or key, may not answer with. var unservedWords = regexp.MustCompile(`(?i)model.{0,80}(not (supported|accessible|available|found|enabled|allowed)|unsupported|does ?n[o']t exist|unknown|invalid)|(no such|unknown|invalid|unsupported) model|model_not_found|模型.{0,12}(不存在|不支持|无权|未开通)`) +// refusedWords are how a vendor says it won't take requests from this +// client at all — WorkBuddy's "Illegal API invocation from an unapproved +// channel" to a chat opening with another agent's own system prompt — a +// refusal of the provider, not of the request, another member may serve. +var refusedWords = regexp.MustCompile(`(?i)unapproved channel|illegal api invocation`) + // retryable says whether another provider may do better with a request // that failed this way: the vendor was busy, out of quota or failing, or // this key or provider can't serve it — not the request itself at fault. @@ -419,7 +425,7 @@ func retryable(status int, body []byte) bool { case status == 401, status == 402, status == 403, status == 404, status == 408, status == 429, status >= 500: return true case status == 400, status == 422: - return quotaWords.Match(body) || unservedWords.Match(body) + return quotaWords.Match(body) || unservedWords.Match(body) || refusedWords.Match(body) } return false } diff --git a/internal/gateway/retry_test.go b/internal/gateway/retry_test.go index 7d720fa1f..44d70e5a5 100644 --- a/internal/gateway/retry_test.go +++ b/internal/gateway/retry_test.go @@ -90,6 +90,7 @@ func TestGroupFailsOverAnUnservedModel(t *testing.T) { {400, `{"error":{"message":"The model gpt-x does not exist"}}`, true}, {400, `{"error":{"message":"messages: field required"}}`, false}, {400, `{"error":{"message":"This model's maximum context length is 128000 tokens"}}`, false}, + {400, `{"error":{"message":"Illegal API invocation from an unapproved channel"}}`, true}, } { if got := retryable(x.status, []byte(x.body)); got != x.want { t.Errorf("retryable(%d, %s) = %v", x.status, x.body, got)