fix(failover): treat stop reason error as timeout
This commit is contained in:
@@ -35,7 +35,7 @@ describe("failover-error", () => {
|
||||
expect(resolveFailoverReasonFromError({ code: "ECONNRESET" })).toBe("timeout");
|
||||
});
|
||||
|
||||
it("infers timeout from abort stop-reason messages", () => {
|
||||
it("infers timeout from abort/error stop-reason messages", () => {
|
||||
expect(resolveFailoverReasonFromError({ message: "Unhandled stop reason: abort" })).toBe(
|
||||
"timeout",
|
||||
);
|
||||
@@ -43,7 +43,9 @@ describe("failover-error", () => {
|
||||
"timeout",
|
||||
);
|
||||
expect(resolveFailoverReasonFromError({ message: "stop reason: abort" })).toBe("timeout");
|
||||
expect(resolveFailoverReasonFromError({ message: "stop reason: error" })).toBe("timeout");
|
||||
expect(resolveFailoverReasonFromError({ message: "reason: abort" })).toBe("timeout");
|
||||
expect(resolveFailoverReasonFromError({ message: "reason: error" })).toBe("timeout");
|
||||
});
|
||||
|
||||
it("treats AbortError reason=abort as timeout", () => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from "./pi-embedded-helpers.js";
|
||||
|
||||
const TIMEOUT_HINT_RE =
|
||||
/timeout|timed out|deadline exceeded|context deadline exceeded|stop reason:\s*abort|reason:\s*abort|unhandled stop reason:\s*(?:abort|error)/i;
|
||||
/timeout|timed out|deadline exceeded|context deadline exceeded|stop reason:\s*(?:abort|error)|reason:\s*(?:abort|error)|unhandled stop reason:\s*(?:abort|error)/i;
|
||||
const ABORT_TIMEOUT_RE = /request was aborted|request aborted/i;
|
||||
|
||||
export class FailoverError extends Error {
|
||||
|
||||
@@ -751,6 +751,17 @@ describe("runWithModelFallback", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back on abort errors with reason: error", async () => {
|
||||
await expectFallsBackToHaiku({
|
||||
provider: "openai",
|
||||
model: "gpt-4.1-mini",
|
||||
firstError: Object.assign(new Error("aborted"), {
|
||||
name: "AbortError",
|
||||
reason: "reason: error",
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back when message says aborted but error is a timeout", async () => {
|
||||
await expectFallsBackToHaiku({
|
||||
provider: "openai",
|
||||
|
||||
@@ -427,7 +427,9 @@ describe("isFailoverErrorMessage", () => {
|
||||
"Unhandled stop reason: abort",
|
||||
"Unhandled stop reason: error",
|
||||
"stop reason: abort",
|
||||
"stop reason: error",
|
||||
"reason: abort",
|
||||
"reason: error",
|
||||
];
|
||||
for (const sample of samples) {
|
||||
expect(isTimeoutErrorMessage(sample)).toBe(true);
|
||||
|
||||
@@ -641,8 +641,8 @@ const ERROR_PATTERNS = {
|
||||
"deadline exceeded",
|
||||
"context deadline exceeded",
|
||||
/without sending (?:any )?chunks?/i,
|
||||
/\bstop reason:\s*abort\b/i,
|
||||
/\breason:\s*abort\b/i,
|
||||
/\bstop reason:\s*(?:abort|error)\b/i,
|
||||
/\breason:\s*(?:abort|error)\b/i,
|
||||
/\bunhandled stop reason:\s*(?:abort|error)\b/i,
|
||||
],
|
||||
billing: [
|
||||
|
||||
Reference in New Issue
Block a user