Skip to content

Commit 31f75d7

Browse files
authored
fix(agents): scope provider failover codes
1 parent df4e823 commit 31f75d7

4 files changed

Lines changed: 31 additions & 14 deletions

File tree

extensions/anthropic/index.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ describe("anthropic provider replay hooks", () => {
133133
errorMessage: "",
134134
errorType: "api_error",
135135
}),
136-
).toBe("timeout");
136+
).toBe("server_error");
137137
expect(
138138
provider.classifyFailoverReason?.({
139139
provider: "anthropic",
@@ -149,6 +149,13 @@ describe("anthropic provider replay hooks", () => {
149149
code: "RATE_LIMIT_ERROR",
150150
}),
151151
).toBe("rate_limit");
152+
expect(
153+
provider.classifyFailoverReason?.({
154+
provider: "anthropic",
155+
errorMessage: "",
156+
code: "API_ERROR",
157+
}),
158+
).toBe("server_error");
152159
expect(
153160
provider.classifyFailoverReason?.({
154161
provider: "anthropic",

extensions/anthropic/register.runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function classifyAnthropicFailoverDescriptor(value: string | undefined) {
6565
case "RATE_LIMIT_ERROR":
6666
return "rate_limit" as const;
6767
case "API_ERROR":
68-
return "timeout" as const;
68+
return "server_error" as const;
6969
default:
7070
return undefined;
7171
}

src/agents/embedded-agent-helpers/errors-provider-structured-signals.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe("provider failover hook structured signals", () => {
118118

119119
it.each([
120120
{ errorType: "rate_limit_error", reason: "rate_limit", runtimeKind: "rate_limit" },
121-
{ errorType: "api_error", reason: "timeout", runtimeKind: "timeout" },
121+
{ errorType: "api_error", reason: "server_error", runtimeKind: "unclassified" },
122122
] as const)(
123123
"classifies message-less Anthropic $errorType assistant failures",
124124
({ errorType, reason, runtimeKind }) => {
@@ -129,7 +129,7 @@ describe("provider failover hook structured signals", () => {
129129
if (context.errorType === "rate_limit_error") {
130130
return "rate_limit";
131131
}
132-
return context.errorType === "api_error" ? "timeout" : undefined;
132+
return context.errorType === "api_error" ? "server_error" : undefined;
133133
});
134134

135135
const message = makeAssistantMessageFixture({
@@ -150,6 +150,26 @@ describe("provider failover hook structured signals", () => {
150150
},
151151
);
152152

153+
it.each([
154+
{ provider: "google", code: "SERVER_ERROR" },
155+
{ provider: "anthropic", code: "INSUFFICIENT_QUOTA" },
156+
{ provider: "openai", code: "INTERNAL" },
157+
{ provider: "openai", code: "DEADLINE_EXCEEDED" },
158+
{ provider: "anthropic", code: "UNAVAILABLE" },
159+
{ provider: "google", code: "API_ERROR" },
160+
{ provider: "google", code: "RATE_LIMIT_ERROR" },
161+
] as const)(
162+
"does not apply provider-native $code semantics to non-owner $provider",
163+
({ provider, code }) => {
164+
providerRuntimeMocks.classifyProviderPluginError.mockReturnValue(undefined);
165+
166+
expect(classifyFailoverSignal({ provider, code, message: "" })).toBeNull();
167+
expect(classifyProviderRuntimeFailureKind({ provider, code, message: "" })).toBe(
168+
"unclassified",
169+
);
170+
},
171+
);
172+
153173
it("does not promote generic SDK type strings as structured provider descriptors", () => {
154174
providerRuntimeMocks.classifyProviderPluginError.mockReturnValue("billing");
155175

src/agents/embedded-agent-helpers/errors.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -919,24 +919,14 @@ function classifyFailoverReasonFromCode(raw: string | undefined): FailoverReason
919919
case "RATE_LIMIT":
920920
case "RATE_LIMITED":
921921
case "RATE_LIMIT_EXCEEDED":
922-
case "RATE_LIMIT_ERROR":
923922
case "TOO_MANY_REQUESTS":
924923
case "THROTTLED":
925924
case "THROTTLING":
926925
case "THROTTLINGEXCEPTION":
927926
case "THROTTLING_EXCEPTION":
928927
return "rate_limit";
929-
case "INSUFFICIENT_QUOTA":
930-
return "billing";
931928
case "DEACTIVATED_WORKSPACE":
932929
return "auth_permanent";
933-
case "INTERNAL":
934-
case "SERVER_ERROR":
935-
return "server_error";
936-
case "API_ERROR":
937-
case "DEADLINE_EXCEEDED":
938-
return "timeout";
939-
case "UNAVAILABLE":
940930
case "OVERLOADED":
941931
case "OVERLOADED_ERROR":
942932
return "overloaded";

0 commit comments

Comments
 (0)