Repository navigation
fix(antigravity): route requests to an account whose plan lists the model #18665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
628452d
4f6dd83
d948093
cdea95c
b2e315d
18e2baa
4e15b3f
ae38f16
4c4653f
33161c6
23ae25d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - **fix(antigravity):** Route each request to an Antigravity/agy account whose synced model list includes the requested model, so Claude 5.5 and Gemini 4 Argon requests no longer start on or fail over to accounts whose plan lacks them; fails open when no account lists the model, keeps never-synced accounts eligible, and lets an operator-pinned account through (a combo step pinned to an account whose plan lacks the model is skipped while another account lists it) ([#18665](https://github.com/cheaper-inference/OmniRoute/pull/18665)) — thanks @bufftop25 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { splitCodexReasoningSuffix } from "@omniroute/open-sse/executors/codex/r | |
| import { isRegisteredImageModel } from "@omniroute/open-sse/config/imageRegistry"; | ||
| import { isModelAdvertisedByConnection } from "@/domain/connectionModelRules"; | ||
| import { isSelfHostedChatProvider } from "@/shared/constants/providers"; | ||
| import { inventoryOrFailOpen, isPerAccountCatalogProvider } from "./perAccountCatalogFilter.ts"; | ||
| import { type ProviderConnectionView } from "@/lib/db/providers/lazyConnectionView"; | ||
| import { | ||
| getSyncedAvailableModelsByConnection, | ||
|
|
@@ -44,8 +45,8 @@ export function isRequestedModelAdvertised( | |
| } | ||
|
|
||
| /** | ||
| * Self-hosted hosts and Codex subscription accounts can advertise different | ||
| * inventories. For Codex, once an account inventory advertises the requested | ||
| * Self-hosted hosts, Codex subscription accounts and Antigravity/agy accounts (plans list | ||
| * different models) can advertise different inventories. For Codex, once an account inventory advertises the requested | ||
| * model, unsynchronized accounts are not eligible guesses for it. With no | ||
| * inventories at all, retain the existing bootstrap/offline behavior. | ||
| * | ||
|
|
@@ -54,6 +55,10 @@ export function isRequestedModelAdvertised( | |
| * account can serve it, so Codex accounts are not filtered for it and the | ||
| * upstream decides. Filtering every account answered a misleading | ||
| * provider_not_configured despite active accounts. | ||
| * | ||
| * Antigravity and agy share one pool and one per-account catalog: accounts whose synced | ||
| * inventory does not list the requested model are skipped, failing open when no account | ||
| * lists it (see perAccountCatalogFilter.ts). | ||
| */ | ||
| export async function loadAdvertisedModelsForConnections( | ||
| connections: ProviderConnectionView[], | ||
|
|
@@ -68,21 +73,32 @@ export async function loadAdvertisedModelsForConnections( | |
| .filter( | ||
| (p): p is string => | ||
| typeof p === "string" && | ||
| (isSelfHostedChatProvider(p) || (p === "codex" && !isCodexImageModel(requestedModel))) | ||
| (isSelfHostedChatProvider(p) || | ||
| (p === "codex" && !isCodexImageModel(requestedModel)) || | ||
| isPerAccountCatalogProvider(p)) | ||
| ) | ||
| ); | ||
| if (inventoryProviders.size === 0) return advertised; | ||
|
|
||
| // Per-account catalogs (Antigravity plans): `antigravity` and `agy` connections share one pool, | ||
| // so their inventories are merged and judged together before the fail-open rule applies. | ||
| const perAccountInventory = new Map<string, Set<string>>(); | ||
| let perAccountMalformed = false; | ||
|
|
||
| await Promise.all( | ||
| [...inventoryProviders].map(async (providerId) => { | ||
| let byConnection: SyncedAvailableModelsByConnection; | ||
| try { | ||
| byConnection = await getSyncedAvailableModelsByConnection(providerId); | ||
| } catch { | ||
| if (isPerAccountCatalogProvider(providerId)) perAccountMalformed = true; | ||
| return; | ||
| } | ||
| // Malformed persisted rows: fail open for the whole provider. | ||
| if (byConnection[SYNCED_AVAILABLE_MODELS_MALFORMED]) return; | ||
| if (byConnection[SYNCED_AVAILABLE_MODELS_MALFORMED]) { | ||
| if (isPerAccountCatalogProvider(providerId)) perAccountMalformed = true; | ||
| return; | ||
| } | ||
| if (providerId === "codex") { | ||
| const advertisedByAnyAccount = Object.values(byConnection).some( | ||
| (models) => | ||
|
|
@@ -99,10 +115,20 @@ export async function loadAdvertisedModelsForConnections( | |
| } | ||
| for (const [connectionId, models] of Object.entries(byConnection)) { | ||
| if (!Array.isArray(models) || models.length === 0) continue; | ||
| advertised.set(connectionId, new Set(models.map((m) => m.id))); | ||
| const ids = new Set(models.map((m) => m.id)); | ||
| if (isPerAccountCatalogProvider(providerId)) perAccountInventory.set(connectionId, ids); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| else advertised.set(connectionId, ids); | ||
| } | ||
| }) | ||
| ); | ||
|
|
||
| if (!perAccountMalformed) { | ||
| // When no account advertises the model the lists are stale/incomplete: fail open instead of | ||
| // emptying the pool. | ||
| for (const [connectionId, ids] of inventoryOrFailOpen(requestedModel, perAccountInventory)) { | ||
| advertised.set(connectionId, ids); | ||
| } | ||
| } | ||
|
|
||
| return advertised; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { isModelAdvertisedByConnection } from "@/domain/connectionModelRules"; | ||
|
|
||
| /** | ||
| * Hosted providers whose model entitlement differs PER ACCOUNT (plan/tier), so the | ||
| * per-connection synced inventory is authoritative for routing. Antigravity: only | ||
| * Ultra accounts are offered the 5.5 Claude models; the rest list 4.6 only and answer | ||
| * 403/404/429 to a 5.5 request, burning a retry (and a cooldown) per account. | ||
| * `agy` connections are served from the same account pool as `antigravity`, and a model can | ||
| * be advertised only by them (Gemini 4 Argon), so both inventories are judged together. | ||
| */ | ||
| const PER_ACCOUNT_CATALOG_PROVIDERS = new Set(["antigravity", "agy"]); | ||
|
|
||
| export function isPerAccountCatalogProvider(providerId: unknown): boolean { | ||
| return typeof providerId === "string" && PER_ACCOUNT_CATALOG_PROVIDERS.has(providerId); | ||
| } | ||
|
|
||
| /** | ||
| * Keep a provider's per-connection inventory only when at least one account really | ||
| * advertises the requested model. If none does, the synced lists are stale or | ||
| * incomplete (a hidden model, a sync that predates a plan upgrade): fail OPEN and | ||
| * return an empty map so selection is unchanged instead of emptying the whole pool. | ||
| */ | ||
| export function inventoryOrFailOpen( | ||
| requestedModel: string, | ||
| inventory: Map<string, Set<string>> | ||
| ): Map<string, Set<string>> { | ||
| for (const models of inventory.values()) { | ||
| if (models.size > 0 && isModelAdvertisedByConnection(requestedModel, models)) return inventory; | ||
| } | ||
| return new Map(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| /** | ||
| * Antigravity entitlement is per ACCOUNT (plan): only Ultra accounts are offered the 5.5 Claude | ||
| * models. Routing must (1) skip accounts whose live inventory lacks the requested model, | ||
| * (2) fail open when no account advertises it, and (3) let an operator-pinned account through. | ||
| */ | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
|
|
||
| const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-agy-plan-routing-")); | ||
| process.env.DATA_DIR = TEST_DATA_DIR; | ||
|
|
||
| const core = await import("../../src/lib/db/core.ts"); | ||
| const providersDb = await import("../../src/lib/db/providers.ts"); | ||
| const modelsDb = await import("../../src/lib/db/models.ts"); | ||
| const auth = await import("../../src/sse/services/auth.ts"); | ||
|
|
||
| const PROVIDER = "antigravity"; | ||
| const OPUS55 = "claude-opus-5-5-low"; | ||
|
|
||
| async function resetStorage() { | ||
| core.resetDbInstance(); | ||
| fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); | ||
| fs.mkdirSync(TEST_DATA_DIR, { recursive: true }); | ||
| } | ||
|
|
||
| test.after(() => { | ||
| core.resetDbInstance(); | ||
| fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); | ||
| }); | ||
|
|
||
| async function account(name: string, priority: number, models: string[]): Promise<string> { | ||
| const created = (await providersDb.createProviderConnection({ | ||
| provider: PROVIDER, | ||
| authType: "oauth", | ||
| name, | ||
| accessToken: `token-${name}`, | ||
| priority, | ||
| isActive: true, | ||
| })) as { id: string }; | ||
| if (models.length > 0) { | ||
| await modelsDb.replaceSyncedAvailableModelsForConnection( | ||
| PROVIDER, | ||
| created.id, | ||
| models.map((id) => ({ id, name: id })) | ||
| ); | ||
| } | ||
| return created.id; | ||
| } | ||
|
|
||
| const idOf = (selected: unknown): string | null => { | ||
| if (!selected || typeof selected !== "object") return null; | ||
| const id = (selected as { connectionId?: unknown }).connectionId; | ||
| return typeof id === "string" ? id : null; | ||
| }; | ||
|
|
||
| const OLD = ["claude-opus-4-6-thinking", "claude-sonnet-4-6"]; | ||
| const ULTRA = [...OLD, OPUS55, "claude-opus-5-5-high"]; | ||
|
|
||
| test("a 5.5 request skips the accounts whose plan does not list it", async () => { | ||
| await resetStorage(); | ||
| const pro1 = await account("pro1", 1, OLD); | ||
| const pro2 = await account("pro2", 2, OLD); | ||
| const ultra = await account("ultra", 3, ULTRA); | ||
|
|
||
| const first = await auth.getProviderCredentials(PROVIDER, null, null, OPUS55); | ||
| assert.equal(idOf(first), ultra, "only the Ultra account advertises the 5.5 model"); | ||
| assert.notEqual(idOf(first), pro1); | ||
| assert.notEqual(idOf(first), pro2); | ||
|
|
||
| const next = await auth.getProviderCredentials(PROVIDER, ultra, null, OPUS55); | ||
| assert.notEqual(idOf(next), pro1, "failover must not wander onto an account without the model"); | ||
| assert.notEqual(idOf(next), pro2); | ||
| }); | ||
|
|
||
| test("a model every account lists keeps all accounts eligible (4.6 failover intact)", async () => { | ||
| await resetStorage(); | ||
| const a = await account("a", 1, ULTRA); | ||
| const b = await account("b", 2, OLD); | ||
|
|
||
| assert.equal( | ||
| idOf(await auth.getProviderCredentials(PROVIDER, null, null, "claude-sonnet-4-6")), | ||
| a | ||
| ); | ||
| assert.equal(idOf(await auth.getProviderCredentials(PROVIDER, a, null, "claude-sonnet-4-6")), b); | ||
| }); | ||
|
|
||
| test("fails open when no account advertises the model (stale or incomplete lists)", async () => { | ||
| await resetStorage(); | ||
| const a = await account("a", 1, OLD); | ||
| await account("b", 2, OLD); | ||
|
|
||
| const selected = await auth.getProviderCredentials(PROVIDER, null, null, "claude-opus-9-9-low"); | ||
| assert.equal(idOf(selected), a, "an unlisted model must not empty the pool"); | ||
| }); | ||
|
|
||
| test("accounts never synced stay eligible (unknown is not 'does not have it')", async () => { | ||
| await resetStorage(); | ||
| const unsynced = await account("unsynced", 1, []); | ||
| await account("ultra", 2, ULTRA); | ||
|
|
||
| const selected = await auth.getProviderCredentials(PROVIDER, null, null, OPUS55); | ||
| assert.equal(idOf(selected), unsynced); | ||
| }); | ||
|
|
||
| test("inventoryOrFailOpen: keeps the inventory only when some account advertises the model", async () => { | ||
| const filter = await import("../../src/sse/services/perAccountCatalogFilter.ts"); | ||
| const inv = new Map([ | ||
| ["x", new Set(["m1"])], | ||
| ["y", new Set(["m2"])], | ||
| ]); | ||
| assert.equal(filter.inventoryOrFailOpen("m1", inv), inv); | ||
| assert.equal(filter.inventoryOrFailOpen("missing", inv).size, 0); | ||
| assert.equal(filter.isPerAccountCatalogProvider("antigravity"), true); | ||
| assert.equal(filter.isPerAccountCatalogProvider("openai"), false); | ||
| }); | ||
|
|
||
| test("an account the operator pinned is not vetoed, but a combo-derived pin still is", async () => { | ||
| await resetStorage(); | ||
| const pro = await account("pro", 1, OLD); | ||
| const ultra = await account("ultra", 2, ULTRA); | ||
|
|
||
| const pinned = await auth.getProviderCredentials(PROVIDER, null, null, OPUS55, { | ||
| forcedConnectionId: pro, | ||
| explicitConnectionPin: true, | ||
| }); | ||
| assert.equal(idOf(pinned), pro, "operator pinned this account; it must be tried as asked"); | ||
|
|
||
| const comboTarget = await auth.getProviderCredentials(PROVIDER, null, null, OPUS55, { | ||
| forcedConnectionId: pro, | ||
| }); | ||
| assert.equal( | ||
| idOf(comboTarget), | ||
| null, | ||
| "a combo expansion must not spend calls on a non-covering account" | ||
| ); | ||
|
|
||
| const automatic = await auth.getProviderCredentials(PROVIDER, null, null, OPUS55); | ||
| assert.equal(idOf(automatic), ultra, "automatic selection still follows the live inventory"); | ||
| }); | ||
|
|
||
| test("a model only the agy accounts list (Gemini 4 Argon) skips the antigravity-provider accounts", async () => { | ||
| await resetStorage(); | ||
| const ARGON = "gemini-4-argon-low"; | ||
| const proAccount = await account("pro", 1, OLD); | ||
| const agy = (await providersDb.createProviderConnection({ | ||
| provider: "agy", | ||
| authType: "oauth", | ||
| name: "ultra-agy", | ||
| accessToken: "token-ultra-agy", | ||
| priority: 2, | ||
| isActive: true, | ||
| })) as { id: string }; | ||
| await modelsDb.replaceSyncedAvailableModelsForConnection("agy", agy.id, [ | ||
| { id: ARGON, name: ARGON }, | ||
| ...OLD.map((id) => ({ id, name: id })), | ||
| ]); | ||
|
|
||
| const first = await auth.getProviderCredentials(PROVIDER, null, null, ARGON); | ||
| assert.equal(idOf(first), agy.id, "only the agy account advertises Argon"); | ||
| assert.notEqual(idOf(first), proAccount); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: cheaper-inference/OmniRoute
Length of output: 8779
Script executed:
Repository: cheaper-inference/OmniRoute
Length of output: 4540
Script executed:
Repository: cheaper-inference/OmniRoute
Length of output: 5775
Load the shared pool inventory before forced narrowing.
A combo-derived pin narrows
connectionsto oneantigravityaccount. The inventory loader then builds its provider list from that narrowed list, soagyinventory is never read. If the pinned account lacks the model,inventoryOrFailOpenreturns an empty map, the account gets no inventory entry, and it is not filtered. The combo can then route to an account that does not list the model.Capture the pool before forced narrowing and pass that pool to the loader. The filter still uses the narrowed list.
Suggested fix
// Forced ids absent from the pool fail; excluded/cooling/quota-blocked ids allow fallback. + const credentialPool = connections; if (isForcedConnectionMissingFromPool(forcedConnectionId, excludedConnectionIds, connections)) {