Skip to content

Commit 1fd1d3c

Browse files
fix(macos): allow cold ChatGPT Codex probes (#128819)
1 parent e514840 commit 1fd1d3c

2 files changed

Lines changed: 46 additions & 5 deletions

File tree

‎src/commands/onboard-inference.test.ts‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,13 @@ describe("detectInferenceBackends", () => {
486486

487487
it("checks login status with the Codex executable discovered in a macOS app", async () => {
488488
const command = "/Applications/ChatGPT.app/Contents/Resources/codex";
489-
const probed: Array<{ command: string; args: string[] }> = [];
489+
const probed: Array<{ command: string; args: string[]; timeoutMs?: number }> = [];
490490
const candidates = await detectInferenceBackends({
491491
env: { HOME: "/Users/tester" },
492492
platform: "darwin",
493493
deps: {
494-
probeLocalCommand: async (probedCommand, args = ["--version"]) => {
495-
probed.push({ command: probedCommand, args });
494+
probeLocalCommand: async (probedCommand, args = ["--version"], opts = {}) => {
495+
probed.push({ command: probedCommand, args, timeoutMs: opts.timeoutMs });
496496
return {
497497
command: probedCommand,
498498
found: probedCommand === command,
@@ -504,7 +504,42 @@ describe("detectInferenceBackends", () => {
504504

505505
expect(candidates).toMatchObject([{ kind: "codex-cli", detail: "installed" }]);
506506
expect(candidates[0]?.credentials).toBeUndefined();
507-
expect(probed).toContainEqual({ command, args: ["login", "status"] });
507+
expect(probed).toContainEqual({ command, args: ["--version"], timeoutMs: 3_000 });
508+
expect(probed).toContainEqual({ command, args: ["login", "status"], timeoutMs: 3_000 });
509+
});
510+
511+
it("allows a cold ChatGPT app probe more time than generic CLI discovery", async () => {
512+
const command = "/Applications/ChatGPT.app/Contents/Resources/codex";
513+
const candidates = await detectInferenceBackends({
514+
env: { HOME: "/Users/tester" },
515+
platform: "darwin",
516+
deps: {
517+
probeLocalCommand: async (probedCommand, args = ["--version"], opts = {}) => {
518+
if (probedCommand !== command) {
519+
return { command: probedCommand, found: false };
520+
}
521+
if (args[0] === "login") {
522+
return { command: probedCommand, found: true, version: "Logged in using ChatGPT" };
523+
}
524+
return opts.timeoutMs === 3_000
525+
? { command: probedCommand, found: true, version: "codex-cli 0.149.0" }
526+
: {
527+
command: probedCommand,
528+
found: true,
529+
timedOut: true,
530+
error: "timed out after 1500ms",
531+
};
532+
},
533+
},
534+
});
535+
536+
expect(candidates).toMatchObject([
537+
{
538+
kind: "codex-cli",
539+
credentials: true,
540+
detail: "logged in · ChatGPT subscription",
541+
},
542+
]);
508543
});
509544

510545
it.each([

‎src/commands/onboard-inference.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ function randomizeClaudeCodexTie(
181181

182182
// ChatGPT.app is the current desktop owner; keep Codex stable/beta as fallbacks.
183183
const CODEX_MACOS_APP_NAMES = ["ChatGPT.app", "Codex.app", "Codex Beta.app"] as const;
184+
const CODEX_MACOS_APP_PROBE_TIMEOUT_MS = 3_000;
184185

185186
async function probeCodexCommand(params: {
186187
probe: typeof probeLocalCommand;
@@ -199,7 +200,12 @@ async function probeCodexCommand(params: {
199200
]),
200201
);
201202
for (const executable of appExecutables) {
202-
const appProbe = await params.probe(executable);
203+
// ChatGPT.app's signed Codex binary can spend most of the generic 1.5s
204+
// probe budget in macOS cold-start validation. Keep the broader probe
205+
// contract tight while giving known desktop-app binaries enough headroom.
206+
const appProbe = await params.probe(executable, ["--version"], {
207+
timeoutMs: CODEX_MACOS_APP_PROBE_TIMEOUT_MS,
208+
});
203209
if (appProbe.found) {
204210
return appProbe;
205211
}

0 commit comments

Comments
 (0)