Skip to content
Merged
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
25 changes: 24 additions & 1 deletion apps/server/src/orchestration-v2/AutoFailoverService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,28 @@ 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 } });
expect(plan(picked("grok-4.7"))?.command.modelSelection).toEqual({
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 = {
Expand All @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions apps/server/src/orchestration-v2/AutoFailoverService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const CAPACITY_CODES: ReadonlySet<string> = 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. */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
}

Expand Down
8 changes: 8 additions & 0 deletions docs/progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -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áš.
127 changes: 100 additions & 27 deletions packages/shared/src/autoModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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<string>,
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<string>) =>
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",
Expand Down
19 changes: 10 additions & 9 deletions packages/shared/src/autoModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<AutoLevel, ReadonlyArray<AutoCandidate>>> = {
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"),
Expand All @@ -90,6 +90,7 @@ const AUTO_CANDIDATES: Readonly<Record<AutoLevel, ReadonlyArray<AutoCandidate>>>
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"),
],
};
Expand Down
Loading