Skip to content

Commit 6879d15

Browse files
committed
fix(codex): address remaining CodeRabbit comments on runtime PR
Pass configDir into persistEffortClamp, expose catalogClamp.runtimeVersion in status JSON, memoize i18n t to avoid Startup refresh loops, and harden settings clamp-correlation coverage.
1 parent 29849bb commit 6879d15

6 files changed

Lines changed: 66 additions & 24 deletions

File tree

‎gui/src/i18n/provider.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState, type ReactNode } from "react";
1+
import { useCallback, useEffect, useMemo, useState, type ReactNode } from "react";
22
import { DICTS, I18nContext, LOCALES, detectInitial, interpolate, type TFn, type TKey, type Vars } from "./shared";
33
import { en } from "./en";
44
import { useI18n } from "./shared";
@@ -12,9 +12,13 @@ export function LanguageProvider({ children }: { children: ReactNode }) {
1212
try { localStorage.setItem("ocx-lang", locale); } catch { /* ignore */ }
1313
}, [locale]);
1414

15-
const t: TFn = (key, vars) => interpolate(DICTS[locale][key] ?? en[key] ?? key, vars);
15+
const t: TFn = useCallback(
16+
(key, vars) => interpolate(DICTS[locale][key] ?? en[key] ?? key, vars),
17+
[locale],
18+
);
19+
const value = useMemo(() => ({ locale, setLocale, t }), [locale, t]);
1620

17-
return <I18nContext.Provider value={{ locale, setLocale, t }}>{children}</I18nContext.Provider>;
21+
return <I18nContext.Provider value={value}>{children}</I18nContext.Provider>;
1822
}
1923

2024
export function Trans({ k, cmd, vars }: { k: TKey; cmd: string; vars?: Vars }) {

‎src/cli/status.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export type CliStatusJson = {
6161
catalogClamp: {
6262
active: boolean;
6363
removedEfforts: string[];
64+
runtimeVersion: string | null;
6465
};
6566
};
6667
};
@@ -189,6 +190,7 @@ export async function collectStatus(): Promise<CliStatusView> {
189190
catalogClamp: {
190191
active: clampActive,
191192
removedEfforts: clampActive ? (lastClamp?.removedEfforts ?? []) : [],
193+
runtimeVersion: clampActive ? (lastClamp?.runtimeVersion ?? null) : null,
192194
},
193195
};
194196
const proxyLabel = pid && health.ok

