Skip to content

Commit 5a02c1b

Browse files
committed
fix(runners): stop fallback on device capacity
1 parent 3eb0f02 commit 5a02c1b

3 files changed

Lines changed: 55 additions & 7 deletions

File tree

‎src/agents/failover-error.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,10 +829,16 @@ describe("failover-error", () => {
829829
).toBe(true);
830830
});
831831

832-
it("returns true for direct and nested runner availability failures", () => {
833-
const unavailable = new Error("The device runner is offline");
834-
unavailable.name = "WorkerRunnerUnavailableError";
835-
for (const error of [unavailable, new Error("worker turn failed", { cause: unavailable })]) {
832+
it.each([
833+
["availability", "WorkerRunnerUnavailableError", "The device runner is offline"],
834+
["capacity", "WorkerRunnerCapacityError", "device worker capacity remained full"],
835+
])("returns true for direct and nested runner %s failures", (_label, name, message) => {
836+
const coordination = new Error(message);
837+
coordination.name = name;
838+
for (const error of [
839+
coordination,
840+
new Error("worker turn failed", { cause: coordination }),
841+
]) {
836842
expect(isNonProviderRuntimeCoordinationError(error)).toBe(true);
837843
expect(resolveModelFallbackError(error)).toEqual({ kind: "coordination", error });
838844
}

‎src/agents/failover-error.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,10 @@ function hasGatewayDrainingFailure(err: unknown): boolean {
492492
return errorGraphHasName(err, "GatewayDrainingError");
493493
}
494494

495-
function hasWorkerRunnerUnavailableFailure(err: unknown): boolean {
496-
return errorGraphHasName(err, "WorkerRunnerUnavailableError");
495+
function hasWorkerRunnerCoordinationFailure(err: unknown): boolean {
496+
return ["WorkerRunnerUnavailableError", "WorkerRunnerCapacityError"].some((name) =>
497+
errorGraphHasName(err, name),
498+
);
497499
}
498500

499501
function hasDirectProviderFailureIdentity(err: unknown): boolean {
@@ -891,7 +893,7 @@ export function resolveModelFallbackError(
891893
}
892894
// Gateway admission can fail before any provider turn starts. Preserve that
893895
// identity through wrappers and aggregates so fallback cannot blame a model.
894-
if (hasGatewayDrainingFailure(err) || hasWorkerRunnerUnavailableFailure(err)) {
896+
if (hasGatewayDrainingFailure(err) || hasWorkerRunnerCoordinationFailure(err)) {
895897
return { kind: "coordination", error: err };
896898
}
897899
const staleLifecycleFailure = hasStaleAgentRunLifecycleFailure(err);

‎src/agents/model-fallback.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,46 @@ describe("runWithModelFallback", () => {
22482248
expect(onFallbackStep).not.toHaveBeenCalled();
22492249
});
22502250

2251+
it.each([
2252+
[
2253+
"direct",
2254+
() =>
2255+
Object.assign(new Error("device worker capacity remained full"), {
2256+
name: "WorkerRunnerCapacityError",
2257+
}),
2258+
],
2259+
[
2260+
"wrapped",
2261+
() =>
2262+
new Error("worker turn failed", {
2263+
cause: Object.assign(new Error("device worker capacity remained full"), {
2264+
name: "WorkerRunnerCapacityError",
2265+
}),
2266+
}),
2267+
],
2268+
])("aborts fallback on %s device capacity failures", async (_label, makeError) => {
2269+
const error = makeError();
2270+
const run = vi.fn().mockRejectedValueOnce(error).mockResolvedValueOnce("too late");
2271+
const onError = vi.fn();
2272+
const onFallbackStep = vi.fn();
2273+
2274+
await expect(
2275+
runWithModelFallback({
2276+
cfg: undefined,
2277+
provider: "openai",
2278+
model: "gpt-5.6-sol",
2279+
fallbacksOverride: ["openai/gpt-5.4-mini"],
2280+
skipAuthProfileRuntime: true,
2281+
run,
2282+
onError,
2283+
onFallbackStep,
2284+
}),
2285+
).rejects.toBe(error);
2286+
expect(run).toHaveBeenCalledTimes(1);
2287+
expect(onError).not.toHaveBeenCalled();
2288+
expect(onFallbackStep).not.toHaveBeenCalled();
2289+
});
2290+
22512291
it("still advances after a genuine provider rate limit", async () => {
22522292
const rateLimit = Object.assign(new Error("rate limit exceeded"), { status: 429 });
22532293
const run = vi.fn().mockRejectedValueOnce(rateLimit).mockResolvedValueOnce("fallback ok");

0 commit comments

Comments
 (0)