feat: Enhance rate limit error retry for some providers#15858
feat: Enhance rate limit error retry for some providers#15858KrOik wants to merge 5 commits intoanomalyco:devfrom
Conversation
- Add RETRY_PATTERNS regex array for common rate limit messages - Add RETRY_ERROR_CODES set for provider-specific error codes (e.g., GLM 1302) - Add isCustomRetryable() function to detect retryable errors - Modify parseAPICallError() to use custom retry detection - Supports Chinese error messages for better i18n
- Test 429/503 status codes are retryable - Test Chinese rate limit messages are retryable - Test GLM error code 1302 is retryable - Test rate_limit_exceeded error code is retryable
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: PR #10767: fix: retry rate_limit APIError This PR appears to address a similar issue around retrying rate limit errors. It may be worth checking if it's still open and whether the current PR (#15858) builds upon or duplicates that work, especially since it focuses on the same All other search results either returned the current PR itself or unrelated PRs about different retry mechanisms (web tools, infinite retry loops, etc.). |
Actually not same. This PR is not a duplicate of #10767, it extends to handle some provider-specific error codes (e.g., GLM's 1302; or the rate limitation) and non-English rate limit messages (e.g., Chinese "请求频率过高") that the original fix didn’t cover. |
Issue for this PR
Closes #
Type of change
What does this PR do?
Adds better retry detection for rate limiting errors across different AI providers, especially for non-English error messages.
The current retry logic mainly handles OpenAI errors and relies on the provider's
isRetryableflag. This doesn't work well when providers like GLM (智谱) return rate limit errors with custom error codes (e.g., 1302) or Chinese error messages like "请求频率过高" (request frequency too high).Added
isCustomRetryable()function that checks for rate limit signals before falling back to provider-specific logic:The function runs first in
parseAPICallError(), so rate limit errors get properly detected regardless of which provider you're using. It's backward compatible since it only adds an OR condition before the existing retry logic.How did you verify your code works?
Added unit tests in
packages/opencode/test/session/retry.test.tsthat verify:All tests pass locally with
bun test.Screenshots / recordings
Checklist