fix(opencode): retry xAI capacity stream errors (#43640)
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b155b15694
commit
71d08e94d5
@@ -144,6 +144,13 @@ export function parseStreamError(input: unknown): ParsedStreamError | undefined
|
|||||||
responseBody,
|
responseBody,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: "api_error",
|
||||||
|
message: typeof body?.error?.message === "string" ? body.error.message : "Server error.",
|
||||||
|
isRetryable: true,
|
||||||
|
responseBody,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ParsedAPICallError =
|
export type ParsedAPICallError =
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ const RETRYABLE_MESSAGE_PATTERNS = [
|
|||||||
/terminated|fetch failed|failed to fetch|network error|upstream connect|connection error|connection refused|connection lost|socket connection was closed|socket hang up|reset before headers|getaddrinfo|enotfound|eai_again|econnrefused|econnreset|etimedout/i,
|
/terminated|fetch failed|failed to fetch|network error|upstream connect|connection error|connection refused|connection lost|socket connection was closed|socket hang up|reset before headers|getaddrinfo|enotfound|eai_again|econnrefused|econnreset|etimedout/i,
|
||||||
/^timeout$|\b(?:request|response|connection|network|stream|read) (?:timeout|timed out|time out)\b/i,
|
/^timeout$|\b(?:request|response|connection|network|stream|read) (?:timeout|timed out|time out)\b/i,
|
||||||
/try your request again|retry your request|resource exhausted|resource_exhausted/i,
|
/try your request again|retry your request|resource exhausted|resource_exhausted/i,
|
||||||
|
/\btry again (?:later|in\b)|\b(?:currently|temporarily) at capacity\b/i,
|
||||||
]
|
]
|
||||||
|
|
||||||
function cap(ms: number) {
|
function cap(ms: number) {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { describe, expect, test } from "bun:test"
|
||||||
|
import { ProviderError } from "@/provider/error"
|
||||||
|
|
||||||
|
describe("provider stream errors", () => {
|
||||||
|
test("retries provider stream errors without a code", () => {
|
||||||
|
const messages = [
|
||||||
|
"The model is currently at capacity due to high demand. Please try again in a few minutes, or use a higher service tier for priority processing: https://docs.x.ai/developers/advanced-api-usage/priority-processing",
|
||||||
|
"The model is temporarily unavailable.",
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const message of messages)
|
||||||
|
expect(
|
||||||
|
ProviderError.parseStreamError({
|
||||||
|
type: "error",
|
||||||
|
error: { message },
|
||||||
|
}),
|
||||||
|
).toEqual({
|
||||||
|
type: "api_error",
|
||||||
|
message,
|
||||||
|
isRetryable: true,
|
||||||
|
responseBody: JSON.stringify({ type: "error", error: { message } }),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -215,6 +215,9 @@ describe("session.retry.retryable", () => {
|
|||||||
"response timed out",
|
"response timed out",
|
||||||
"Please retry your request",
|
"Please retry your request",
|
||||||
"try your request again",
|
"try your request again",
|
||||||
|
"Please try again in a few minutes",
|
||||||
|
"The model is currently at capacity due to high demand",
|
||||||
|
"The service is temporarily at capacity",
|
||||||
"upstream returned status 524",
|
"upstream returned status 524",
|
||||||
])("retries matching API error text: %s", (message) => {
|
])("retries matching API error text: %s", (message) => {
|
||||||
expect(SessionRetry.retryable(wrap(message), retryProvider)).toEqual({ message })
|
expect(SessionRetry.retryable(wrap(message), retryProvider)).toEqual({ message })
|
||||||
|
|||||||
Reference in New Issue
Block a user