fix(failover): classify z.ai network_error stop reason as retryable timeout

This commit is contained in:
hougangdev
2026-03-12 17:16:21 +08:00
committed by Altay
parent 3700279b14
commit 7458ba74b6
3 changed files with 19 additions and 3 deletions

View File

@@ -289,6 +289,9 @@ describe("failover-error", () => {
expect(resolveFailoverReasonFromError({ message: "stop reason: error" })).toBe("timeout");
expect(resolveFailoverReasonFromError({ message: "reason: abort" })).toBe("timeout");
expect(resolveFailoverReasonFromError({ message: "reason: error" })).toBe("timeout");
expect(
resolveFailoverReasonFromError({ message: "Unhandled stop reason: network_error" }),
).toBe("timeout");
});
it("infers timeout from connection/network error messages", () => {

View File

@@ -576,6 +576,19 @@ describe("isFailoverErrorMessage", () => {
}
});
it("matches z.ai network_error stop reason as timeout", () => {
const samples = [
"Unhandled stop reason: network_error",
"stop reason: network_error",
"reason: network_error",
];
for (const sample of samples) {
expect(isTimeoutErrorMessage(sample)).toBe(true);
expect(classifyFailoverReason(sample)).toBe("timeout");
expect(isFailoverErrorMessage(sample)).toBe(true);
}
});
it("does not classify MALFORMED_FUNCTION_CALL as timeout", () => {
const sample = "Unhandled stop reason: MALFORMED_FUNCTION_CALL";
expect(isTimeoutErrorMessage(sample)).toBe(false);

View File

@@ -47,9 +47,9 @@ const ERROR_PATTERNS = {
/\benotfound\b/i,
/\beai_again\b/i,
/without sending (?:any )?chunks?/i,
/\bstop reason:\s*(?:abort|error|malformed_response)\b/i,
/\breason:\s*(?:abort|error|malformed_response)\b/i,
/\bunhandled stop reason:\s*(?:abort|error|malformed_response)\b/i,
/\bstop reason:\s*(?:abort|error|malformed_response|network_error)\b/i,
/\breason:\s*(?:abort|error|malformed_response|network_error)\b/i,
/\bunhandled stop reason:\s*(?:abort|error|malformed_response|network_error)\b/i,
],
billing: [
/["']?(?:status|code)["']?\s*[:=]\s*402\b|\bhttp\s*402\b|\berror(?:\s+code)?\s*[:=]?\s*402\b|\b(?:got|returned|received)\s+(?:a\s+)?402\b|^\s*402\s+payment/i,