mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
fix(failover): handle unhandled stop reason error
This commit is contained in:
@@ -39,6 +39,9 @@ describe("failover-error", () => {
|
||||
expect(resolveFailoverReasonFromError({ message: "Unhandled stop reason: abort" })).toBe(
|
||||
"timeout",
|
||||
);
|
||||
expect(resolveFailoverReasonFromError({ message: "Unhandled stop reason: error" })).toBe(
|
||||
"timeout",
|
||||
);
|
||||
expect(resolveFailoverReasonFromError({ message: "stop reason: abort" })).toBe("timeout");
|
||||
expect(resolveFailoverReasonFromError({ message: "reason: abort" })).toBe("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/i;
|
||||
/timeout|timed out|deadline exceeded|context deadline exceeded|stop reason:\s*abort|reason:\s*abort|unhandled stop reason:\s*(?:abort|error)/i;
|
||||
const ABORT_TIMEOUT_RE = /request was aborted|request aborted/i;
|
||||
|
||||
export class FailoverError extends Error {
|
||||
|
||||
@@ -743,6 +743,14 @@ describe("runWithModelFallback", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back on unhandled stop reason error responses", async () => {
|
||||
await expectFallsBackToHaiku({
|
||||
provider: "openai",
|
||||
model: "gpt-4.1-mini",
|
||||
firstError: new Error("Unhandled stop reason: error"),
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back when message says aborted but error is a timeout", async () => {
|
||||
await expectFallsBackToHaiku({
|
||||
provider: "openai",
|
||||
|
||||
@@ -423,7 +423,12 @@ describe("isFailoverErrorMessage", () => {
|
||||
});
|
||||
|
||||
it("matches abort stop-reason timeout variants", () => {
|
||||
const samples = ["Unhandled stop reason: abort", "stop reason: abort", "reason: abort"];
|
||||
const samples = [
|
||||
"Unhandled stop reason: abort",
|
||||
"Unhandled stop reason: error",
|
||||
"stop reason: abort",
|
||||
"reason: abort",
|
||||
];
|
||||
for (const sample of samples) {
|
||||
expect(isTimeoutErrorMessage(sample)).toBe(true);
|
||||
expect(classifyFailoverReason(sample)).toBe("timeout");
|
||||
|
||||
@@ -643,7 +643,7 @@ const ERROR_PATTERNS = {
|
||||
/without sending (?:any )?chunks?/i,
|
||||
/\bstop reason:\s*abort\b/i,
|
||||
/\breason:\s*abort\b/i,
|
||||
/\bunhandled stop reason:\s*abort\b/i,
|
||||
/\bunhandled stop reason:\s*(?:abort|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,
|
||||
|
||||
Reference in New Issue
Block a user