Skip to content

Commit 2e9af3f

Browse files
committed
fix(cli): resolve the effort ladder the way the runtime resolves it
`ocx models` built `reasoningEfforts` from a bare per-model lookup falling back to the provider-wide list. The catalog (`provider-fetch`) and the effort cap (`effort-policy`) both go through `configuredReasoningEfforts`, which does three more things: it returns `[]` for a `noReasoningModels` match, drops levels Codex does not declare, and re-adds tiers a wire map proves the model emits. Restating two of its five lines meant the command reported a ladder the proxy strips and echoed junk as a supported level: noReasoningModels: ["model-b"] ocx models ["low","medium","high"] runtime [] modelReasoningEfforts: model-c: ["high","bogus","low"] ocx models ["high","bogus","low"] runtime ["low","high"] `ocx models` is what an operator reads to check what a config actually did, so a row that disagrees with the proxy is the one thing it must not print. This is the sibling of the modality fix in #2086, which routed the three maps through `modelRecordValue` on the lines above but left this one a partial re-implementation.
1 parent 438b9cc commit 2e9af3f

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

‎src/cli/models.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { randomUUID } from "node:crypto";
55
import { createInterface } from "node:readline/promises";
66
import { syncModelsToCodex } from "../codex/sync";
77
import { hasOwnProvider, isValidProviderName, loadConfig, saveConfig } from "../config";
8-
import { canonicalizeReasoningEfforts, isDeclaredReasoningEffort, modelRecordValue } from "../reasoning-effort";
8+
import {
9+
canonicalizeReasoningEfforts,
10+
configuredReasoningEfforts,
11+
isDeclaredReasoningEffort,
12+
modelRecordValue,
13+
} from "../reasoning-effort";
914
import { encodedModelIdCollides, routedSlug, slugEquals } from "../providers/slug-codec";
1015
import { knownModelIdsForProvider } from "../router";
1116
import { findLiveProxy } from "../server/proxy-liveness";
@@ -91,7 +96,6 @@ function collectModels(config: OcxConfig, providerFilter?: string): ModelEntry[]
9196
const seen = new Set<string>();
9297
const contextWindows = prov.modelContextWindows ?? {};
9398
const inputModalities = prov.modelInputModalities ?? {};
94-
const reasoningEfforts = prov.modelReasoningEfforts ?? {};
9599
const globalContext = prov.contextWindow ?? null;
96100

97101
const addModel = (model: string, isDefault: boolean) => {
@@ -107,7 +111,13 @@ function collectModels(config: OcxConfig, providerFilter?: string): ModelEntry[]
107111
// an exact `gpt-oss:120b` entry that lists "image", and the proxy rejects the image.
108112
const noVision = modelInList(prov.noVisionModels, model);
109113
const modalities = noVision ? ["text"] : (modelRecordValue(inputModalities, model) ?? null);
110-
const efforts = modelRecordValue(reasoningEfforts, model) ?? prov.reasoningEfforts ?? null;
114+
// Same reason, for the ladder: `configuredReasoningEfforts` is what the catalog
115+
// (`provider-fetch`) and the effort cap (`effort-policy`) resolve through, and it
116+
// does three things this expression did not — it returns [] for a noReasoningModels
117+
// match, drops levels Codex does not declare, and re-adds tiers the wire map proves
118+
// the model emits. Restating two of its five lines here reported a ladder the proxy
119+
// strips, and unsanitized junk as a supported level.
120+
const efforts = configuredReasoningEfforts(prov, model) ?? null;
111121

112122
entries.push({
113123
provider: provName,

‎tests/cli-models.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { tmpdir } from "node:os";
55
import { dirname, join } from "node:path";
66
import { fileURLToPath } from "node:url";
77
import { INTERNAL_DEADLINE_MS, SPAWN_BUDGET_MS } from "./helpers/test-budget";
8+
import { configuredReasoningEfforts } from "../src/reasoning-effort";
89
import { isModelTextOnly } from "../src/vision";
910
import type { OcxProviderConfig } from "../src/types";
1011

@@ -203,6 +204,48 @@ describe("ocx models richer metadata", () => {
203204
}
204205
});
205206

207+
test("the effort ladder is the one the runtime resolves, as with the modality", () => {
208+
// `configuredReasoningEfforts` is what the catalog and the effort cap resolve
209+
// through. Restating part of it here reported a ladder for a model the proxy
210+
// strips reasoning from, and echoed a level Codex does not declare.
211+
const dir = mkdtempSync(join(tmpdir(), "ocx-models-efforts-"));
212+
const provider = {
213+
adapter: "openai-chat",
214+
baseUrl: "http://localhost:8080/v1",
215+
allowPrivateNetwork: true,
216+
defaultModel: "model-a",
217+
models: ["model-a", "model-b", "model-c"],
218+
reasoningEfforts: ["low", "medium", "high"],
219+
noReasoningModels: ["model-b"],
220+
modelReasoningEfforts: { "model-c": ["high", "bogus", "low"] },
221+
};
222+
writeFileSync(
223+
join(dir, "config.json"),
224+
JSON.stringify({ port: 10122, providers: { test: provider }, defaultProvider: "test" }),
225+
"utf8",
226+
);
227+
try {
228+
const config = provider as unknown as OcxProviderConfig;
229+
// Ground truth first: what the proxy itself will do with this config.
230+
expect(configuredReasoningEfforts(config, "model-a")).toEqual(["low", "medium", "high"]);
231+
// An empty ladder is not the same claim as "no override": it says this model
232+
// intentionally exposes no effort control, which is why it must survive to the row.
233+
expect(configuredReasoningEfforts(config, "model-b")).toEqual([]);
234+
expect(configuredReasoningEfforts(config, "model-c")).toEqual(["low", "high"]);
235+
236+
const result = runCli(["models", "--json"], { OPENCODEX_HOME: dir });
237+
expect(result.status).toBe(0);
238+
const rows = JSON.parse(result.stdout).models as { model: string; reasoningEfforts: unknown }[];
239+
const ladderOf = (model: string) => rows.find((m) => m.model === model)?.reasoningEfforts;
240+
241+
expect(ladderOf("model-a")).toEqual(["low", "medium", "high"]);
242+
expect(ladderOf("model-b")).toEqual([]);
243+
expect(ladderOf("model-c")).toEqual(["low", "high"]);
244+
} finally {
245+
rmSync(dir, { recursive: true, force: true });
246+
}
247+
});
248+
206249
test("a noVision family entry beats an exact modality entry, as the runtime does", () => {
207250
// isModelTextOnly returns true on the noVisionModels match before it ever reads
208251
// modelInputModalities, so an exact entry listing "image" does not grant vision.

0 commit comments

Comments
 (0)