fix(opencode): extract statusCode from error variants for 5xx retry#19204
fix(opencode): extract statusCode from error variants for 5xx retry#19204okuyam2y wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PRsFound 2 related PRs that address similar retry logic issues:
These PRs are not exact duplicates but address the same general area (session/retry error handling for provider responses). You may want to review them for potential conflicts or ensure consistency in the retry logic approach. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
4be2e20 to
dbb61ba
Compare
|
Rebased onto latest dev and squashed into a single commit. All 28 Changes from previous version:
Would appreciate a review when you get a chance. Happy to address any feedback. |
dbb61ba to
17b44a0
Compare
|
Nice PR! This covers the most common error shapes well. One edge case I have hit with OpenRouter: their error JSON uses {"code":502,"message":"Network connection lost.","metadata":{"error_type":"provider_unavailable"}}The current JSON fallback checks const status =
obj?.status ?? obj?.statusCode ?? obj?.code ??
obj?.response?.status ?? obj?.response?.statusCode
if (typeof status === "number" && status >= 500) {The I logged this separately in #22448 — happy to close it as a duplicate if this PR ends up covering the |
Some OpenAI-compatible providers throw native Error subclasses or plain objects instead of ai-sdk's APICallError. These fell through to NamedError.Unknown and were not retried, even on 5xx status codes. Extract statusCode from common error shapes (Error.status, Error.statusCode, Error.response.status, JSON-encoded message) and treat 5xx as retryable in both `instanceof Error` and plain object fallback branches. Closes anomalyco#19203
17b44a0 to
4b4e18f
Compare
|
Good catch, thanks! I've added Updated in 4b4e18f. Also rebased onto latest @tim-mohrbach-ikigai feel free to close #22448 if this covers your case — or keep it open if you want |
Issue for this PR
Closes #19203
Type of change
What does this PR do?
Some OpenAI-compatible providers throw plain errors or objects instead of
APICallError, so 5xx responses fall through toUnknownErrorand never retry. This extracts the status code from common error shapes so 5xx responses stay retryable.How did you verify your code works?
Added unit coverage for the status extraction paths and negative cases.
bun test test/session/message-v2.test.tsandbun run typecheckpass.Screenshots / recordings
N/A — no UI change.
Checklist