From c719d5b08e5d9fb9bbcb1f1792281eea8b442812 Mon Sep 17 00:00:00 2001 From: "robopipi[bot]" <336283572+robopipi[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:37:07 +0100 Subject: [PATCH] fix(ai): do not retry Zhipu usage limit errors (code 1308) (#11572) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a Zhipu/Z.ai (`open.bigmodel.cn`) plan hits its usage cap, the API returns HTTP 429 with error code `1308`. The cap resets after hours, but `isRetryableAssistantError()` still marked the error as retryable, because the bare `429` in the message matched the transient-error pattern. The agent-level retry then re-sent a request that could not succeed and slowed down the final error. With default settings that is 3 attempts, about 14 s. This change adds the Zhipu `"code":"1308"` error code to the non-retryable provider-limit patterns in `packages/ai/src/utils/retry.ts`, next to the existing quota and subscription-limit entries. The pattern matches the JSON code field, not a bare number, so request IDs or byte counts that contain 1308 do not trigger it. Not changed: the provider-level HTTP retry (`retry.provider.maxRetries`, off by default). It still retries every 429 based on the status code alone. Testing: - `npm run check` passes. - `test/retry.test.ts` passes. - Calling `isRetryableAssistantError` directly on the reported message, `429 {"code":"1308","message":"已达到 5 小时的使用上限。…"}`, returned `true` before the change and returns `false` after. Fixes #11537 Requested by @davidbrai Co-authored-by: triagent --- packages/ai/src/utils/retry.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/ai/src/utils/retry.ts b/packages/ai/src/utils/retry.ts index a1e984032..eabf6c7de 100644 --- a/packages/ai/src/utils/retry.ts +++ b/packages/ai/src/utils/retry.ts @@ -28,6 +28,10 @@ const NON_RETRYABLE_PROVIDER_LIMIT_ERROR_PATTERN = buildProviderErrorPattern([ // Sign in with ChatGPT on a ChatGPT Business plan: a usage limit set by the // workspace admin. Only the admin can raise it. "subscription_sharing_workplace_individual_usage_limit_exceeded", + + // Zhipu/Z.ai (open.bigmodel.cn) error code 1308: the plan's usage limit is + // reached, sent as HTTP 429. It resets after hours, not seconds (#11537). + '"code"\\s*:\\s*"?1308(?![0-9])', ]); const RETRYABLE_PROVIDER_ERROR_PATTERN = buildProviderErrorPattern([