diff --git a/changelog/unreleased/codearts-credit-exhausted-cooldown.md b/changelog/unreleased/codearts-credit-exhausted-cooldown.md new file mode 100644 index 000000000..035161b46 --- /dev/null +++ b/changelog/unreleased/codearts-credit-exhausted-cooldown.md @@ -0,0 +1,7 @@ +### English + +- Huawei Cloud CodeArts accounts now enter quota cooldown and fail over when chat returns TM.00001050 (积分已耗尽). That response was previously treated as an invalid request, so the exhausted account stayed in rotation. + +### 中文 + +- 华为云码道聊天返回 TM.00001050(积分已耗尽)时,账号会进入额度冷却并切换到其他账号。此前该响会被当成无效请求,耗尽的账号会继续被调度。 diff --git a/internal/providers/codearts/codearts_test.go b/internal/providers/codearts/codearts_test.go index 767163026..49badaeec 100644 --- a/internal/providers/codearts/codearts_test.go +++ b/internal/providers/codearts/codearts_test.go @@ -1010,6 +1010,36 @@ func TestClassifyEmbeddedBadRequestCodeIsInvalidRequest(t *testing.T) { } } +// TM.00001050 is Huawei's credit-exhausted business error ("您的积分已耗尽"). +// It arrives as an HTTP 400 body or as the first SSE data frame. Either form +// must be quota, so the account cools down and the route fails over. +func TestClassifyCreditsExhaustedIsQuota(t *testing.T) { + body := `{"text":"[DONE]","error_code":"TM.00001050","error_msg":"您的积分已耗尽,请关注活动积分领取活动或者升级套餐。"}` + for _, status := range []int{http.StatusBadRequest, http.StatusBadGateway, http.StatusOK} { + got := Classify(status, body) + if got.Kind != accounts.KindQuota || got.Status != http.StatusPaymentRequired { + t.Fatalf("status %d = %+v", status, got) + } + } + wrapped := (&upstreamError{Code: "TM.00001050", Msg: "您的积分已耗尽"}).Error() + if got := Classify(http.StatusBadGateway, wrapped); got.Kind != accounts.KindQuota { + t.Fatalf("wrapped = %+v", got) + } + codeOnly := `{"error_code":"TM.00001050","error_msg":"request failed"}` + if got := Classify(http.StatusBadRequest, codeOnly); got.Kind != accounts.KindQuota { + t.Fatalf("code only = %+v", got) + } +} + +func TestPreflightSSECreditsExhaustedIsQuota(t *testing.T) { + frame := "data:{\"text\":\"[DONE]\",\"error_code\":\"TM.00001050\",\"error_msg\":\"您的积分已耗尽\"}\n" + _, err := preflightSSE(io.NopCloser(strings.NewReader(frame))) + var providerErr *providers.Error + if !errors.As(err, &providerErr) || providerErr.Kind != accounts.KindQuota || providerErr.Status != http.StatusPaymentRequired { + t.Fatalf("preflight err = %#v", err) + } +} + func TestPreflightSSEEmbeddedImageRejectionIsInvalidRequest(t *testing.T) { frame := "data:{\"text\":\"[DONE]\",\"error_code\":\"InferHub.ModelArts.81001.400\",\"error_msg\":\"the content of image_url.url field is unsafe\"}\n" _, err := preflightSSE(io.NopCloser(strings.NewReader(frame))) diff --git a/internal/providers/codearts/errors.go b/internal/providers/codearts/errors.go index 84813aad6..994541a94 100644 --- a/internal/providers/codearts/errors.go +++ b/internal/providers/codearts/errors.go @@ -53,6 +53,12 @@ var quotaMarkers = []string{ "insufficient balance", "余额不足", "积分不足", + // TM.00001050 is the credit-exhausted business error ("您的积分已耗尽"). + // It is often an HTTP 400, which would otherwise look like a bad request + // and leave the account in rotation. TM.00001041 stays a rate limit. + "tm.00001050", + "积分已耗尽", + "积分耗尽", } var rateLimitMarkers = []string{