Skip to content

Commit 0531356

Browse files
committed
fix(app-server): pass -c model="..." to codex app-server so options.model takes effect
When `runAppServerTurn` / `runAppServerReview` are invoked with a `model` option, that value was only delivered via the `thread/start` and `turn/start` requests. However, the spawn of `codex app-server` itself did not include a `-c model="..."` override, so the codex CLI session booted with the CLI's built-in default model. On a ChatGPT account where the default (`gpt-5.3-codex`) is unsupported, every task launched via `codex-companion.mjs task --background --model <m>` failed with: ``` Codex error: 'gpt-5.3-codex' model is not supported when using Codex with a ChatGPT account. ``` even though the user passed `--model gpt-5.4`. This change threads the model option through to the spawn site: - `lib/app-server.mjs`: when `options.model` is set, add `-c model=${JSON.stringify(model)}` to the spawned argv. JSON quoting yields a valid TOML string literal that the codex CLI's `-c` parser accepts unambiguously (e.g. `model="gpt-5.4"`). - `lib/codex.mjs` `withAppServer`: accept a third `clientOptions` argument and forward it to `CodexAppServerClient.connect` for both the primary and the direct-retry connection. - `lib/codex.mjs` `runAppServerReview` / `runAppServerTurn`: pass `{ model: options.model }` through to `withAppServer`. `interruptAppServerTurn` and `findLatestTaskThread` still create their own short-lived clients without a model override; they are not exercised by the failing `task --background --model` path and are left for a follow-up. Verified locally on macOS / codex-cli 0.130.0 with: ``` node companion.mjs task --background --fresh --model gpt-5.4 "say hi" ``` Before this patch the job failed during `turn/start`; after, the job completes in ~7s with the assistant reply.
1 parent 8e403f9 commit 0531356

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎plugins/codex/scripts/lib/app-server.mjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ class SpawnedCodexAppServerClient extends AppServerClientBase {
186186
}
187187

188188
async initialize() {
189-
this.proc = spawn("codex", ["app-server"], {
189+
const args = ["app-server"];
190+
if (this.options.model) {
191+
args.push("-c", `model=${JSON.stringify(String(this.options.model))}`);
192+
}
193+
this.proc = spawn("codex", args, {
190194
cwd: this.cwd,
191195
env: this.options.env,
192196
stdio: ["pipe", "pipe", "pipe"],

‎plugins/codex/scripts/lib/codex.mjs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,10 @@ async function captureTurn(client, threadId, startRequest, options = {}) {
604604
}
605605
}
606606

607-
async function withAppServer(cwd, fn) {
607+
async function withAppServer(cwd, fn, clientOptions = {}) {
608608
let client = null;
609609
try {
610-
client = await CodexAppServerClient.connect(cwd);
610+
client = await CodexAppServerClient.connect(cwd, clientOptions);
611611
const result = await fn(client);
612612
await client.close();
613613
return result;
@@ -626,7 +626,7 @@ async function withAppServer(cwd, fn) {
626626
throw error;
627627
}
628628

629-
const directClient = await CodexAppServerClient.connect(cwd, { disableBroker: true });
629+
const directClient = await CodexAppServerClient.connect(cwd, { ...clientOptions, disableBroker: true });
630630
try {
631631
return await fn(directClient);
632632
} finally {
@@ -823,7 +823,7 @@ export async function runAppServerReview(cwd, options = {}) {
823823
error: turnState.error,
824824
stderr: cleanCodexStderr(client.stderr)
825825
};
826-
});
826+
}, { model: options.model });
827827
}
828828

829829
export async function runAppServerTurn(cwd, options = {}) {
@@ -890,7 +890,7 @@ export async function runAppServerTurn(cwd, options = {}) {
890890
touchedFiles: collectTouchedFiles(turnState.fileChanges),
891891
commandExecutions: turnState.commandExecutions
892892
};
893-
});
893+
}, { model: options.model });
894894
}
895895

896896
export async function findLatestTaskThread(cwd) {

0 commit comments

Comments
 (0)