From ab5e1ee992eb47aef3243d580f2c66b67990dd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20=C5=98=C3=A1dek?= Date: Tue, 24 Nov 2026 14:54:32 +0100 Subject: [PATCH] fix(auto): use ChatGPT Plus candidates by level Requested by Tomas: spend the Plus allowance before Antigravity Opus at high and medium, and preserve low-cost candidates at low. Skip unlisted models, bench lapsed Claude subscriptions like usage limits, and align hand-picked failover levels with the new candidates. --- .../AutoFailoverService.test.ts | 25 +++- .../orchestration-v2/AutoFailoverService.ts | 9 +- docs/progress.md | 8 ++ packages/shared/src/autoModel.test.ts | 127 ++++++++++++++---- packages/shared/src/autoModel.ts | 19 +-- 5 files changed, 148 insertions(+), 40 deletions(-) diff --git a/apps/server/src/orchestration-v2/AutoFailoverService.test.ts b/apps/server/src/orchestration-v2/AutoFailoverService.test.ts index 894f2cf0bfff..b73537e24393 100644 --- a/apps/server/src/orchestration-v2/AutoFailoverService.test.ts +++ b/apps/server/src/orchestration-v2/AutoFailoverService.test.ts @@ -71,6 +71,17 @@ describe("autoFailoverPlan", () => { expect(result?.cooldownUntilMs).toBe(now + 5 * 60_000); }); + it("benches a lapsed Claude plan like a limit without a reset", () => { + // A cancelled plan's token still says "pro", so Auto kept picking it and every turn failed. + const lapsed = shell({ + lastErrorClass: "provider_error", + lastErrorCode: "api_error_403", + lastError: + "Claude Code can't use your Claude subscription, usually because a payment is past due · Pay or renew at https://claude.ai/settings/billing (if you just paid, try again shortly), or use an Anthropic API key instead", + }); + expect(plan(lapsed)?.cooldownUntilMs).toBe(now + 30 * 60_000); + }); + it("moves a hand-picked thread to Auto at the level its model implies", () => { const picked = (model: string) => shell({ modelSelection: { instanceId: ProviderInstanceId.make("grok"), model } }); @@ -78,7 +89,10 @@ describe("autoFailoverPlan", () => { instanceId: "grok", model: "auto-medium", }); - expect(plan(picked("gpt-6.1-sol"))?.command.modelSelection?.model).toBe("auto-high"); + expect(plan(picked("gpt-6.1-sol"))?.command.modelSelection?.model).toBe("auto-medium"); + expect(plan(picked("gpt-6.2-sol"))?.command.modelSelection?.model).toBe("auto-medium"); + expect(plan(picked("gpt-6.2-astra"))?.command.modelSelection?.model).toBe("auto-high"); + expect(plan(picked("gpt-6.1-terra"))?.command.modelSelection?.model).toBe("auto-low"); expect(plan(picked("claude-haiku-5-5"))?.command.modelSelection?.model).toBe("auto-low"); // A delegated thread keeps the model its parent chose. const delegated = { @@ -93,6 +107,15 @@ describe("autoFailoverPlan", () => { expect( plan(shell({ lastErrorClass: "provider_error", lastErrorCode: "api_error_404" })), ).toBeNull(); + expect( + plan( + shell({ + lastErrorClass: "provider_error", + lastErrorCode: "api_error_403", + lastError: "Request not allowed", + }), + ), + ).toBeNull(); expect(plan(shell({ latestRunId: RunId.make("run:newer") }))).toBeNull(); expect(plan(shell({ status: "idle" }))).toBeNull(); expect(plan(shell({ settledOverride: "settled" }))).toBeNull(); diff --git a/apps/server/src/orchestration-v2/AutoFailoverService.ts b/apps/server/src/orchestration-v2/AutoFailoverService.ts index b9190b455914..c87c035049a6 100644 --- a/apps/server/src/orchestration-v2/AutoFailoverService.ts +++ b/apps/server/src/orchestration-v2/AutoFailoverService.ts @@ -26,6 +26,8 @@ const CAPACITY_CODES: ReadonlySet = new Set([ "api_error_529", "overloaded_error", ]); +/** A cancelled or unpaid Claude plan: its token still looks valid, but every turn fails. */ +const LAPSED_PLAN_ERROR = /can.t use your Claude subscription/i; /** A limit without a reported reset benches the instance this long. */ const LIMIT_COOLDOWN_MS = 30 * 60_000; /** No capacity is usually short-lived. */ @@ -80,7 +82,8 @@ export function autoFailoverPlan(input: { const routed = routedAutoLevel(shell.modelSelection); if (routed === undefined && isDelegatedAppThread(shell)) return null; const level = routed ?? impliedAutoLevel(shell.modelSelection.model); - const limited = shell.lastErrorClass === "usage_limit"; + const limited = + shell.lastErrorClass === "usage_limit" || LAPSED_PLAN_ERROR.test(shell.lastError ?? ""); const noCapacity = !limited && CAPACITY_CODES.has(shell.lastErrorCode ?? ""); if (!limited && !noCapacity) return null; const resetMs = shell.usageLimitResetAt ? Date.parse(shell.usageLimitResetAt) : Number.NaN; @@ -111,8 +114,8 @@ export function autoFailoverPlan(input: { /** The Auto level whose orchestrator is closest to a hand-picked model. */ function impliedAutoLevel(model: string): "low" | "medium" | "high" { - if (/gpt-6\.1-sol|astra/i.test(model)) return "high"; - if (/sonnet|haiku|flash|opencode\/|luna/i.test(model)) return "low"; + if (/astra/i.test(model)) return "high"; + if (/sonnet|haiku|flash|opencode\/|luna|terra/i.test(model)) return "low"; return "medium"; } diff --git a/docs/progress.md b/docs/progress.md index 5a74de002dfb..f925d2a84c5a 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -357,3 +357,11 @@ - Review: one read-only review on OpenCode, since the second Claude account refused the session ("payment is past due") and the Codex account had no quota for a GPT reviewer. It confirmed the 13 resolutions, the catalogs and the queued-edit fix, and found the scheduled-task conflict fixed above. Each of its quoted lines was checked against the source. - Switching the hubs: hub2's live database is at migration 102, so its switch applies 103-111. The lockfile and package manifests changed (`pnpm-lock.yaml`, `pnpm-workspace.yaml`, root, web, client-runtime and shared `package.json`), so the new build needs `vp i`. - Next: Tomáš merges the PR, then switches hub2 and hub to the new build, and renews Claude B's subscription. Mobile's scheduled-task editor (unchanged by upstream) still rebuilds options without the `auto` option when effort changes; it is left for its own fix. Upstream main moved 20 commits during the sync (`27c2d01a83`, 97 files); they touch 23 fork files (the 20 catalogs, `ws.ts` and its test, contracts `settings.ts`), merge without conflicts, and go in the next sync. + +## 2026-11-24: Auto uses the ChatGPT Plus candidates by level + +- Request: use the Plus subscription before Antigravity Opus at high and medium, with separate Codex model lists and efforts to conserve the monthly allowance. Low keeps cheap/free candidates first. Unlisted models still fall through, including a listing without the newer models. +- Fix: updated the shared candidate order and existing routing test cases. Lapsed Claude subscriptions now receive the same cooldown as a usage limit instead of trapping Auto on an account whose token still looks valid. Unrelated provider errors still do not trigger failover. +- Review: an independent read-only review confirmed the candidate order and caught outdated hand-picked failover levels for Sol and Terra; aligned those with medium and low and extended the existing regression case. Added assertions for primary Claude and low-cost candidate precedence. Kept the existing generic continuation message for a separate copy change. +- Validation: the hand-picked level regression failed before the fix (Sol chose high instead of medium). `vp run check:changed --concurrency 1` passes: format, lint, both knip checks, server GraphQL, typechecks across 37 affected packages and 35/35 tests in 3 files. Initial checks caught an overlong comment and tuple inference in the added test; both were corrected before the passing run. +- Next: merge the PR after review; switching the running fork remains a separate action for Tomáš. diff --git a/packages/shared/src/autoModel.test.ts b/packages/shared/src/autoModel.test.ts index bb9ddc7e9e3d..66c81c740bb7 100644 --- a/packages/shared/src/autoModel.test.ts +++ b/packages/shared/src/autoModel.test.ts @@ -513,7 +513,7 @@ describe("resolveAutoModelSelection", () => { ).toBe("claudeAuto"); }); - it("falls back to Claude on the Antigravity subscription before other providers", () => { + it("falls back to Claude on the Antigravity subscription", () => { const antigravity = { ...claude("antigravity", 0, false), driver: ProviderDriverKind.make("antigravity"), @@ -564,46 +564,119 @@ describe("resolveAutoModelSelection", () => { ).toBeNull(); }); - it("after every Claude subscription, uses ChatGPT, then Grok, then Gemini", () => { - const other = (id: string, driver: string, slug: string, optionId: string) => + it("after Claude, spends ChatGPT Plus ahead of Claude on Antigravity, then Grok, then Gemini", () => { + const other = ( + id: string, + driver: string, + slugs: string | ReadonlyArray, + optionId: string, + ) => ({ ...claude(id, 0, false), driver: ProviderDriverKind.make(driver), - models: [ - { - slug, - name: slug, - isCustom: false, - capabilities: { - optionDescriptors: [ - { - id: optionId, - label: "Effort", - type: "select" as const, - options: ["low", "medium", "high"].map((value) => ({ id: value, label: value })), - }, - ], - }, + models: [slugs].flat().map((slug) => ({ + slug, + name: slug, + isCustom: false, + capabilities: { + optionDescriptors: [ + { + id: optionId, + label: "Effort", + type: "select" as const, + options: ["low", "medium", "high"].map((value) => ({ id: value, label: value })), + }, + ], }, - ], + })), usageLimits: undefined, }) as unknown as ServerProvider; const claudeOut = [claude("claudeAuto", 100), claude("claudeAutoB", 100)]; - const codex = other("codex", "codex", "gpt-6-luna", "reasoningEffort"); - const grok = other("grok", "grok", "grok-4.7", "reasoningEffort"); - const gemini = other("antigravity", "antigravity", "gemini-3.8-flash", "thinking_level"); - const route = (providers: ServerProvider[]) => - resolveAutoModelSelection({ selection: auto("high"), providers, now })?.selection; + // The models reported by the Plus account. + const plus = [ + "gpt-6.2-sol", + "gpt-6.2-astra", + "gpt-6.1-terra", + "gpt-6.1-sol", + "gpt-6-astra", + "gpt-6-sol", + "gpt-6-luna", + ]; + const without = (...dropped: string[]) => plus.filter((slug) => !dropped.includes(slug)); + const opus = other("agyOpus", "antigravity", "claude-opus-4-6-thinking", "thinking_level"); + const pick = (level: string, slugs: ReadonlyArray) => + resolveAutoModelSelection({ + selection: auto(level), + providers: [...claudeOut, opus, other("codex", "codex", slugs, "reasoningEffort")], + now, + })?.selection; - expect(route([...claudeOut, gemini, grok, codex])).toMatchObject({ + // Each level has its own ChatGPT models at its own effort; unlisted ones are skipped. + expect(pick("high", plus)).toMatchObject({ instanceId: "codex", - model: "gpt-6-luna", + model: "gpt-6.2-astra", options: [ { id: "reasoningEffort", value: "high" }, { id: "auto", value: "high" }, ], }); - expect(route([...claudeOut, gemini, grok])?.instanceId).toBe("grok"); + expect(pick("high", without("gpt-6.2-astra"))?.model).toBe("gpt-6-astra"); + expect(pick("high", without("gpt-6.2-astra", "gpt-6-astra"))?.model).toBe("gpt-6.2-sol"); + expect(pick("medium", plus)).toMatchObject({ + instanceId: "codex", + model: "gpt-6.2-sol", + options: [ + { id: "reasoningEffort", value: "medium" }, + { id: "auto", value: "medium" }, + ], + }); + expect(pick("medium", without("gpt-6.2-sol"))?.model).toBe("gpt-6.1-sol"); + // Low reaches ChatGPT only after the free models, none of which are listed here. + expect(pick("low", plus)).toMatchObject({ + instanceId: "codex", + model: "gpt-6-luna", + options: [ + { id: "reasoningEffort", value: "low" }, + { id: "auto", value: "low" }, + ], + }); + expect(pick("low", without("gpt-6-luna"))?.model).toBe("gpt-6.1-terra"); + // A listing with only Luna is skipped at high and medium. + expect(pick("high", ["gpt-6-luna"])?.instanceId).toBe("agyOpus"); + expect(pick("medium", ["gpt-6-luna"])?.instanceId).toBe("agyOpus"); + + for (const level of ["high", "medium", "low"]) { + expect( + resolveAutoModelSelection({ + selection: auto(level), + providers: [other("codex", "codex", plus, "reasoningEffort"), claude("claudeAuto", 0)], + now, + })?.selection.instanceId, + ).toBe("claudeAuto"); + } + for (const [id, driver, model, option] of [ + ["agy", "antigravity", "claude-sonnet-4-6", "thinking_level"], + ["free", "opencode", "opencode/big-pickle", "variant"], + ] as const) { + expect( + resolveAutoModelSelection({ + selection: auto("low"), + providers: [ + other("codex", "codex", plus, "reasoningEffort"), + other(id, driver, model, option), + ], + now, + })?.selection.instanceId, + ).toBe(id); + } + + const codex = other("codex", "codex", "gpt-6-luna", "reasoningEffort"); + const grok = other("grok", "grok", "grok-4.7", "reasoningEffort"); + const gemini = other("antigravity", "antigravity", "gemini-3.8-flash", "thinking_level"); + const route = (providers: ServerProvider[]) => + resolveAutoModelSelection({ selection: auto("high"), providers, now })?.selection; + + expect(route([...claudeOut, gemini, grok, codex])?.instanceId).toBe("grok"); expect(route([...claudeOut, gemini])).toMatchObject({ instanceId: "antigravity", model: "gemini-3.8-flash", diff --git a/packages/shared/src/autoModel.ts b/packages/shared/src/autoModel.ts index 93c8670a355f..f6bf8f319c11 100644 --- a/packages/shared/src/autoModel.ts +++ b/packages/shared/src/autoModel.ts @@ -53,29 +53,29 @@ const opencode = (model: string, effort: string): AutoCandidate => ({ }); /** - * Orchestrator candidates per level, best first: Claude A/B, Claude on Antigravity A/B, ChatGPT - * (Codex), Grok, Gemini, then free OpenCode models. Models a provider does not list are skipped, - * so paid-plan models (Sol, Astra) wait until the plan has them. + * High and medium prefer Claude, then ChatGPT (Codex), then Claude on Antigravity. + * Low spends Claude, Antigravity and free OpenCode models before ChatGPT and Grok. + * Each level has its own ChatGPT models and effort to conserve the plan's allowance. + * Unlisted models are skipped, including paid models after the plan ends. */ const AUTO_CANDIDATES: Readonly>> = { high: [ claude("claude-opus-5-5", "max"), - antigravity("claude-opus-4-6-thinking", "high"), - codex("gpt-6.1-sol", "high"), + codex("gpt-6.2-astra", "high"), codex("gpt-6-astra", "high"), - codex("gpt-6-luna", "high"), + codex("gpt-6.2-sol", "high"), + antigravity("claude-opus-4-6-thinking", "high"), grok("high"), antigravity("gemini-3.8-flash", "high"), ], medium: [ claude("claude-opus-5-5", "medium"), claude("claude-fable-5-2", "medium"), - antigravity("claude-opus-4-6-thinking", "medium"), + codex("gpt-6.2-sol", "medium"), codex("gpt-6.1-sol", "medium"), - codex("gpt-6-astra", "medium"), + antigravity("claude-opus-4-6-thinking", "medium"), claude("claude-sonnet-5-5", "medium"), antigravity("claude-sonnet-4-6", "medium"), - codex("gpt-6-luna", "medium"), grok("medium"), antigravity("gemini-3.8-flash", "medium"), opencode("opencode/big-pickle", "medium"), @@ -90,6 +90,7 @@ const AUTO_CANDIDATES: Readonly>> opencode("opencode/deepseek-v4.1-flash-free", "medium"), opencode("opencode/glm-5.3-flash-free", "medium"), codex("gpt-6-luna", "low"), + codex("gpt-6.1-terra", "low"), grok("low"), ], };