Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(codex): emit all non-default fast service tiers in model catalog

jonathanwxh-cell522e56a5f1ec
diff --git a/server/drivers/codex-catalog.test.ts b/server/drivers/codex-catalog.test.ts
index ac74e47a5e..7d899db844 100644
--- a/server/drivers/codex-catalog.test.ts
+++ b/server/drivers/codex-catalog.test.ts
@@ -48,12 +48,17 @@ describe("decodeCodexSelection", () => {
});
});
- it("reads a Fast row as its base model on the Fast tier", () => {
+ it("reads a Fast or Ultrafast row as its base model on that service tier", () => {
expect(decodeCodexSelection("gpt-5.6-sol+priority")).toEqual({
model: "gpt-5.6-sol",
modelProvider: OFFICIAL_CODEX_PROVIDER,
serviceTier: "priority",
});
+ expect(decodeCodexSelection("gpt-6.2-sol+ultrafast")).toEqual({
+ model: "gpt-6.2-sol",
+ modelProvider: OFFICIAL_CODEX_PROVIDER,
+ serviceTier: "ultrafast",
+ });
});
it("splits provider-encoded custom ids", () => {
@@ -158,6 +163,55 @@ describe("readCodexModelCatalog", () => {
});
});
+ it("emits every distinct non-default fast tier (Fast and Ultrafast) without dropping later tiers", async () => {
+ chmodSync(FAKE_CLI, 0o755);
+ const catalog = await readCodexModelCatalog(
+ {
+ HOME: join(tmpdir(), "omb-codex-app-server-ultrafast"),
+ PATH: process.env.PATH,
+ FAKE_CODEX_TIERS: "1",
+ FAKE_CODEX_ULTRAFAST: "1",
+ },
+ fetch,
+ FAKE_CLI,
+ );
+
+ expect(catalog).toEqual({
+ default: "gpt-fake-default",
+ options: [
+ { id: "gpt-fake-default", label: "GPT Fake Default" },
+ { id: "gpt-fake-default+priority", label: "GPT Fake Default · Fast" },
+ { id: "gpt-fake-default+ultrafast", label: "GPT Fake Default · Ultrafast" },
+ { id: "gpt-page-two", label: "GPT Page Two" },
+ { id: "gpt-page-two+ultrafast", label: "GPT Page Two · Ultrafast" },
+ ],
+ });
+ });
+
+ it("strips all tiered options when model_catalog_json routes models to a custom provider", async () => {
+ chmodSync(FAKE_CLI, 0o755);
+ const home = scratchHome({
+ "config.toml": [
+ 'model = "gpt-fake-default"',
+ 'model_provider = "gw"',
+ "model_catalog_json = 'gw-models.json'",
+ "",
+ "[model_providers.gw]",
+ 'name = "My gateway"',
+ 'base_url = "http://127.0.0.1:9/v1"',
+ "",
+ ].join("\n"),
+ });
+
+ const catalog = await readCodexModelCatalog(
+ { HOME: home, PATH: process.env.PATH, FAKE_CODEX_TIERS: "1", FAKE_CODEX_ULTRAFAST: "1" },
+ fetch,
+ FAKE_CLI,
+ );
+
+ expect(catalog.options.map((option) => option.id)).toEqual(["gw::gpt-fake-default", "gw::gpt-page-two"]);
+ });
+
it("appends the configured local model and cached catalog slugs as custom", async () => {
const home = scratchHome({
"config.toml": `
diff --git a/server/drivers/codex-catalog.ts b/server/drivers/codex-catalog.ts
index dcbe0ec4b8..d1d589ff05 100644
--- a/server/drivers/codex-catalog.ts
+++ b/server/drivers/codex-catalog.ts
@@ -82,15 +82,21 @@ interface CodexAppServerModel {
const FAST_TIER = /fast/i;
-/** The model's Fast tier (codex-cli 0.167 lists `{id: "priority", name: "Fast"}`), unless it already runs on it. */
-function fastTier(row: CodexAppServerModel): { id: string; name: string } | null {
- if (!Array.isArray(row.serviceTiers)) return null;
+/** Non-default fast tiers the model advertises (e.g. Fast, Ultrafast), in advertised order without duplicates. */
+function fastTiers(row: CodexAppServerModel): Array<{ id: string; name: string }> {
+ if (!Array.isArray(row.serviceTiers)) return [];
+ const tiers: Array<{ id: string; name: string }> = [];
+ const seen = new Set<string>();
for (const tier of row.serviceTiers) {
- const id = tier?.id, name = tier?.name;
- if (typeof id !== "string" || typeof name !== "string" || !FAST_TIER.test(name) || !PROVIDER_ID.test(id)) continue;
- return id === row.defaultServiceTier ? null : { id, name };
+ if (!tier || typeof tier !== "object") continue;
+ const { id, name } = tier as { id?: unknown; name?: unknown };
+ const trimmedName = typeof name === "string" ? name.trim() : "";
+ if (typeof id !== "string" || !trimmedName || !FAST_TIER.test(trimmedName) || !PROVIDER_ID.test(id)) continue;
+ if (id === row.defaultServiceTier || seen.has(id)) continue;
+ seen.add(id);
+ tiers.push({ id, name: trimmedName });
}
- return null;
+ return tiers;
}
/** The installed Codex CLI's own ChatGPT catalog, every page: it changes more often than our releases. */
@@ -177,14 +183,22 @@ export function readCodexAppServerModelCatalog(
const options: ModelCatalog["options"] = [];
const seen = new Set<string>();
+ const seenOptions = new Set<string>();
let defaultModel: string | null = null;
for (const row of models) {
- if (row.hidden === true || typeof row.id !== "string" || !MODEL_ID.test(row.id) || seen.has(row.id)) continue;
+ if (row.hidden === true || typeof row.id !== "string" || !MODEL_ID.test(row.id) || seenOptions.has(row.id)) continue;
seen.add(row.id);
+ seenOptions.add(row.id);
const label = typeof row.displayName === "string" && row.displayName.trim() ? row.displayName : row.id;
options.push({ id: row.id, label });
- const fast = fastTier(row);
- if (fast && !TIERED_ID.test(row.id)) options.push({ id: `${row.id}+${fast.id}`, label: `${label} · ${fast.name}` });
+ if (!TIERED_ID.test(row.id)) {
+ for (const tier of fastTiers(row)) {
+ const tierId = `${row.id}+${tier.id}`;
+ if (seenOptions.has(tierId)) continue;
+ seenOptions.add(tierId);
+ options.push({ id: tierId, label: `${label} · ${tier.name}` });
+ }
+ }
if (row.isDefault === true) defaultModel = row.id;
}
if (!options.length) {
diff --git a/server/drivers/codex.test.ts b/server/drivers/codex.test.ts
index 7a403726b2..999208c6e1 100644
--- a/server/drivers/codex.test.ts
+++ b/server/drivers/codex.test.ts
@@ -4596,7 +4596,7 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)
expect(turnStart.params).not.toHaveProperty("effort");
});
- it("runs a Fast row on its base model with the Fast tier for that turn only", async () => {
+ it("runs a Fast or Ultrafast row on its base model with that service tier for that turn only", async () => {
await create();
const dump = join(scratch, "fast.json");
process.env.FAKE_CODEX_DUMP = dump;
@@ -4611,6 +4611,24 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)
expect(threadStart.params).not.toHaveProperty("serviceTier");
expect(turnStart.params).toMatchObject({ serviceTierForTurn: "priority", effort: "high" });
expect(turnStart.params).not.toHaveProperty("serviceTier");
+
+ const ultraDump = join(scratch, "ultrafast.json");
+ process.env.FAKE_CODEX_DUMP = ultraDump;
+ await instance.adapter.sendTurn({ threadId: "t-ultrafast", text: "hi", model: "gpt-6.2-sol+ultrafast" });
+ await recorder.until((e) => e.type === "turn.completed" && e.threadId === "t-ultrafast");
+
+ const ultraSeen = JSON.parse(readFileSync(ultraDump, "utf8"));
+ const ultraThreadStart = ultraSeen.calls.find((c: any) => c.method === "thread/start");
+ const ultraTurnStart = ultraSeen.calls.find((c: any) => c.method === "turn/start");
+ expect(ultraThreadStart.params).toMatchObject({
+ model: "gpt-6.2-sol",
+ modelProvider: "openai",
+ });
+ expect(ultraThreadStart.params).not.toHaveProperty("serviceTier");
+ expect(ultraTurnStart.params).toMatchObject({
+ serviceTierForTurn: "ultrafast",
+ });
+ expect(ultraTurnStart.params).not.toHaveProperty("serviceTier");
});
it("sends no service tier for a plain row", async () => {
diff --git a/server/model-prices.test.ts b/server/model-prices.test.ts
index 352a6053f8..e0bfcf32f7 100644
--- a/server/model-prices.test.ts
+++ b/server/model-prices.test.ts
@@ -74,11 +74,14 @@ describe("what the ledger books for a settled turn", () => {
expect(ledgerCost({ driverKind: "acp", model: "fake-model", input: 1_000_000, output: 0, costUsd: null }, operator)).toEqual({ costUsd: 10, costSource: "estimated" });
});
- it("prices a Codex Fast row as its base model", () => {
+ it("prices a Codex Fast or Ultrafast row as its base model", () => {
const fast = { ...codex, model: "gpt-5.5+priority", costUsd: null };
+ const ultrafast = { ...codex, model: "gpt-5.5+ultrafast", costUsd: null };
expect(ledgerCost(fast, null)).toEqual(ledgerCost({ ...codex, costUsd: null }, null));
+ expect(ledgerCost(ultrafast, null)).toEqual(ledgerCost({ ...codex, costUsd: null }, null));
const operator: PriceList = { "codex/gpt-5.5": { inputPerMillion: 1, outputPerMillion: 2 }, default: { inputPerMillion: 10, outputPerMillion: 10 } };
expect(ledgerCost(fast, operator).costUsd).toBeCloseTo(1 * 1 + 0.1 * 2, 9);
+ expect(ledgerCost(ultrafast, operator).costUsd).toBeCloseTo(1 * 1 + 0.1 * 2, 9);
expect(estimatePriceFor({ driverKind: "codex", model: "gpt-5.5+priority" }, { "codex/gpt-5.5+priority": { inputPerMillion: 7, outputPerMillion: 7 } })?.inputPerMillion).toBe(7);
expect(estimatePriceFor({ driverKind: "acp", model: "gpt-5.5+priority" }, null)).toBeNull();
// A provider-qualified custom model keeps its `+`: it is not a Fast row, so another model's price must not apply.
diff --git a/server/testing/fake-codex-app-server.ts b/server/testing/fake-codex-app-server.ts
index 3f11a1464c..0b2ed0dfae 100755
--- a/server/testing/fake-codex-app-server.ts
+++ b/server/testing/fake-codex-app-server.ts
@@ -58,7 +58,7 @@
// FAKE_CODEX_TEXT_BLOCK `codex exec`: comma-separated models answered with the 403 OpenAI sends a region it does not serve
// FAKE_CODEX_LUNA "1": model/list also offers gpt-6-luna
// FAKE_CODEX_TIERS "1": model/list rows list a Fast service tier, as codex-cli 0.167.2 does; gpt-page-two
-// already runs on it by default
+// already runs on it by default. Set FAKE_CODEX_ULTRAFAST="1" alongside it to also include Ultrafast.
// FAKE_CODEX_UPDATED_FILE while this file exists, the CLI was updated in place: --version answers codex-cli 0.162.1
// and model/list also offers gpt-6.1-sol
// FAKE_CODEX_MCP_START "1": on thread/start, start each `-c mcp_servers.*` mount as codex-cli 0.160.1 does
@@ -89,7 +89,20 @@ import { appendFileSync, existsSync, readFileSync, renameSync, unlinkSync, write
const mode = process.env.FAKE_CODEX_MODE ?? "happy";
const tiers = process.env.FAKE_CODEX_TIERS === "1";
-const FAST_TIERS = [{ id: "priority", name: "Fast", description: "Fastest inference with increased plan usage" }];
+const ultrafastTier = process.env.FAKE_CODEX_ULTRAFAST === "1";
+const FAST_TIERS = [
+ { id: "priority", name: "Fast", description: "Fastest inference with increased plan usage" },
+ ...(ultrafastTier
+ ? [
+ null,
+ { id: "flex", name: "Flex", description: "Non-fast tier should not be emitted." },
+ { id: "bad tier", name: "Fast", description: "Invalid tier id should be ignored." },
+ { id: "blank", name: " ", description: "Whitespace-only tier name should be ignored." },
+ { id: "ultrafast", name: "Ultrafast", description: "The fastest available responses for latency-sensitive work." },
+ { id: "ultrafast", name: "Ultrafast", description: "Duplicate entry to verify deduplication." },
+ ]
+ : []),
+];
// Follow the spawning server down; on Windows ppid does not change after parent exit.
{