Skip to content

Commit 71b5322

Browse files
committed
fix(opencode): recognize legacy admission refusal codes
1 parent 4978ce3 commit 71b5322

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

‎packages/shared/src/orchestrationV2ThreadError.test.ts‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ import { describe, expect, it } from "vite-plus/test";
33
import { providerFailurePresentation } from "./orchestrationV2ThreadError.ts";
44

55
describe("providerFailurePresentation", () => {
6-
it("recognizes an OpenCode admission refusal and replaces a legacy title", () => {
7-
expect(
8-
providerFailurePresentation(
9-
{
10-
class: "usage_limit",
11-
code: "provider.rate-limit",
12-
message:
13-
"Upstream request failed: [ttft_admission_refused] the cell is at capacity; retry shortly (after 30 s)",
14-
},
15-
"Usage limit reached",
16-
),
17-
).toEqual({ kind: "provider_capacity", title: "Provider at capacity" });
18-
});
6+
it.each(["provider.rate-limit", "APIError"])(
7+
"recognizes an OpenCode %s admission refusal and replaces a legacy title",
8+
(code) => {
9+
expect(
10+
providerFailurePresentation(
11+
{
12+
class: "usage_limit",
13+
code,
14+
message:
15+
"Upstream request failed: [ttft_admission_refused] the cell is at capacity; retry shortly (after 30 s)",
16+
},
17+
"Usage limit reached",
18+
),
19+
).toEqual({ kind: "provider_capacity", title: "Provider at capacity" });
20+
},
21+
);
1922

2023
it("keeps true quota and ordinary rate-limit failures under the usage-limit title", () => {
2124
for (const failure of [
@@ -31,6 +34,12 @@ describe("providerFailurePresentation", () => {
3134
message: "Rate limit exceeded: free-models-per-min.",
3235
retryable: null,
3336
},
37+
{
38+
class: "usage_limit",
39+
code: "APIError",
40+
message: "Rate limit exceeded.",
41+
retryable: null,
42+
},
3443
] as const) {
3544
expect(providerFailurePresentation(failure)).toEqual({
3645
kind: "usage_limit",

‎packages/shared/src/orchestrationV2ThreadError.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function providerFailurePresentation(
2020
} {
2121
if (
2222
failure.class === "usage_limit" &&
23-
failure.code === "provider.rate-limit" &&
23+
(failure.code === "provider.rate-limit" || failure.code === "APIError") &&
2424
failure.message.includes("[ttft_admission_refused]")
2525
) {
2626
return { kind: "provider_capacity", title: "Provider at capacity" };

0 commit comments

Comments
 (0)