Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/agents/embedded-agent-helpers/failover-matches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,33 @@ describe("server error status classification", () => {
expect(isServerErrorMessage("Proxy notice: Status: Internal Server Error")).toBe(false);
});
});

describe("upstream provider transient errors (#95519)", () => {
it("treats the upstream_error type token as a server error", () => {
expect(isServerErrorMessage("upstream_error")).toBe(true);
});

it("treats an 'Upstream request failed' message as a server error", () => {
expect(isServerErrorMessage("Upstream request failed")).toBe(true);
});

it("classifies the raw upstream_error payload as a fallbackable reason", () => {
// Provider returned {type:"upstream_error", message:"Upstream request failed"}.
// It must NOT stay unclassified, otherwise the turn ends without trying the
// configured fallback models. server_error reasons map to the transient
// failover path so the next candidate is attempted.
const raw =
'{"error":{"message":"Upstream request failed","type":"upstream_error","param":"","code":null}}';
expect(classifyFailoverReason(raw)).not.toBeNull();
});

it("classifies a bare 'Upstream request failed' message as fallbackable", () => {
expect(classifyFailoverReason("Upstream request failed")).not.toBeNull();
});

it("does not classify the generic 'LLM request failed' assistant text as fallbackable", () => {
// This is OpenClaw's own GENERIC_ASSISTANT_ERROR_TEXT, not a provider signal.
// Treating it as fallbackable would risk a fallback loop on internal failures.
expect(classifyFailoverReason("LLM request failed")).toBeNull();
});
});
2 changes: 2 additions & 0 deletions src/agents/embedded-agent-helpers/failover-matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ const ERROR_PATTERNS = {
"bad gateway",
"gateway timeout",
"upstream error",
"upstream_error",
"upstream connect error",
"upstream request failed",
"connection reset",
// Chinese provider server error messages
"内部错误",
Expand Down
Loading