Skip to content

Commit 8ccca16

Browse files
committed
fix(models): address CodeRabbit round 3 + carry-over findings
- CLI: empty-string --reasoning-efforts stores an explicit no-reasoning ladder; embedded blank CSV members (low,,high, ,,) are rejected in add and edit; usage text lists none and minimal - pi export: max maps to ultra when ultra is the only declared tier (Pi would otherwise have no selectable level) - GUI: re-enabling the reasoning override restores the loaded ladder instead of re-pre-checking every level - management rows carry the stored defaultReasoningEffort so clients can restore the full edit state - catalog test restores globalThis.fetch in a finally block - management-API tests share one config fixture (seed + follow-up state) and reset it per test - docs: US English afterward
1 parent fbda693 commit 8ccca16

10 files changed

Lines changed: 94 additions & 38 deletions

File tree

‎docs-site/src/content/docs/guides/pi.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ catalog's ladder is the proxy's own statement about whether a model accepts reas
113113
reasoning-free. Pi then offers its effort control for exactly the models opencodex will accept it
114114
on. The export also emits a `thinkingLevelMap` that hides every pi level outside the declared
115115
ladder (`null`), so pi never offers — and never sends — an effort the ladder does not contain.
116-
If you need a different mapping, hand-edit `thinkingLevelMap` afterwards as documented by Pi.
116+
If you need a different mapping, hand-edit `thinkingLevelMap` afterward as documented by Pi.
117117

118118
Treat `reasoning` as Pi-UI metadata: it is derived from the catalog ladder, not proof that the
119119
upstream natively supports a reasoning parameter. What the proxy actually sends for a given

