Skip to content

Commit 2aa0bc5

Browse files
Zuriclaude
andcommitted
fix(server): codex text generation keeps local provider launch args
Text generation filtered the instance's launch args down to config and feature flags, so `--oss`, `--local-provider` and `-p/--profile` were dropped and `codex exec` used a different model provider than chat. Split the filter into per-command builders: `codex exec` now keeps those flags (all accepted by `codex exec`), while `codex mcp list`, which rejects them and `--strict-config`, keeps the shared config/feature flags only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 25bf84a commit 2aa0bc5

4 files changed

Lines changed: 74 additions & 17 deletions

File tree

‎apps/server/src/provider/codexLaunchArgs.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import * as NodeAssert from "node:assert/strict";
22

33
import { describe, it } from "vite-plus/test";
44

5-
import { codexAppServerArgs, codexExecLaunchArgs } from "./codexLaunchArgs.ts";
5+
import {
6+
codexAppServerArgs,
7+
codexExecLaunchArgs,
8+
codexMcpListLaunchArgs,
9+
} from "./codexLaunchArgs.ts";
610

711
describe("codexAppServerArgs", () => {
812
it("preserves escaped TOML quotes in config values", () => {
@@ -27,3 +31,26 @@ describe("codexExecLaunchArgs", () => {
2731
]);
2832
});
2933
});
34+
35+
describe("codex exec and mcp list launch args", () => {
36+
const launchArgs =
37+
"--strict-config --oss --local-provider ollama --profile local -p=work --listen off --enable foo";
38+
39+
it("keeps the local model provider flags for codex exec", () => {
40+
NodeAssert.deepStrictEqual(codexExecLaunchArgs(launchArgs), [
41+
"--strict-config",
42+
"--oss",
43+
"--local-provider",
44+
"ollama",
45+
"--profile",
46+
"local",
47+
"-p=work",
48+
"--enable",
49+
"foo",
50+
]);
51+
});
52+
53+
it("drops exec-only flags for codex mcp list", () => {
54+
NodeAssert.deepStrictEqual(codexMcpListLaunchArgs(launchArgs), ["--enable", "foo"]);
55+
});
56+
});

‎apps/server/src/provider/codexLaunchArgs.ts‎

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,54 @@ export const codexAppServerArgs = (launchArgs?: string) => [
1414
...codexLaunchArgv(launchArgs),
1515
];
1616

17-
export const codexExecLaunchArgs = (launchArgs?: string) => {
17+
interface LaunchArgFilter {
18+
readonly switches: ReadonlySet<string>;
19+
readonly valueFlags: ReadonlySet<string>;
20+
readonly inlinePrefixes: ReadonlyArray<string>;
21+
}
22+
23+
const SHARED_VALUE_FLAGS = ["--config", "-c", "--enable", "--disable"];
24+
const SHARED_INLINE_PREFIXES = ["--config=", "-c=", "--enable=", "--disable="];
25+
26+
const MCP_LIST_FILTER: LaunchArgFilter = {
27+
switches: new Set(),
28+
valueFlags: new Set(SHARED_VALUE_FLAGS),
29+
inlinePrefixes: SHARED_INLINE_PREFIXES,
30+
};
31+
32+
// `codex exec` also takes the local model provider flags; `codex mcp list` rejects them.
33+
const EXEC_FILTER: LaunchArgFilter = {
34+
switches: new Set(["--strict-config", "--oss"]),
35+
valueFlags: new Set([...SHARED_VALUE_FLAGS, "--local-provider", "--profile", "-p"]),
36+
inlinePrefixes: [...SHARED_INLINE_PREFIXES, "--local-provider=", "--profile=", "-p="],
37+
};
38+
39+
const filterLaunchArgs = (launchArgs: string | undefined, allowed: LaunchArgFilter) => {
1840
const args = codexLaunchArgv(launchArgs);
19-
const execArgs: Array<string> = [];
41+
const kept: Array<string> = [];
2042

2143
for (let index = 0; index < args.length; index++) {
2244
const arg = args[index];
2345
if (arg === undefined) continue;
2446

25-
if (arg === "--strict-config" || arg.startsWith("--config=") || arg.startsWith("-c=")) {
26-
execArgs.push(arg);
27-
} else if (arg === "--config" || arg === "-c" || arg === "--enable" || arg === "--disable") {
47+
if (allowed.switches.has(arg)) {
48+
kept.push(arg);
49+
} else if (allowed.valueFlags.has(arg)) {
2850
const value = args[index + 1];
2951
if (value !== undefined && !value.startsWith("-")) {
30-
execArgs.push(arg, value);
52+
kept.push(arg, value);
3153
index++;
3254
}
33-
} else if (arg.startsWith("--enable=") || arg.startsWith("--disable=")) {
34-
execArgs.push(arg);
55+
} else if (allowed.inlinePrefixes.some((prefix) => arg.startsWith(prefix))) {
56+
kept.push(arg);
3557
}
3658
}
3759

38-
return execArgs;
60+
return kept;
3961
};
62+
63+
export const codexExecLaunchArgs = (launchArgs?: string) =>
64+
filterLaunchArgs(launchArgs, EXEC_FILTER);
65+
66+
export const codexMcpListLaunchArgs = (launchArgs?: string) =>
67+
filterLaunchArgs(launchArgs, MCP_LIST_FILTER);

‎apps/server/src/textGeneration/CodexTextGeneration.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {
429429
subject: "Add important change",
430430
body: "",
431431
}),
432-
launchArgs: "--strict-config --listen off",
433-
requireArg: "--strict-config",
432+
launchArgs: "--strict-config --oss --local-provider ollama --listen off",
433+
requireArg: "--strict-config --oss --local-provider ollama",
434434
forbidArg: "--listen",
435435
},
436436
(textGeneration) =>

‎apps/server/src/textGeneration/CodexTextGeneration.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import { resolveSpawnCommand } from "@t3tools/shared/shell";
1818
import { resolveAttachmentPath } from "../attachmentStore.ts";
1919
import * as ServerConfig from "../config.ts";
2020
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
21-
import { codexExecLaunchArgs, resolveCodexLaunchArgs } from "../provider/codexLaunchArgs.ts";
21+
import {
22+
codexExecLaunchArgs,
23+
codexMcpListLaunchArgs,
24+
resolveCodexLaunchArgs,
25+
} from "../provider/codexLaunchArgs.ts";
2226
import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations";
2327
import {
2428
normalizeCliError,
@@ -287,19 +291,17 @@ export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(func
287291
}
288292
: {}),
289293
};
290-
const execLaunchArgs = codexExecLaunchArgs(launchArgs);
291294
const mcpServersOff = yield* listEnabledMcpServers({
292295
binary,
293296
cwd,
294297
env,
295-
// `codex mcp` rejects --strict-config; the overrides still apply.
296-
launchArgs: execLaunchArgs.filter((arg) => arg !== "--strict-config"),
298+
launchArgs: codexMcpListLaunchArgs(launchArgs),
297299
}).pipe(Effect.map(codexMcpServersOff));
298300
const spawnCommand = yield* resolveSpawnCommand(
299301
binary,
300302
[
301303
"exec",
302-
...execLaunchArgs,
304+
...codexExecLaunchArgs(launchArgs),
303305
// A user's MCP server could act on the text-generation prompt.
304306
...CODEX_NO_PLUGIN_ARGS,
305307
...(mcpServersOff ? ["--config", mcpServersOff] : []),

0 commit comments

Comments
 (0)