mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-28 08:52:45 +00:00
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");
|
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(
|
expect(resolveFailoverReasonFromError({ message: "Unhandled stop reason: abort" })).toBe(
|
||||||
"timeout",
|
"timeout",
|
||||||
);
|
);
|
||||||
@@ -43,7 +43,9 @@ describe("failover-error", () => {
|
|||||||
"timeout",
|
"timeout",
|
||||||
);
|
);
|
||||||
expect(resolveFailoverReasonFromError({ message: "stop reason: abort" })).toBe("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: abort" })).toBe("timeout");
|
||||||
|
expect(resolveFailoverReasonFromError({ message: "reason: error" })).toBe("timeout");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("treats AbortError reason=abort as timeout", () => {
|
it("treats AbortError reason=abort as timeout", () => {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from "./pi-embedded-helpers.js";
|
} from "./pi-embedded-helpers.js";
|
||||||
|
|
||||||
const TIMEOUT_HINT_RE =
|
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;
|
const ABORT_TIMEOUT_RE = /request was aborted|request aborted/i;
|
||||||
|
|
||||||
export class FailoverError extends Error {
|
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 () => {
|
it("falls back when message says aborted but error is a timeout", async () => {
|
||||||
await expectFallsBackToHaiku({
|
await expectFallsBackToHaiku({
|
||||||
provider: "openai",
|
provider: "openai",
|
||||||
|
|||||||
@@ -427,7 +427,9 @@ describe("isFailoverErrorMessage", () => {
|
|||||||
"Unhandled stop reason: abort",
|
"Unhandled stop reason: abort",
|
||||||
"Unhandled stop reason: error",
|
"Unhandled stop reason: error",
|
||||||
"stop reason: abort",
|
"stop reason: abort",
|
||||||
|
"stop reason: error",
|
||||||
"reason: abort",
|
"reason: abort",
|
||||||
|
"reason: error",
|
||||||
];
|
];
|
||||||
for (const sample of samples) {
|
for (const sample of samples) {
|
||||||
expect(isTimeoutErrorMessage(sample)).toBe(true);
|
expect(isTimeoutErrorMessage(sample)).toBe(true);
|
||||||
|
|||||||
@@ -641,8 +641,8 @@ const ERROR_PATTERNS = {
|
|||||||
"deadline exceeded",
|
"deadline exceeded",
|
||||||
"context deadline exceeded",
|
"context deadline exceeded",
|
||||||
/without sending (?:any )?chunks?/i,
|
/without sending (?:any )?chunks?/i,
|
||||||
/\bstop reason:\s*abort\b/i,
|
/\bstop reason:\s*(?:abort|error)\b/i,
|
||||||
/\breason:\s*abort\b/i,
|
/\breason:\s*(?:abort|error)\b/i,
|
||||||
/\bunhandled stop reason:\s*(?:abort|error)\b/i,
|
/\bunhandled stop reason:\s*(?:abort|error)\b/i,
|
||||||
],
|
],
|
||||||
billing: [
|
billing: [
|
||||||
|
|||||||
Reference in New Issue
Block a user