Skip to content

Commit 71ed29d

Browse files
committed
fix(cli): report model capabilities the way the runtime resolves them
`ocx models` classified each row with bare lookups while the proxy resolves the same four fields through modelInList / modelRecordValue, which accept a family entry for a tagged id. With models ["gpt-oss:120b"], noVisionModels ["gpt-oss"], modelContextWindows {"gpt-oss": 131072} and modelReasoningEfforts {"gpt-oss": ["low","high"]}: runtime isModelTextOnly = true, window 131072, efforts [low, high] ocx models {"contextWindow":null,"inputModalities":null, "reasoningEfforts":null} Every field came back unclassified, so a text-only model reads as image-capable and a configured window reads as unset -- for a config the proxy honours in full. Two tests. The first asserts isModelTextOnly first, so the command is pinned to the runtime's answer rather than to a copy of it; it is red without the src change. The second pins exact-over-family precedence and passes either way -- it guards the fix from over-reaching, it is not evidence of the bug. 237 tests green across cli-models, vision-eligibility, codex-catalog and input-admission. tsc --noEmit clean.
1 parent abaa75a commit 71ed29d

2 files changed

Lines changed: 73 additions & 6 deletions

File tree

‎src/cli/models.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ 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 } from "../reasoning-effort";
8+
import { canonicalizeReasoningEfforts, isDeclaredReasoningEffort, modelRecordValue } from "../reasoning-effort";
99
import { encodedModelIdCollides, routedSlug, slugEquals } from "../providers/slug-codec";
1010
import { knownModelIdsForProvider } from "../router";
1111
import { findLiveProxy } from "../server/proxy-liveness";
12-
import type { OcxConfig, OcxCustomModel } from "../types";
12+
import { modelInList, type OcxConfig, type OcxCustomModel } from "../types";
1313

1414
const ADD_USAGE = "Usage: ocx models add <provider> <modelId> [--display-name <name>] [--context-window <tokens>] [--modalities text,image,audio] [--reasoning-efforts <none,minimal,low,medium,high,xhigh,max,ultra>] [--default-reasoning-effort <level>]";
1515
const REMOVE_USAGE = "Usage: ocx models remove <customId|provider/modelId> [--yes]";
@@ -98,15 +98,19 @@ function collectModels(config: OcxConfig, providerFilter?: string): ModelEntry[]
9898
if (seen.has(model)) return;
9999
seen.add(model);
100100

101-
const noVision = prov.noVisionModels?.includes(model);
102-
const modalities = inputModalities[model] ?? (noVision ? ["text"] : null);
103-
const efforts = reasoningEfforts[model] ?? prov.reasoningEfforts ?? null;
101+
// Resolve exactly as the runtime does, or this command reports capabilities the
102+
// proxy will not honour: `isModelTextOnly` matches noVisionModels with modelInList
103+
// and reads modelInputModalities with modelRecordValue, so a `gpt-oss` entry covers
104+
// `gpt-oss:120b`. A bare lookup reported that model as unclassified on every field.
105+
const noVision = modelInList(prov.noVisionModels, model);
106+
const modalities = modelRecordValue(inputModalities, model) ?? (noVision ? ["text"] : null);
107+
const efforts = modelRecordValue(reasoningEfforts, model) ?? prov.reasoningEfforts ?? null;
104108

105109
entries.push({
106110
provider: provName,
107111
model,
108112
isDefault,
109-
contextWindow: contextWindows[model] ?? globalContext,
113+
contextWindow: modelRecordValue(contextWindows, model) ?? globalContext,
110114
inputModalities: modalities,
111115
reasoningEfforts: efforts,
112116
});

‎tests/cli-models.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ 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 { isModelTextOnly } from "../src/vision";
9+
import type { OcxProviderConfig } from "../src/types";
810

911
const repoRoot = dirname(fileURLToPath(new URL("../package.json", import.meta.url)));
1012
const cliPath = join(repoRoot, "src", "cli", "index.ts");
@@ -165,6 +167,67 @@ describe("ocx models richer metadata", () => {
165167
}
166168
});
167169

170+
test("a family entry classifies its tagged siblings, as the runtime does", () => {
171+
// isModelTextOnly matches noVisionModels with modelInList and reads
172+
// modelInputModalities with modelRecordValue, so a `gpt-oss` entry covers
173+
// `gpt-oss:120b`. This command must not report a different answer.
174+
const dir = mkdtempSync(join(tmpdir(), "ocx-models-family-"));
175+
const provider = {
176+
adapter: "openai-chat",
177+
baseUrl: "http://localhost:8080/v1",
178+
allowPrivateNetwork: true,
179+
defaultModel: "gpt-oss:120b",
180+
models: ["gpt-oss:120b"],
181+
modelContextWindows: { "gpt-oss": 131000 },
182+
noVisionModels: ["gpt-oss"],
183+
modelReasoningEfforts: { "gpt-oss": ["low", "high"] },
184+
};
185+
writeFileSync(
186+
join(dir, "config.json"),
187+
JSON.stringify({ port: 10121, providers: { test: provider }, defaultProvider: "test" }),
188+
"utf8",
189+
);
190+
try {
191+
// Ground truth first: what the proxy itself will do with this config.
192+
expect(isModelTextOnly(provider as unknown as OcxProviderConfig, "gpt-oss:120b")).toBe(true);
193+
194+
const result = runCli(["models", "--json"], { OPENCODEX_HOME: dir });
195+
expect(result.status).toBe(0);
196+
const row = JSON.parse(result.stdout).models
197+
.find((m: { model: string }) => m.model === "gpt-oss:120b");
198+
expect(row.inputModalities).toEqual(["text"]);
199+
expect(row.contextWindow).toBe(131000);
200+
expect(row.reasoningEfforts).toEqual(["low", "high"]);
201+
} finally {
202+
rmSync(dir, { recursive: true, force: true });
203+
}
204+
});
205+
206+
test("an exact entry still wins over the family entry", () => {
207+
const dir = mkdtempSync(join(tmpdir(), "ocx-models-exact-"));
208+
const provider = {
209+
adapter: "openai-chat",
210+
baseUrl: "http://localhost:8080/v1",
211+
allowPrivateNetwork: true,
212+
defaultModel: "gpt-oss:20b",
213+
models: ["gpt-oss:20b"],
214+
modelContextWindows: { "gpt-oss": 131000, "gpt-oss:20b": 32000 },
215+
};
216+
writeFileSync(
217+
join(dir, "config.json"),
218+
JSON.stringify({ port: 10122, providers: { test: provider }, defaultProvider: "test" }),
219+
"utf8",
220+
);
221+
try {
222+
const result = runCli(["models", "--json"], { OPENCODEX_HOME: dir });
223+
const row = JSON.parse(result.stdout).models
224+
.find((m: { model: string }) => m.model === "gpt-oss:20b");
225+
expect(row.contextWindow).toBe(32000);
226+
} finally {
227+
rmSync(dir, { recursive: true, force: true });
228+
}
229+
});
230+
168231
test("models rejects unknown flags", () => {
169232
const { dir } = freshConfig();
170233
try {

0 commit comments

Comments
 (0)