Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-7797 fix(daemon): detect the Codex CLI nested in ChatGPT.app (#8944)
2penheimer10a7e519da96
diff --git a/server/internal/daemon/agents_probe.go b/server/internal/daemon/agents_probe.goindex 0551c32c1c..928a38f670 100644--- a/server/internal/daemon/agents_probe.go+++ b/server/internal/daemon/agents_probe.go@@ -142,7 +142,7 @@ var probeAgentCLIs = func() map[string]AgentEntry {// Codex Desktop bundles its CLI inside the macOS app instead of// installing it onto PATH.for _, p := range codexDesktopAppBundlePaths() {- if _, err := os.Stat(p); err == nil {+ if executableCandidate(p) {return AgentEntry{Path: p,Command: cmd,diff --git a/server/internal/daemon/config.go b/server/internal/daemon/config.goindex 5c80e65901..638df6a43f 100644--- a/server/internal/daemon/config.go+++ b/server/internal/daemon/config.go@@ -978,17 +978,21 @@ var defaultAgentCommandNames = append([]string{// codexDesktopAppBundlePaths returns candidate macOS app-bundle locations for// the bundled Codex CLI. OpenAI relocated the Desktop app from Codex.app to-// ChatGPT.app (#5205). Candidates are ordered by install location first-// (system /Applications before user ~/Applications); within each location the-// new ChatGPT.app path is tried before the legacy Codex.app path, so updated-// installs win while older installs still resolve.+// ChatGPT.app (#5205), then nested the CLI under Resources/codex-cli/bin+// (#8941). Candidates are ordered by install location first (system+// /Applications before user ~/Applications). Within each location the current+// ChatGPT.app nested path is tried before the flat Resources/codex path, which+// is tried before the legacy Codex.app path, so the newest install wins while+// older installs still resolve.var codexDesktopAppBundlePaths = func() []string {paths := []string{+ "/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex","/Applications/ChatGPT.app/Contents/Resources/codex","/Applications/Codex.app/Contents/Resources/codex",}if home, err := os.UserHomeDir(); err == nil {paths = append(paths,+ filepath.Join(home, "Applications", "ChatGPT.app", "Contents", "Resources", "codex-cli", "bin", "codex"),filepath.Join(home, "Applications", "ChatGPT.app", "Contents", "Resources", "codex"),filepath.Join(home, "Applications", "Codex.app", "Contents", "Resources", "codex"),)diff --git a/server/internal/daemon/config_test.go b/server/internal/daemon/config_test.goindex 98220efc46..5be99274e0 100644--- a/server/internal/daemon/config_test.go+++ b/server/internal/daemon/config_test.go@@ -1435,35 +1435,137 @@ func TestLoadConfig_UsesChatGPTAppBundleCodexPath(t *testing.T) {}}-func TestCodexDesktopAppBundlePaths_IncludesChatGPTAndLegacy(t *testing.T) {- paths := codexDesktopAppBundlePaths()- var hasChatGPT, hasLegacy bool- for _, p := range paths {- if strings.Contains(p, "ChatGPT.app") && strings.HasSuffix(filepath.ToSlash(p), "Contents/Resources/codex") {- hasChatGPT = true+// Regression for #8941: ChatGPT.app 26.924+ ships the CLI at+// Resources/codex-cli/bin/codex. Discovery must use that path when the older+// flat Resources/codex file is absent.+func TestLoadConfig_UsesNestedChatGPTCodexCLIPath(t *testing.T) {+ pathDir := t.TempDir()+ nested := filepath.Join(pathDir, "ChatGPT.app", "Contents", "Resources", "codex-cli", "bin", "codex")+ if err := os.MkdirAll(filepath.Dir(nested), 0o755); err != nil {+ t.Fatalf("mkdir: %v", err)+ }+ if err := os.WriteFile(nested, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {+ t.Fatalf("write fake CLI: %v", err)+ }++ oldBundlePaths := codexDesktopAppBundlePaths+ codexDesktopAppBundlePaths = func() []string { return []string{nested} }+ t.Cleanup(func() { codexDesktopAppBundlePaths = oldBundlePaths })++ t.Setenv("PATH", t.TempDir())+ t.Setenv("SHELL", filepath.Join(t.TempDir(), "fish"))+ t.Setenv("MULTICA_DAEMON_ID", "11111111-1111-1111-1111-111111111111")+ pinNonCodexAgentsToMissingPaths(t)++ cfg, err := LoadConfig(Overrides{+ ServerURL: "http://localhost:0",+ WorkspacesRoot: t.TempDir(),+ })+ if err != nil {+ t.Fatalf("LoadConfig: %v", err)+ }+ got, ok := cfg.Agents["codex"]+ if !ok {+ t.Fatalf("expected codex agent from nested ChatGPT.app path, got %#v", cfg.Agents)+ }+ if got.Path != nested {+ t.Fatalf("codex path = %q, want nested path %q", got.Path, nested)+ }+}++// A bundled CLI that exists but cannot be spawned must stay unregistered:+// registering it would advertise a healthy runtime whose every task fails.+func TestProbeAgentCLIsIgnoresNonExecutableCodexBundle(t *testing.T) {+ if runtime.GOOS == "windows" {+ t.Skip("the Codex Desktop app bundle fallback is macOS-only")+ }++ pathDir := t.TempDir()+ nested := filepath.Join(pathDir, "ChatGPT.app", "Contents", "Resources", "codex-cli", "bin", "codex")+ if err := os.MkdirAll(filepath.Dir(nested), 0o755); err != nil {+ t.Fatalf("mkdir: %v", err)+ }+ if err := os.WriteFile(nested, []byte("#!/bin/sh\nexit 0\n"), 0o644); err != nil {+ t.Fatalf("write non-executable fake CLI: %v", err)+ }++ oldBundlePaths := codexDesktopAppBundlePaths+ codexDesktopAppBundlePaths = func() []string { return []string{nested} }+ t.Cleanup(func() { codexDesktopAppBundlePaths = oldBundlePaths })++ t.Setenv("PATH", t.TempDir())+ t.Setenv("SHELL", filepath.Join(t.TempDir(), "fish"))+ pinNonCodexAgentsToMissingPaths(t)++ if _, found := probeAgentCLIs()["codex"]; found {+ t.Fatal("codex was registered from a non-executable app bundle path")+ }+}++// When both the nested CLI and the older flat binary exist, the nested path+// is the current ChatGPT.app layout and must win.+func TestLoadConfig_PrefersNestedChatGPTCodexCLIPath(t *testing.T) {+ pathDir := t.TempDir()+ nested := filepath.Join(pathDir, "ChatGPT.app", "Contents", "Resources", "codex-cli", "bin", "codex")+ flat := filepath.Join(pathDir, "ChatGPT.app", "Contents", "Resources", "codex")+ for _, p := range []string{nested, flat} {+ if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {+ t.Fatalf("mkdir: %v", err)}- if strings.Contains(p, "Codex.app") && strings.HasSuffix(filepath.ToSlash(p), "Contents/Resources/codex") {- hasLegacy = true+ if err := os.WriteFile(p, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {+ t.Fatalf("write fake CLI: %v", err)}}- if !hasChatGPT {- t.Fatalf("codexDesktopAppBundlePaths missing ChatGPT.app entry: %#v", paths)++ oldBundlePaths := codexDesktopAppBundlePaths+ codexDesktopAppBundlePaths = func() []string { return []string{nested, flat} }+ t.Cleanup(func() { codexDesktopAppBundlePaths = oldBundlePaths })++ t.Setenv("PATH", t.TempDir())+ t.Setenv("SHELL", filepath.Join(t.TempDir(), "fish"))+ t.Setenv("MULTICA_DAEMON_ID", "11111111-1111-1111-1111-111111111111")+ pinNonCodexAgentsToMissingPaths(t)++ cfg, err := LoadConfig(Overrides{+ ServerURL: "http://localhost:0",+ WorkspacesRoot: t.TempDir(),+ })+ if err != nil {+ t.Fatalf("LoadConfig: %v", err)+ }+ got, ok := cfg.Agents["codex"]+ if !ok {+ t.Fatalf("expected codex agent, got %#v", cfg.Agents)}- if !hasLegacy {- t.Fatalf("codexDesktopAppBundlePaths missing legacy Codex.app entry: %#v", paths)+ if got.Path != nested {+ t.Fatalf("codex path = %q, want nested path %q", got.Path, nested)}- // New path must be preferred (listed before legacy).- chatgptIdx, legacyIdx := -1, -1+}++func TestCodexDesktopAppBundlePaths_IncludesChatGPTAndLegacy(t *testing.T) {+ paths := codexDesktopAppBundlePaths()+ const (+ nestedSuffix = "ChatGPT.app/Contents/Resources/codex-cli/bin/codex"+ flatSuffix = "ChatGPT.app/Contents/Resources/codex"+ legacySuffix = "Codex.app/Contents/Resources/codex"+ )+ nestedIdx, flatIdx, legacyIdx := -1, -1, -1for i, p := range paths {- if chatgptIdx < 0 && strings.Contains(p, "ChatGPT.app") {- chatgptIdx = i- }- if legacyIdx < 0 && strings.Contains(p, "Codex.app") {+ slash := filepath.ToSlash(p)+ switch {+ case nestedIdx < 0 && strings.HasSuffix(slash, nestedSuffix):+ nestedIdx = i+ case flatIdx < 0 && strings.HasSuffix(slash, flatSuffix):+ flatIdx = i+ case legacyIdx < 0 && strings.HasSuffix(slash, legacySuffix):legacyIdx = i}}- if chatgptIdx < 0 || legacyIdx < 0 || chatgptIdx > legacyIdx {- t.Fatalf("expected ChatGPT.app before Codex.app, got indices chat=%d legacy=%d paths=%#v", chatgptIdx, legacyIdx, paths)+ if nestedIdx < 0 || flatIdx < 0 || legacyIdx < 0 {+ t.Fatalf("codexDesktopAppBundlePaths missing nested, flat, or legacy entry: %#v", paths)+ }+ if nestedIdx > flatIdx || flatIdx > legacyIdx {+ t.Fatalf("expected nested ChatGPT path before flat ChatGPT path before Codex.app, got nested=%d flat=%d legacy=%d paths=%#v", nestedIdx, flatIdx, legacyIdx, paths)}}