Merge pull request #3773 from cailgarrisk-collab/fix/glm-rate-limit-fallback-statuscode

fix(model-fallback): add HTTP statusCode check for GLM rate limit fallback
This commit is contained in:
YeonGyu-Kim
2026-05-15 20:04:22 +09:00
committed by GitHub
5 changed files with 187 additions and 4 deletions
@@ -65,6 +65,33 @@ export function extractErrorMessage(error: unknown): string | undefined {
}
}
export function extractErrorStatusCode(error: unknown): number | undefined {
if (!isRecord(error)) return undefined
for (const key of ["statusCode", "status", "code"]) {
const val = (error as Record<string, unknown>)[key]
if (typeof val === "number" && val >= 100 && val < 600) return val
}
const statusVal = (error as Record<string, unknown>)["status"]
if (typeof statusVal === "string") {
const parsed = parseInt(statusVal, 10)
if (parsed >= 100 && parsed < 600) return parsed
}
const responseRaw = (error as Record<string, unknown>)["response"]
if (isRecord(responseRaw)) {
const respStatus = responseRaw["status"]
if (typeof respStatus === "number" && respStatus >= 100 && respStatus < 600) return respStatus
if (typeof respStatus === "string") {
const parsed = parseInt(respStatus, 10)
if (parsed >= 100 && parsed < 600) return parsed
}
}
return undefined
}
interface EventPropertiesLike {
[key: string]: unknown
}
@@ -41,7 +41,7 @@ const defaultFallbackRetryHandlerDeps: FallbackRetryHandlerDeps = {
export async function tryFallbackRetry(args: {
task: BackgroundTask
errorInfo: { name?: string; message?: string }
errorInfo: { name?: string; message?: string; statusCode?: number }
source: string
concurrencyManager: ConcurrencyManager
client: OpencodeClient
+6 -2
View File
@@ -48,6 +48,7 @@ import {
isAbortedSessionError,
extractErrorName,
extractErrorMessage,
extractErrorStatusCode,
getSessionErrorMessage,
isRecord,
} from "./error-classifier"
@@ -944,6 +945,7 @@ The fallback retry session is now created and can be inspected directly.
const errorInfo = {
name: extractErrorName(error),
message: extractErrorMessage(error),
statusCode: extractErrorStatusCode(error),
}
if (await this.tryFallbackRetry(existingTask, errorInfo, "promptAsync.launch")) {
return
@@ -1311,6 +1313,7 @@ The fallback retry session is now created and can be inspected directly.
const errorInfo = {
name: extractErrorName(error),
message: extractErrorMessage(error),
statusCode: extractErrorStatusCode(error),
}
if (await this.tryFallbackRetry(existingTask, errorInfo, "promptAsync.resume")) {
return
@@ -1644,6 +1647,7 @@ The fallback retry session is now created and can be inspected directly.
const errorInfo = {
name: extractErrorName(assistantError),
message: extractErrorMessage(assistantError),
statusCode: extractErrorStatusCode(assistantError),
}
void this.tryFallbackRetry(task, errorInfo, "message.updated").catch((error) => {
log("[background-agent] Error handling message.updated fallback retry:", {
@@ -1969,7 +1973,7 @@ The fallback retry session is now created and can be inspected directly.
private async handleSessionErrorEvent(args: {
task: BackgroundTask
errorInfo: { name?: string; message?: string }
errorInfo: { name?: string; message?: string; statusCode?: number }
errorName: string | undefined
errorMessage: string | undefined
}): Promise<void> {
@@ -2078,7 +2082,7 @@ The fallback retry session is now created and can be inspected directly.
private async tryFallbackRetry(
task: BackgroundTask,
errorInfo: { name?: string; message?: string },
errorInfo: { name?: string; message?: string; statusCode?: number },
source: string,
): Promise<boolean> {
const previousSessionID = task.sessionId