Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/codex/scripts/app-server-broker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function main() {
}

const { options } = parseArgs(argv, {
valueOptions: ["cwd", "pid-file", "endpoint"]
valueOptions: ["cwd", "pid-file", "endpoint", "model"]
});

if (!options.endpoint) {
Expand All @@ -65,7 +65,7 @@ async function main() {
const pidFile = options["pid-file"] ? path.resolve(options["pid-file"]) : null;
writePidFile(pidFile);

const appClient = await CodexAppServerClient.connect(cwd, { disableBroker: true });
const appClient = await CodexAppServerClient.connect(cwd, { disableBroker: true, model: options.model });
let activeRequestSocket = null;
let activeStreamSocket = null;
let activeStreamThreadIds = null;
Expand Down
8 changes: 6 additions & 2 deletions plugins/codex/scripts/lib/app-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ class SpawnedCodexAppServerClient extends AppServerClientBase {
}

async initialize() {
this.proc = spawn("codex", ["app-server"], {
const args = ["app-server"];
if (this.options.model) {
args.push("-c", `model=${JSON.stringify(String(this.options.model))}`);
}
this.proc = spawn("codex", args, {
cwd: this.cwd,
env: this.options.env,
stdio: ["pipe", "pipe", "pipe"],
Expand Down Expand Up @@ -334,7 +338,7 @@ export class CodexAppServerClient {
if (!options.disableBroker) {
brokerEndpoint = options.brokerEndpoint ?? options.env?.[BROKER_ENDPOINT_ENV] ?? process.env[BROKER_ENDPOINT_ENV] ?? null;
if (!brokerEndpoint) {
const brokerSession = await ensureBrokerSession(cwd, { env: options.env });
const brokerSession = await ensureBrokerSession(cwd, { env: options.env, model: options.model });
brokerEndpoint = brokerSession?.endpoint ?? null;
}
}
Expand Down
9 changes: 7 additions & 2 deletions plugins/codex/scripts/lib/broker-lifecycle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ export async function sendBrokerShutdown(endpoint) {
});
}

export function spawnBrokerProcess({ scriptPath, cwd, endpoint, pidFile, logFile, env = process.env }) {
export function spawnBrokerProcess({ scriptPath, cwd, endpoint, pidFile, logFile, model, env = process.env }) {
const logFd = fs.openSync(logFile, "a");
const child = spawn(process.execPath, [scriptPath, "serve", "--endpoint", endpoint, "--cwd", cwd, "--pid-file", pidFile], {
const args = [scriptPath, "serve", "--endpoint", endpoint, "--cwd", cwd, "--pid-file", pidFile];
if (model) {
args.push("--model", String(model));
}
const child = spawn(process.execPath, args, {
cwd,
env,
detached: true,
Expand Down Expand Up @@ -143,6 +147,7 @@ export async function ensureBrokerSession(cwd, options = {}) {
endpoint,
pidFile,
logFile,
model: options.model,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restart stale brokers for model overrides

When a ready broker session already exists, ensureBrokerSession returns it before reaching this new model spawn argument, so a later task --model gpt-5.4 can still attach to an app-server that was originally started without -c model=.... In the ChatGPT-account scenario described by this fix, that leaves the unsupported default model in effect until the user ends/cleans up the shared session; store/compare the broker's model or bypass/restart the broker when a model override is requested.

Useful? React with 👍 / 👎.

env: options.env ?? process.env
});

Expand Down
10 changes: 5 additions & 5 deletions plugins/codex/scripts/lib/codex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,10 @@ async function captureTurn(client, threadId, startRequest, options = {}) {
}
}

async function withAppServer(cwd, fn) {
async function withAppServer(cwd, fn, clientOptions = {}) {
let client = null;
try {
client = await CodexAppServerClient.connect(cwd);
client = await CodexAppServerClient.connect(cwd, clientOptions);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Forward model overrides into broker startup

When no shared session exists, this call enters the default broker path before any direct app-server is spawned. CodexAppServerClient.connect only passes env into ensureBrokerSession, and app-server-broker.mjs starts its inner direct app-server with { disableBroker: true }, so clientOptions.model never becomes the new -c model=... argv; I verified a task --model gpt-5.4 launch records codex app-server with no -c. The ChatGPT-account failure described in the commit therefore still happens for the default shared-runtime path, and only the direct retry path gets the override.

Useful? React with 👍 / 👎.

const result = await fn(client);
await client.close();
return result;
Expand All @@ -626,7 +626,7 @@ async function withAppServer(cwd, fn) {
throw error;
}

const directClient = await CodexAppServerClient.connect(cwd, { disableBroker: true });
const directClient = await CodexAppServerClient.connect(cwd, { ...clientOptions, disableBroker: true });
try {
return await fn(directClient);
} finally {
Expand Down Expand Up @@ -823,7 +823,7 @@ export async function runAppServerReview(cwd, options = {}) {
error: turnState.error,
stderr: cleanCodexStderr(client.stderr)
};
});
}, { model: options.model });
}

export async function runAppServerTurn(cwd, options = {}) {
Expand Down Expand Up @@ -890,7 +890,7 @@ export async function runAppServerTurn(cwd, options = {}) {
touchedFiles: collectTouchedFiles(turnState.fileChanges),
commandExecutions: turnState.commandExecutions
};
});
}, { model: options.model });
}

export async function findLatestTaskThread(cwd) {
Expand Down