Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/codearts-credit-exhausted-cooldown.md
Original file line number Diff line number Diff line change
@@ -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(积分已耗尽)时,账号会进入额度冷却并切换到其他账号。此前该响会被当成无效请求,耗尽的账号会继续被调度。
30 changes: 30 additions & 0 deletions internal/providers/codearts/codearts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
6 changes: 6 additions & 0 deletions internal/providers/codearts/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading