codex: the Windows Codex app's own app-server is found, so Connect, Disconnect and failover restart it there too
zhibukaixinyao on Discord (#help, 10-27): on Windows there is no restart, and Codex keeps the old provider until it is restarted by hand. The cause: isCodexAppServer took the Windows app's codex to live under WindowsApps\OpenAI.*, which was a guess. The real ChatGPT/Codex MSIX (OpenAI.Codex 26.1021.3705.0, installed with winget OpenAI.ChatGPT) runs it from %LOCALAPPDATA%\OpenAI\Codex\bin\<hash>\codex.exe ... app-server --analytics-default-enabled. So findCodexApp found nothing, KeepCodexAppOnItsProvider never ended it, and the "still signed in to the old account" notice never showed on Windows. Now that path counts too (WindowsApps is kept); the npm, WinGet Links and --listen app-servers still don't. Run: - go test ./internal/provider -skip TestUnreadLogins: ok except TestFetchAsksASharedBaseOnce and two siblings, red on main and filed as #3854; TestUnreadLoginsWriteErrorsKeepCredentials crashes the package on main, filed as #3632. Neither is touched here. - go test -run 'TestCodexApp|TestFindCodexApp|TestIsCodexClient' ./internal/provider ./internal/agent: ok. - gofmt -l; go vet on darwin, linux -tags nogui and windows; go build for darwin, windows and linux nogui: clean. - On the Windows box (Windows 11, real Codex app 26.1021, sandbox USERPROFILE/APPDATA/LOCALAPPDATA, gateway on :3491, a fake custom provider): `magpie codex fakeai/fake-1` ended the app's app-server and the app started a new one (pid 63320 -> 56692); `magpie codex default` did it again (56692 -> 56216). The app logged the exit as expected (code 0, app_server_restart_recovery_done) and kept its window. The origin/main build left pid 56216 through both. Broken by hand: with the old WindowsApps-only check, TestCodexAppOwnServer and TestFindCodexApp go red on the real Windows command line. Not tried: a signed-in Windows app switching ChatGPT accounts, the durable host, and the managed `codex app-server daemon` (winget's portable codex 0.161 refuses to run it: "the CLI package does not match this platform or executable").
This commit is contained in:
@@ -372,15 +372,28 @@ func TestCodexOutUntil(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// codexWindowsAppServer is the Windows Codex app's own app-server.
|
||||
const codexWindowsAppServer = `C:\Users\yeton\AppData\Local\OpenAI\Codex\bin\2993767bd1dfb009\codex.exe -c features.code_mode_host=true app-server --analytics-default-enabled -c plugins.codex-app-tools@openai-bundled.mcp_servers.codex_app.enabled=true`
|
||||
|
||||
// Only the app's own app-server is restarted: another program's, started
|
||||
// from the app's bundled codex with --listen (Miyi Helper's, seen on the
|
||||
// owner's Mac), is that program's.
|
||||
func TestCodexAppOwnServer(t *testing.T) {
|
||||
own := "/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex -c features.code_mode_host=true app-server --analytics-default-enabled -c plugins.codex-app-tools@openai-bundled.mcp_servers.codex_app.enabled=true"
|
||||
if !isCodexAppOwnServer(own) {
|
||||
t.Fatalf("the app's own app-server not taken: %s", own)
|
||||
for _, own := range []string{
|
||||
"/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex -c features.code_mode_host=true app-server --analytics-default-enabled -c plugins.codex-app-tools@openai-bundled.mcp_servers.codex_app.enabled=true",
|
||||
// the Windows app's (OpenAI.Codex 26.1021, ChatGPT.exe's child),
|
||||
// as Windows listed it on the Windows box: run from LOCALAPPDATA,
|
||||
// not from its package (zhibukaixinyao on Discord)
|
||||
codexWindowsAppServer,
|
||||
} {
|
||||
if !isCodexAppOwnServer(own) {
|
||||
t.Errorf("the app's own app-server not taken: %s", own)
|
||||
}
|
||||
}
|
||||
for _, other := range []string{
|
||||
`C:\Users\me\AppData\Local\OpenAI\Codex\bin\2993767bd1dfb009\codex.exe app-server --listen stdio://`,
|
||||
`C:\Users\me\AppData\Roaming\npm\node_modules\@openai\codex\vendor\x86_64-pc-windows-msvc\codex\codex.exe app-server`,
|
||||
`C:\Users\me\AppData\Local\Microsoft\WinGet\Links\codex.exe app-server`,
|
||||
"/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex app-server --listen stdio://",
|
||||
"/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex app-server --listen=ws://127.0.0.1:4500",
|
||||
"/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex -c forced_login_method=\"chatgpt\" exec-server --remote https://codex-cloud-environments.chatgpt.com/api",
|
||||
|
||||
@@ -258,9 +258,12 @@ func DismissCodexApp() {
|
||||
// Codex desktop app runs for itself: 0 when it isn't open. On macOS that
|
||||
// is ChatGPT.app's (or Codex.app's) bundled codex, `…/CodexCLI.app/
|
||||
// Contents/MacOS/codex [-c k=v…] app-server --analytics-default-enabled …`;
|
||||
// on Windows the Store app's `…\WindowsApps\OpenAI.Codex_…\codex.exe
|
||||
// app-server`. Not the managed daemon, nor an app-server's helpers or
|
||||
// proxy, nor an editor's codex.
|
||||
// on Windows the Store app's (OpenAI.Codex, ChatGPT.exe), which copies its
|
||||
// codex out of WindowsApps and runs it from %LOCALAPPDATA%:
|
||||
// `C:\Users\…\AppData\Local\OpenAI\Codex\bin\<hash>\codex.exe -c … app-server
|
||||
// --analytics-default-enabled …` (26.1021 on the Windows box). Not the
|
||||
// managed daemon, nor an app-server's helpers or proxy, nor an editor's
|
||||
// codex.
|
||||
func findCodexApp(ps []proc.Process) int {
|
||||
for _, p := range ps {
|
||||
if isCodexAppServer(p.Args) {
|
||||
@@ -278,7 +281,7 @@ func isCodexAppServer(args string) bool {
|
||||
// the program's own path: ps leaves a path's spaces unquoted, so
|
||||
// "…/Codex Computer Use.app/Contents/MacOS/…" reads as one named Codex
|
||||
exe, rest := splitExe(args)
|
||||
if !strings.Contains(exe, ".app/Contents/") && !strings.Contains(exe, `\WindowsApps\OpenAI.`) {
|
||||
if !strings.Contains(exe, ".app/Contents/") && !windowsCodexApp(exe) {
|
||||
return false
|
||||
}
|
||||
if base := strings.ToLower(exe[strings.LastIndexAny(exe, `/\`)+1:]); base != "codex" && base != "codex.exe" {
|
||||
@@ -289,6 +292,14 @@ func isCodexAppServer(args string) bool {
|
||||
return i >= 0 && (i+1 >= len(f) || strings.HasPrefix(f[i+1], "-"))
|
||||
}
|
||||
|
||||
// windowsCodexApp is whether exe is the Windows Codex app's codex: the one
|
||||
// it runs from %LOCALAPPDATA%\OpenAI\Codex\bin\<hash>\, or one in its
|
||||
// package under WindowsApps.
|
||||
func windowsCodexApp(exe string) bool {
|
||||
e := strings.ToLower(exe)
|
||||
return strings.Contains(e, `\appdata\local\openai\codex\bin\`) || strings.Contains(e, `\windowsapps\openai.`)
|
||||
}
|
||||
|
||||
// RestartCodexDaemon has Codex restart its app-server, which reads the
|
||||
// sign-in again: `codex app-server daemon restart`, run with the codex CLI
|
||||
// magpie finds and the Codex home it signs Codex in through. Codex 0.162's
|
||||
|
||||
@@ -339,6 +339,7 @@ func TestIsCodexClient(t *testing.T) {
|
||||
"/Users/me/.vscode/extensions/openai.chatgpt-1.0/bin/darwin-aarch64/codex app-server": false,
|
||||
"codex mcp-server": false,
|
||||
`"C:\Program Files\WindowsApps\OpenAI.Codex_1.0\app\resources\codex.exe" app-server`: false,
|
||||
codexWindowsAppServer: false,
|
||||
// other programs
|
||||
"/Users/me/.codex/plugins/cache/chrome/extension-host ChatGPT for Chrome": false,
|
||||
// a path with a space, as the user's own ps showed it
|
||||
@@ -493,8 +494,9 @@ func TestFindCodexApp(t *testing.T) {
|
||||
// (ChatGPT 26.1007), beside a terminal codex and the managed daemon
|
||||
app := "/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex -c features.code_mode_host=true app-server --analytics-default-enabled -c plugins.codex-app-tools@openai-bundled.mcp_servers.codex_app.enabled=true"
|
||||
for want, ps := range map[int][]proc.Process{
|
||||
9: {{PID: 3, Args: "codex"}, {PID: 4, Args: "/Users/me/.codex/packages/app-server-daemon/releases/0.162.0-aarch64-apple-darwin/bin/codex app-server --listen unix:///x --managed-daemon"}, {PID: 9, Args: app}},
|
||||
8: {{PID: 8, Args: `"C:\Program Files\WindowsApps\OpenAI.Codex_1.0\app\resources\codex.exe" app-server`}},
|
||||
9: {{PID: 3, Args: "codex"}, {PID: 4, Args: "/Users/me/.codex/packages/app-server-daemon/releases/0.162.0-aarch64-apple-darwin/bin/codex app-server --listen unix:///x --managed-daemon"}, {PID: 9, Args: app}},
|
||||
8: {{PID: 8, Args: `"C:\Program Files\WindowsApps\OpenAI.Codex_1.0\app\resources\codex.exe" app-server`}},
|
||||
61552: {{PID: 3, Args: `C:\Users\yeton\AppData\Local\Microsoft\WinGet\Links\codex.exe`}, {PID: 61552, Args: codexWindowsAppServer}},
|
||||
0: {
|
||||
{PID: 3, Args: "codex app-server proxy"},
|
||||
{PID: 5, Args: "/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex exec-server --remote x"},
|
||||
|
||||
Reference in New Issue
Block a user