fix case where opencode wasn't retrying

This commit is contained in:
Aiden Cline
2025-12-01 12:46:28 -06:00
parent 729a6eda23
commit 027d43b5ea
4 changed files with 47 additions and 18 deletions

View File

@@ -1,3 +1,4 @@
import type { NamedError } from "@opencode-ai/util/error"
import { MessageV2 } from "./message-v2"
export namespace SessionRetry {
@@ -51,4 +52,22 @@ export namespace SessionRetry {
return Math.min(RETRY_INITIAL_DELAY * Math.pow(RETRY_BACKOFF_FACTOR, attempt - 1), RETRY_MAX_DELAY_NO_HEADERS)
}
export function retryable(error: ReturnType<NamedError["toObject"]>) {
if (MessageV2.APIError.isInstance(error)) {
if (!error.data.isRetryable) return undefined
return error.data.message.includes("Overloaded") ? "Provider is overloaded" : error.data.message
}
if (typeof error.data?.message === "string") {
try {
const json = JSON.parse(error.data.message)
if (json.type === "error" && json.error?.type === "too_many_requests") {
return "Too Many Requests"
}
} catch {}
}
return undefined
}
}