‎src/codex/catalog/effort.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export function clampEntryToCodexSupportedEfforts(entry: RawEntry, supported: Se
266266
export function clampCatalogModelsToCodexSupport(models: RawEntry[], deps: BundledCatalogDeps = {}): RawEntry[] {
267267
const supported = codexSupportedReasoningEfforts(deps);
268268
if (!supported) {
269-
if (!deps.commandCandidates) persistEffortClamp(null);
269+
if (!deps.commandCandidates) persistEffortClamp(null, { configDir: deps.configDir });
270270
return models;
271271
}
272272

@@ -331,10 +331,10 @@ export function clampCatalogModelsToCodexSupport(models: RawEntry[], deps: Bundl
331331
affectedModels: affected,
332332
};
333333
for (const line of formatClampLogLines(diagnostic)) console.warn(line);
334-
if (!deps.commandCandidates) persistEffortClamp(diagnostic);
334+
if (!deps.commandCandidates) persistEffortClamp(diagnostic, { configDir: deps.configDir });
335335
deps.onEffortClamp?.(diagnostic);
336336
} else if (!deps.commandCandidates) {
337-
persistEffortClamp(null);
337+
persistEffortClamp(null, { configDir: deps.configDir });
338338
}
339339

340340
return models;

‎tests/cli-status-json.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe("CLI status JSON", () => {
7474
source?: unknown;
7575
warning?: unknown;
7676
newerAvailable?: unknown;
77-
catalogClamp?: { active?: unknown; removedEfforts?: unknown };
77+
catalogClamp?: { active?: unknown; removedEfforts?: unknown; runtimeVersion?: unknown };
7878
};
7979
};
8080

@@ -116,6 +116,7 @@ describe("CLI status JSON", () => {
116116
).toBe(true);
117117
expect(parsed.codexRuntime?.catalogClamp?.active).toBe(false);
118118
expect(Array.isArray(parsed.codexRuntime?.catalogClamp?.removedEfforts)).toBe(true);
119+
expect(parsed.codexRuntime?.catalogClamp?.runtimeVersion).toBeNull();
119120

120121
const serialized = JSON.stringify(parsed).toLowerCase();
121122
for (const forbidden of ["apikey", "sk-test-secret", "token", "refreshtoken", "authorization", "email"]) {

‎tests/codex-runtime.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,27 @@ describe("resolveCodexRuntime", () => {
263263
expect(typeof failed.persistError).toBe("string");
264264
expect(failed.persistError!.length).toBeGreaterThan(0);
265265
});
266+
267+
test("catalog clamp clears diagnostics inside deps.configDir when probe fails", async () => {
268+
const { clampCatalogModelsToCodexSupport } = await import("../src/codex/catalog/effort");
269+
const nested = join(tempConfigDir(), "nested", "opencodex-home");
270+
persistEffortClamp({
271+
runtimePath: "C:\\keep\\codex.exe",
272+
runtimeVersion: "0.133.0",
273+
removedEfforts: ["max"],
274+
affectedModels: ["gpt-5.6-sol"],
275+
}, { configDir: nested });
276+
expect(loadLastEffortClamp({ configDir: nested })?.removedEfforts).toEqual(["max"]);
277+
278+
clampCatalogModelsToCodexSupport([], {
279+
configDir: nested,
280+
env: { PATH: "" },
281+
platform: "win32",
282+
existsSync: () => false,
283+
execFileSync: () => {
284+
throw new Error("catalog probe failed");
285+
},
286+
});
287+
expect(loadLastEffortClamp({ configDir: nested })).toBeNull();
288+
});
266289
});

‎tests/settings-stream-mode.test.ts‎

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,25 @@ describe("GET /api/settings", () => {
8282
});
8383

8484
test("reports redacted codexRuntime diagnostics and clamp correlation", async () => {
85-
const { persistCodexRuntime, persistEffortClamp, resetCodexRuntimeResolveCacheForTests } = await import("../src/codex/runtime");
85+
const { chmodSync } = await import("node:fs");
86+
const {
87+
persistEffortClamp,
88+
resetCodexRuntimeResolveCacheForTests,
89+
} = await import("../src/codex/runtime");
8690
resetCodexRuntimeResolveCacheForTests();
87-
persistCodexRuntime({
88-
command: join(TEST_DIR, "Users", "Alice", "codex.exe"),
89-
version: "0.133.0",
90-
source: "configured",
91-
}, { configDir: TEST_DIR });
91+
92+
const fakeCodex = process.platform === "win32"
93+
? join(TEST_DIR, "bin", "codex.cmd")
94+
: join(TEST_DIR, "bin", "codex");
95+
mkdirSync(join(TEST_DIR, "bin"), { recursive: true });
96+
if (process.platform === "win32") {
97+
writeFileSync(fakeCodex, "@echo off\r\necho codex-cli 0.133.0\r\n", "utf8");
98+
} else {
99+
writeFileSync(fakeCodex, "#!/bin/sh\necho 'codex-cli 0.133.0'\n", "utf8");
100+
chmodSync(fakeCodex, 0o755);
101+
}
92102
persistEffortClamp({
93-
runtimePath: join(TEST_DIR, "Users", "Alice", "codex.exe"),
103+
runtimePath: fakeCodex,
94104
runtimeVersion: "0.133.0",
95105
removedEfforts: ["max", "ultra"],
96106
affectedModels: ["gpt-5.6-sol"],
@@ -99,10 +109,8 @@ describe("GET /api/settings", () => {
99109
const previousCli = process.env.CODEX_CLI_PATH;
100110
const previousPath = process.env.PATH;
101111
try {
102-
process.env.CODEX_CLI_PATH = join(TEST_DIR, "Users", "Alice", "codex.exe");
112+
process.env.CODEX_CLI_PATH = fakeCodex;
103113
process.env.PATH = "";
104-
// Force resolve to use the persisted/env path without spawning a real Codex.
105-
// The settings handler catches resolve failures; probe will fail existence and fall back.
106114
const body = await (await getSettings(baseConfig()))!.json() as {
107115
codexRuntime?: {
108116
path?: string;
@@ -114,17 +122,21 @@ describe("GET /api/settings", () => {
114122
};
115123
};
116124
expect(typeof body.codexRuntime?.path).toBe("string");
117-
expect(body.codexRuntime?.path?.toLowerCase()).not.toContain("alice");
125+
// OPENCODEX_HOME lives under the OS user profile; username must stay redacted.
126+
expect(body.codexRuntime?.path?.toLowerCase()).not.toMatch(/\\users\\[^\\[\]/]+\\/i);
127+
expect(body.codexRuntime?.version).toBe("0.133.0");
128+
expect(body.codexRuntime?.source).toBe("environment");
129+
expect(body.codexRuntime?.catalogClamp).toEqual({
130+
active: true,
131+
removedEfforts: ["max", "ultra"],
132+
runtimeVersion: "0.133.0",
133+
});
118134
expect(
119135
body.codexRuntime?.newerAvailable === null
120136
|| (typeof body.codexRuntime?.newerAvailable === "object" && body.codexRuntime?.newerAvailable !== null),
121137
).toBe(true);
122-
expect(body.codexRuntime?.warning === null || typeof body.codexRuntime?.warning === "string").toBe(true);
123-
expect(Array.isArray(body.codexRuntime?.catalogClamp?.removedEfforts)).toBe(true);
124-
expect(
125-
body.codexRuntime?.catalogClamp?.runtimeVersion === null
126-
|| typeof body.codexRuntime?.catalogClamp?.runtimeVersion === "string",
127-
).toBe(true);
138+
expect(typeof body.codexRuntime?.warning).toBe("string");
139+
expect(body.codexRuntime?.warning).toContain("0.133.0");
128140
} finally {
129141
if (previousCli === undefined) delete process.env.CODEX_CLI_PATH;
130142
else process.env.CODEX_CLI_PATH = previousCli;

0 commit comments

Comments
 (0)