‎gui/src/pages/Models.tsx‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ export default function Models({ apiBase }: { apiBase: string }) {
196196
const [customFormModalities, setCustomFormModalities] = useState<string[]>(["text"]);
197197
const [customFormReasoning, setCustomFormReasoning] = useState(false);
198198
const [customFormReasoningEfforts, setCustomFormReasoningEfforts] = useState<string[]>([]);
199+
// The ladder loaded from the row being edited. Re-enabling the override must restore this
200+
// instead of re-pre-checking every level, which would silently discard a stored ladder.
201+
const customFormReasoningLoadedRef = useRef<string[]>([]);
199202
const [customSaving, setCustomSaving] = useState(false);
200203
const [customError, setCustomError] = useState("");
201204
const [contextModalProvider, setContextModalProvider] = useState<string | null>(null);
@@ -1006,6 +1009,7 @@ export default function Models({ apiBase }: { apiBase: string }) {
10061009
setCustomFormModalities(["text"]);
10071010
setCustomFormReasoning(false);
10081011
setCustomFormReasoningEfforts([]);
1012+
customFormReasoningLoadedRef.current = [];
10091013
setCustomError("");
10101014
setCustomModalOpen(true);
10111015
}}
@@ -1157,6 +1161,7 @@ export default function Models({ apiBase }: { apiBase: string }) {
11571161
// provider row's current metadata.
11581162
setCustomFormReasoning(Array.isArray(m.reasoningEfforts));
11591163
setCustomFormReasoningEfforts(m.reasoningEfforts ?? []);
1164+
customFormReasoningLoadedRef.current = m.reasoningEfforts ?? [];
11601165
setCustomError("");
11611166
setCustomModalOpen(true);
11621167
setHoveredModel(null);
@@ -1616,10 +1621,16 @@ export default function Models({ apiBase }: { apiBase: string }) {
16161621
checked={customFormReasoning}
16171622
onChange={e => {
16181623
setCustomFormReasoning(e.target.checked);
1619-
// Default to the full ladder: the common intent is "allow every known
1620-
// step". An explicit no-reasoning override (empty ladder) then requires
1621-
// deliberately unchecking all of them instead of being an accident.
1622-
if (e.target.checked) setCustomFormReasoningEfforts([...REASONING_EFFORT_LEVELS]);
1624+
if (e.target.checked) {
1625+
setCustomFormReasoningEfforts(prev => {
1626+
// First enable (nothing picked yet): seed from the stored ladder,
1627+
// or pre-check the full set for a new row / an explicit
1628+
// no-reasoning row. Re-enable keeps whatever the user had.
1629+
if (prev.length > 0) return prev;
1630+
const loaded = customFormReasoningLoadedRef.current;
1631+
return loaded.length > 0 ? loaded : [...REASONING_EFFORT_LEVELS];
1632+
});
1633+
}
16231634
}}
16241635
disabled={customSaving}
16251636
/>

‎src/cli/models-runtime.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const USAGE = `Usage:
1717
ocx models live [--provider <name>] [--json]
1818
ocx models edit <custom-id> [--model-id <id>] [--display-name <name|->]
1919
[--context-window <tokens|0>] [--modalities <text,image,audio|->]
20-
[--reasoning-efforts <low,medium,high,xhigh,max,ultra|->]
20+
[--reasoning-efforts <none,minimal,low,medium,high,xhigh,max,ultra|->]
2121
[--default-reasoning-effort <level|->] [--json]
2222
ocx models <enable|disable> <provider/model|native-model> [--native] [--json]
2323
ocx models provider <name> <on|off> [--json]
@@ -70,17 +70,18 @@ async function edit(argv: string[], deps: RuntimeApiDeps): Promise<void> {
7070
patch.contextWindow = value === 0 ? null : value;
7171
}
7272
if (modalitiesRaw !== undefined) patch.inputModalities = modalitiesRaw === "-" ? [] : csv(modalitiesRaw);
73-
// "-" restores inheritance by clearing the stored ladder (null). An explicit empty
74-
// ladder ("no reasoning") has no CLI shorthand — use the dashboard for that state.
73+
// "-" restores inheritance by clearing the stored ladder (null); "" stores an explicit
74+
// empty ladder (the "no reasoning" override, same as the dashboard's uncheck-all).
75+
// Embedded blank CSV members (`low,,high`, `,,`) are malformed and must be rejected, not
76+
// silently normalized by csv().
7577
if (reasoningEffortsRaw !== undefined) {
7678
if (reasoningEffortsRaw === "-") {
7779
patch.reasoningEfforts = null;
7880
} else {
79-
const values = csv(reasoningEffortsRaw);
80-
// csv() silently drops empty members; a value that normalizes to an empty list would
81-
// otherwise store an explicit "no reasoning" ladder the user never asked for.
82-
if (!values || values.length === 0) {
83-
throw new CliUsageError("--reasoning-efforts must be comma-separated values from none, minimal, low, medium, high, xhigh, max, ultra (or \"-\" to inherit)", USAGE);
81+
const trimmed = reasoningEffortsRaw.trim();
82+
const values = trimmed === "" ? [] : trimmed.split(",").map(value => value.trim());
83+
if (values.some(value => value === "")) {
84+
throw new CliUsageError("--reasoning-efforts must be comma-separated values from none, minimal, low, medium, high, xhigh, max, ultra (\"\" for no reasoning, \"-\" to inherit)", USAGE);
8485
}
8586
patch.reasoningEfforts = values;
8687
}

‎src/cli/models.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ import { routedSlug } from "../providers/slug-codec";
1010
import { findLiveProxy } from "../server/proxy-liveness";
1111
import type { OcxConfig, OcxCustomModel } from "../types";
1212

13-
const ADD_USAGE = "Usage: ocx models add <provider> <modelId> [--display-name <name>] [--context-window <tokens>] [--modalities text,image,audio] [--reasoning-efforts <low,medium,high,xhigh,max,ultra>] [--default-reasoning-effort <level>]";
13+
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>]";
1414
const REMOVE_USAGE = "Usage: ocx models remove <customId|provider/modelId> [--yes]";
1515
const LIST_CUSTOM_USAGE = "Usage: ocx models list-custom [--json]";
1616
const ALLOWED_MODALITIES = new Set(["text", "image", "audio"]);
1717

1818
/**
1919
* Parse and validate the reasoning flags shared by `ocx models add` (offline path).
20-
* "-" means "inherit" and omits the field entirely; an empty string is rejected instead of
21-
* silently meaning something (edit's "-" is the documented clear idiom). Values are
22-
* canonicalized into Codex ladder order so the stored config matches what the API stores.
20+
* "-" means "inherit" and omits the field entirely; "" means an explicit empty ladder
21+
* ("no reasoning" override, the same state the dashboard stores for the toggle-off
22+
* checkbox set). Malformed CSV like `low,,high` or `,,` is rejected instead of being
23+
* silently normalized. Values are canonicalized into Codex ladder order so the stored
24+
* config matches what the API stores.
2325
*/
2426
export function parseReasoningArgs(
2527
reasoningEffortsValue: string | undefined,
@@ -31,10 +33,14 @@ export function parseReasoningArgs(
3133
const trimmed = reasoningEffortsValue.trim();
3234
if (trimmed === "-") {
3335
reasoningEfforts = undefined;
36+
} else if (trimmed === "") {
37+
// Explicit no-reasoning override, exactly like the API's [] / the dashboard's
38+
// uncheck-all state.
39+
reasoningEfforts = [];
3440
} else {
3541
const parts = trimmed.split(",").map(value => value.trim());
36-
if (parts.length === 0 || parts.some(part => part === "")) {
37-
return { error: "--reasoning-efforts must be comma-separated values from none, minimal, low, medium, high, xhigh, max, ultra (or \"-\" to inherit)" };
42+
if (parts.some(part => part === "")) {
43+
return { error: "--reasoning-efforts must be comma-separated values from none, minimal, low, medium, high, xhigh, max, ultra (\"\" for no reasoning, \"-\" to inherit)" };
3844
}
3945
const invalid = parts.filter(value => !isDeclaredReasoningEffort(value));
4046
if (invalid.length > 0) {

‎src/clients/config-export.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ function buildPiClientConfig(ctx: ExportContext): PiGeneratedConfig {
891891
medium: efforts.includes("medium") ? "medium" : null,
892892
high: efforts.includes("high") ? "high" : null,
893893
xhigh: efforts.includes("xhigh") ? "xhigh" : null,
894-
max: efforts.includes("max") ? "max" : null,
894+
max: efforts.includes("max") ? "max" : efforts.includes("ultra") ? "ultra" : null,
895895
};
896896
}
897897
const context = authoritativeContextWindow(model.contextWindow);

‎src/server/management/model-rows.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export async function listManagementModelRows(config: OcxConfig): Promise<Manage
9595
// set (including an explicit empty "no reasoning" ladder), not what the provider row
9696
// happens to advertise today.
9797
...(Array.isArray(cm.reasoningEfforts) ? { reasoningEfforts: [...cm.reasoningEfforts] } : {}),
98+
// The stored default rides along so a client reloading /api/models can restore the
99+
// full edit state; the GUI has no default-effort control today, but dropping it here
100+
// would make any future PUT-based edit lose it silently.
101+
...(cm.defaultReasoningEffort ? { defaultReasoningEffort: cm.defaultReasoningEffort } : {}),
98102
};
99103
});
100104
const publicModels = uniqueCatalogModelsForPublicList(models);

‎tests/catalog-input-modality-enum.test.ts‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { describe, expect, test } from "bun:test";
1+
import { beforeEach, describe, expect, test } from "bun:test";
22
import { ensureStrictCatalogFields } from "../src/codex/catalog/parsing";
33
import { catalogHintsFromModelsApiItem } from "../src/codex/catalog/provider-fetch";
4+
import type { OcxConfig } from "../src/types";
45

56
/**
67
* Codex parses `input_modalities` as a closed enum of text | image | audio. A single out-of-enum
@@ -57,6 +58,21 @@ describe("catalog input_modalities stay inside the enum Codex accepts", () => {
5758
*/
5859
describe("custom-model API rejects out-of-enum input modalities", () => {
5960
let persistCalls = 0;
61+
// Shared fixture: the PUT/POST handlers mutate and persist the config object they
62+
// receive, so seed requests and their follow-ups must see the SAME object (a fresh
63+
// object per call would discard the seeded default before the follow-up asserts on it).
64+
const fixtureConfig = {
65+
providers: { deepseek: { adapter: "openai-chat", baseUrl: "https://example.invalid/v1" } },
66+
customModels: [] as Array<{ id: string; provider: string; modelId: string; inputModalities?: string[] }>,
67+
} as unknown as OcxConfig;
68+
69+
beforeEach(() => {
70+
// Seeded WITH modalities on purpose: a fixture without them would let the
71+
// clear-path test pass against a PUT that ignored the field entirely.
72+
fixtureConfig.customModels = [
73+
{ id: "existing-uuid", provider: "deepseek", modelId: "deepseek-v4", inputModalities: ["text", "image"] },
74+
];
75+
});
6076

6177
async function callCustomModels(
6278
method: "POST" | "PUT",
@@ -73,14 +89,7 @@ describe("custom-model API rejects out-of-enum input modalities", () => {
7389
return handleModelRoutes({
7490
req,
7591
url,
76-
config: {
77-
providers: { deepseek: { adapter: "openai-chat", baseUrl: "https://example.invalid/v1" } },
78-
customModels: [
79-
// Seeded WITH modalities on purpose: a fixture without them would let the
80-
// clear-path test pass against a PUT that ignored the field entirely.
81-
{ id: "existing-uuid", provider: "deepseek", modelId: "deepseek-v4", inputModalities: ["text", "image"] },
82-
],
83-
} as unknown as Parameters<typeof handleModelRoutes>[0]["config"],
92+
config: fixtureConfig,
8493
// This handler mutates and persists the config object it receives. The
8594
// fixture must NEVER reach the process-global OPENCODEX_HOME; that exact bug
8695
// replaced a real 41KB provider config with this `existing-uuid` fixture.

‎tests/cli-models-reasoning.test.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ describe("ocx models add --reasoning-efforts parsing", () => {
3030
expect(parsed.reasoningEfforts).toBeUndefined();
3131
});
3232

33-
test("an empty string is rejected instead of silently meaning something", () => {
34-
expect(parseReasoningArgs("", undefined)?.error).toContain("comma-separated");
33+
test('an empty string is the explicit no-reasoning ladder; malformed CSV is rejected', () => {
34+
expect(parseReasoningArgs("", undefined)).toEqual({ reasoningEfforts: [] });
3535
expect(parseReasoningArgs("low,,high", undefined)?.error).toContain("comma-separated");
36+
expect(parseReasoningArgs(",,", undefined)?.error).toContain("comma-separated");
37+
});
38+
39+
test("a default still cannot ride on an explicit empty ladder", () => {
40+
expect(parseReasoningArgs("", "low")?.error).toContain("requires --reasoning-efforts");
3641
});
3742

3843
test('"-" omits the field (inherit) exactly like the API null-clear', () => {
@@ -81,10 +86,15 @@ describe("ocx models edit reasoning flag mapping onto the PUT body", () => {
8186
expect(body.reasoningEfforts).toBeNull();
8287
});
8388

84-
test('"--reasoning-efforts \"\"" is rejected instead of storing an empty ladder', async () => {
89+
test('"--reasoning-efforts \"\"" stores an explicit empty ladder (no-reasoning override)', async () => {
90+
const body = await editWith(["--reasoning-efforts", ""]);
91+
expect(body.reasoningEfforts).toEqual([]);
92+
});
93+
94+
test("embedded blank CSV members are rejected without touching the API", async () => {
8595
let fetchCalled = false;
8696
const fetchImpl = async () => { fetchCalled = true; return new Response("{}", { status: 200 }); };
87-
const code = await handleModelsRuntimeCommand("edit", ["cm-1", "--reasoning-efforts", ""], {
97+
const code = await handleModelsRuntimeCommand("edit", ["cm-1", "--reasoning-efforts", "low,,high"], {
8898
baseUrl: "http://127.0.0.1:1",
8999
fetchImpl,
90100
});

‎tests/client-config-export.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ describe("Pi serializer (accept criterion 2)", () => {
219219
xhigh: null,
220220
max: null,
221221
});
222+
// An ultra-only ladder has no exact pi level: pi's max maps to the only declared tier
223+
// so the model's sole reasoning level is actually selectable.
224+
const ultraOnly = piConfig(ctx({
225+
models: [{ namespaced: "e/ultra", provider: "e", id: "ultra", reasoningEfforts: ["ultra"] }],
226+
}));
227+
expect(ultraOnly.providers.opencodex!.models[0]!.thinkingLevelMap).toMatchObject({
228+
max: "ultra",
229+
off: null,
230+
minimal: null,
231+
});
222232
// An explicit empty ladder is the catalog's "no reasoning" statement; no boolean.
223233
expect(models.find(model => model.id === "b/none")).not.toHaveProperty("reasoning");
224234
expect(models.find(model => model.id === "c/plain")).not.toHaveProperty("reasoning");

‎tests/codex-catalog.test.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,8 +2916,10 @@ describe("Codex catalog routed normalization", () => {
29162916
});
29172917

29182918
test("an explicit empty custom ladder beats the native-alias ladder on a forward row", async () => {
2919+
const originalFetch = globalThis.fetch;
29192920
globalThis.fetch = (() => { throw new Error("forward providers must not fetch /models"); }) as typeof fetch;
2920-
const models = await gatherRoutedModels({
2921+
try {
2922+
const models = await gatherRoutedModels({
29212923
port: 10100,
29222924
defaultProvider: "openai",
29232925
providers: {
@@ -2946,10 +2948,13 @@ describe("Codex catalog routed normalization", () => {
29462948
});
29472949
expect(model?.defaultReasoningEffort).toBeUndefined();
29482950

2949-
const entries = buildCatalogEntries(nativeTemplate(), [], models);
2950-
const daybreak = entries.find(entry => entry.slug === `openai/${NATIVE_DAYBREAK_BLUE_MODEL}`);
2951-
expect(daybreak?.supported_reasoning_levels).toEqual([]);
2952-
expect(daybreak).not.toHaveProperty("default_reasoning_level");
2951+
const entries = buildCatalogEntries(nativeTemplate(), [], models);
2952+
const daybreak = entries.find(entry => entry.slug === `openai/${NATIVE_DAYBREAK_BLUE_MODEL}`);
2953+
expect(daybreak?.supported_reasoning_levels).toEqual([]);
2954+
expect(daybreak).not.toHaveProperty("default_reasoning_level");
2955+
} finally {
2956+
globalThis.fetch = originalFetch;
2957+
}
29532958
});
29542959

29552960
test("catalog sync upgrades fallback-quality gpt-5.6 entries but preserves genuine ones", () => {

0 commit comments

Comments
 (0)