Skip to content

codex app-server daemon commands fail with path must be shorter than SUN_LEN when CODEX_HOME is a deep path (macOS) #27765

Closed

Description

@Bohan-J

Summary

All codex app-server daemon client commands (version, start, stop, ...) derive the control socket path as $CODEX_HOME/app-server-control/app-server-control.sock. On macOS, the sun_path limit for Unix domain sockets is 104 bytes, so any CODEX_HOME longer than ~60 characters makes these commands fail before they can connect:

Error: failed to connect to <CODEX_HOME>/app-server-control/app-server-control.sock

Caused by:
    path must be shorter than SUN_LEN

There is currently no way to override the control socket location for the daemon client commands: codex app-server proxy accepts --sock, and the server side accepts --listen unix://PATH, but codex app-server daemon version/start/stop do not, and there is no config key or environment variable for it (the path is hardcoded in app_server_control_socket_path() in codex-rs/app-server-transport/src/transport/mod.rs).

Deep CODEX_HOME paths are common for tools that run Codex in isolated per-task or per-project homes (CI sandboxes, agent platforms, devcontainer setups), where the home lives inside a nested workspace directory and easily exceeds the budget.

Environment

  • macOS (Darwin 25.4.0, arm64)
  • codex-cli 0.137.0 (also reported on 0.139.0)

Reproduction

DEEP="/tmp/codex-sunlen-repro/$(printf 'a%.0s' {1..40})/$(printf 'b%.0s' {1..40})/codex-home"
mkdir -p "$DEEP"
echo "${#DEEP}"   # 116 chars
CODEX_HOME="$DEEP" codex app-server daemon version

Output:

Error: failed to connect to /private/tmp/codex-sunlen-repro/aaaa…aaaa/bbbb…bbbb/codex-home/app-server-control/app-server-control.sock

Caused by:
    path must be shorter than SUN_LEN

Note that pointing CODEX_HOME at a short symlink to the deep directory does not help: the home is canonicalized before the socket path is derived (visible above as /tmp resolving to /private/tmp), so the resolved long path still exceeds the limit.

Expected behavior

codex app-server daemon commands should work regardless of how deep CODEX_HOME is. Any of the following would solve it:

  1. An override for the control socket directory — a config key (e.g. app_server.control_socket_dir), an environment variable, or a --sock flag on the daemon subcommands (matching the existing codex app-server proxy --sock).
  2. A short hashed default location when the derived path would exceed the platform limit — e.g. $TMPDIR/codex-<hash-of-CODEX_HOME>/control.sock, similar to how OpenSSH solves the same problem with ControlPath %C.
  3. At minimum, a clearer error message that names CODEX_HOME length as the cause and suggests a workaround.

Activity

  1. added
    bug
    CLI
    app-server
    on Jun 12, 2026
  2. wgu9 commented on Jun 15, 2026

    @wgu9

    I checked current main and this still looks like a single choke point rather than a daemon-only bug.

    The default control socket path is built in codex-rs/app-server-transport/src/transport/mod.rs:

    pub fn app_server_control_socket_path(codex_home: &Path) -> std::io::Result<AbsolutePathBuf> {
        AbsolutePathBuf::from_absolute_path(
            codex_home
                .join(APP_SERVER_CONTROL_SOCKET_DIR_NAME)
                .join(APP_SERVER_CONTROL_SOCKET_FILE_NAME),
        )
    }

    That same helper is used by:

    • codex-rs/app-server-daemon/src/lib.rs in Daemon::from_environment() for lifecycle commands such as version, start, stop, etc.
    • AppServerTransport::from_listen_url("unix://"), so the default Unix listener path has the same long-CODEX_HOME exposure.
    • codex app-server proxy when --sock is omitted.
    • TUI/default daemon probing paths that try to discover the local app-server daemon.

    So I would avoid fixing this only in the CLI command parser. A more robust fix would make app_server_control_socket_path() return a platform-safe path by default, or add a single resolver beside it that all default-control-socket callers use.

    Patch shape that seems low-risk:

    1. Keep the current $CODEX_HOME/app-server-control/app-server-control.sock path while it is short enough.
    2. If the path exceeds the Unix-domain-socket budget, fall back to a short per-user temp/runtime path keyed by a hash of canonical CODEX_HOME, for example $TMPDIR/codex-app-server/<hash>/control.sock.
    3. Keep the startup/operation lock and pid/settings state under CODEX_HOME; only the UDS rendezvous path needs to move.
    4. Add coverage in codex-rs/app-server-transport/src/transport/unix_socket_tests.rs for a deep CODEX_HOME and for stable hashing, plus one daemon/client smoke test if the final API surface changes.

    One small test detail: find_codex_home() canonicalizes CODEX_HOME, so the regression test should create the deep directory first and assert against the canonical path length. That matches the reported /tmp -> /private/tmp behavior on macOS.

  3. kyoh86 commented on Jun 26, 2026

    @kyoh86

    I can reproduce the same failure on Ubuntu 24.04.4 LTS on WSL2.

    Environment:

    • Codex CLI: codex-cli 0.142.2
    • OS: Ubuntu 24.04.4 LTS on WSL2
    • Kernel: 6.6.87.2-microsoft-standard-WSL2
    • WSL version: 2.6.3.0
    • Architecture: x86_64

    In my case this shows up when CODEX_HOME is configured under an XDG-style config path and resolves to a long path. The symlink/dotfiles detail is only one way to hit the issue; the underlying problem is that runtime socket paths are derived from CODEX_HOME.

    I also think it would be useful to separate the default location question from the override question:

    • Runtime IPC files such as Unix sockets, pid files, and locks should probably not live under CODEX_HOME by default.
    • On Linux, XDG_RUNTIME_DIR seems like a more appropriate default for runtime files.
    • However, XDG_RUNTIME_DIR can also be unsuitable in some environments, so a Codex-specific override such as CODEX_RUNTIME_DIR or CODEX_APP_SERVER_RUNTIME_DIR would still be valuable.

    So the desired shape from my perspective would be:

    1. Keep durable Codex config/state under CODEX_HOME.
    2. Put app-server runtime files under a runtime directory by default, e.g. XDG_RUNTIME_DIR on Linux.
    3. Provide an explicit Codex-specific environment variable or config key for the runtime directory, so users can choose a short/suitable path when needed.
  4. nezc commented on Jul 10, 2026

    @nezc

    I can reproduce this through Codex Desktop SSH to a Linux remote.

    • Codex App: 26.707.31428 (build 5059) on macOS 15.7.3
    • Remote CLI: codex-cli 0.144.1
    • Remote /root is a symlink to a deeply nested persistent-volume path
    • Canonical control-socket path: 130 bytes

    SSH public-key authentication, the remote shell/version probes, and app-server bootstrap all succeed. The failure occurs when Desktop runs codex app-server proxy:

    Error: failed to connect to socket at
    /redacted/deep/path/.codex/app-server-control/app-server-control.sock
    
    Caused by:
        path must be shorter than SUN_LEN
    

    Desktop then surfaces only ECONNRESET: socket hang up, making this look like an SSH/network failure.

    This confirms the same path-length bug also blocks the Desktop SSH flow. A short symlink does not help because CODEX_HOME is canonicalized; using a genuinely short real path/bind mount works around it.

  5. tsuvic commented on Aug 7, 2026

    @tsuvic

    Still reproduces on current macOS builds (arm64), identically on both:

    • standalone CLI 0.146.0
    • ChatGPT desktop bundled codex 0.147.0-alpha.6.5
    $ DEEP=/tmp/x/aaaa…(40)/bbbb…(40)/codex-home   # 116 chars
    $ CODEX_HOME=$DEEP codex app-server daemon version
    Error: failed to connect to /private/tmp/x/aaaa…/bbbb…/codex-home/app-server-control/app-server-control.sock
    
    Caused by:
        path must be shorter than SUN_LEN
    

    Including the /tmp → /private/tmp canonicalization that defeats short-symlink workarounds.

    Update — traced to a single choke point on current main:

    • app_server_control_socket_path() (codex-rs/app-server-transport/src/transport/mod.rs:54–62) always returns CODEX_HOME/app-server-control/app-server-control.sock (+44 bytes), and find_codex_home() canonicalizes a CODEX_HOME env value (codex-rs/utils/home-dir/src/lib.rs:45), hence /private/tmp.
    • The error itself comes from Rust std (os/unix/net/addr.rs): macOS sun_path is 104 bytes, so the usable budget for CODEX_HOME is 103 − 44 = 59 bytes.
    • Everything (daemon bind/connect, TUI auto-connect, codex doctor, app-server proxy) funnels through that one function — which is also why doctor misreports "stale or unreachable" here.

    The repo already solves this exact problem two other places: codex-rs/linux-sandbox/src/proxy_routing.rs:58 (UNIX_SOCKET_PATH_MAX_BYTES + /tmp fallback chain) and codex-rs/tui/src/ide_context/ipc.rs:179–190 ($TMPDIR/codex-ipc/… fallback + explicit sockaddr_un length checks). The control socket is the last unhandled site.

    Suggested fix (hybrid, zero migration): keep the classic path when it fits (≤103 bytes — every currently working install); otherwise fall back to a deterministic short path both daemon and clients can compute with no I/O:

    /tmp/codex-<uid>/<sha256(canonical CODEX_HOME)[:16]>/app-server-control.sock
    

    (Linux: prefer $XDG_RUNTIME_DIR/codex; root dir verified uid-owned + 0700.) Collision safety can be hardened for free by checking InitializeResponse.codex_home on fallback probes. Deep-CODEX_HOME installs are fully broken today, so there is nothing to stay compatible with.

  6. tsuvic commented on Aug 19, 2026

    @tsuvic

    Still reproduces on 0.148.0 (release binary, macOS arm64), identically to 0.137–0.147:

    $ CODEX_HOME=/tmp/x/aaaa…(40)/bbbb…(40)/codex-home   # deep path
    $ codex app-server daemon version
    Error: failed to connect to /private/tmp/x/aaaa…/bbbb…/codex-home/app-server-control/app-server-control.sock
    
    Caused by:
        path must be shorter than SUN_LEN
    

    Including the /tmp → /private/tmp canonicalization (+8 bytes) that defeats short-symlink workarounds.

    On current main the single choke point is unchanged: app_server_control_socket_path() (codex-rs/app-server-transport/src/transport/mod.rs:58–64) still has no length handling, and every producer/consumer (daemon bind/connect, TUI auto-connect, codex doctor, app-server proxy) funnels through it. The hybrid fallback suggested in my earlier comment (keep the classic path when ≤103 bytes, otherwise a deterministic hashed short path both sides can compute without I/O) still applies; the in-tree templates for exactly this remain codex-rs/linux-sandbox/src/proxy_routing.rs and codex-rs/tui/src/ide_context/ipc.rs.

  7. seonghoshim commented on Aug 26, 2026

    @seonghoshim

    I can confirm that this still reproduces on Codex CLI 0.149.1 when launched through Orca, which uses an isolated per-account CODEX_HOME.

    Environment

    • macOS 26.5.2 (Build 25F84), arm64
    • Orca 1.4.184
    • Codex CLI 0.149.1
    • CODEX_HOME length: 108 bytes
    • Derived control socket path length: 151 bytes

    The generated path has this form:

    /Users/<user>/Library/Application Support/orca/codex-accounts/<account-id>/home/app-server-control/app-server-control.sock
    
    Starting a normal Codex session through Orca produces:
    
    Failed to start the background server: Error: app server did not become ready on <CODEX_HOME>/app-server-control/app-server-control.sock
    
    Managed app-server stderr:
      Error: path must be shorter than SUN_LEN
    
    Caused by:
        0: failed to connect to <CODEX_HOME>/app-server-control/app-server-control.sock
        1: path must be shorter than SUN_LEN
    
    The managed app-server binary is:
    
    Codex CLI 0.149.1
    
    codex doctor --json reports that the background server is not running, while the installation, configuration, authentication, and provider reachability checks all pass.
    
    This is worth noting because the deep path is not an unusual project path configured manually. It is the default per-account home layout generated by Orca under macOS Application
    Support. This means GUI or integration hosts that isolate Codex accounts can exceed the socket-path limit by default.
    
    There is no existing control socket, and restarting only reproduces the same bind/connect failure. This confirms that the issue remains present in 0.149.1.
    
  8. LuizPiccini commented on Sep 25, 2026

    @LuizPiccini

    Still reproduces on codex-cli 0.157.0 (Homebrew cask, macOS arm64), and 0.157.0 makes it more visible: plain codex now installs and starts the managed daemon on launch, so a deep CODEX_HOME breaks the default interactive launch rather than only codex app-server daemon ....

    $ codex
    Installing daemon from CLI version 0.157.0 into <CODEX_HOME>/packages/app-server-daemon...
    Error: app server did not become ready on <CODEX_HOME>/app-server-control/app-server-control.sock
      version: 0.157.0: failed to connect to <CODEX_HOME>/app-server-control/app-server-control.sock: path must be shorter than SUN_LEN
    

    CODEX_HOME here is an Orca per-account home (~/Library/Application Support/orca/codex-accounts/<uuid>/home), giving a 147-byte socket path.

    New detail: in 0.157.0 the listener side already has a short-path fallback, but the client side does not use it. After the failed launch:

    • The daemon process was running (.../app-server-daemon/releases/0.157.0-aarch64-apple-darwin/bin/codex app-server --listen unix:// ...).
    • It had bound a real socket at /private/tmp/codex-daemon-501/<sha256>, where <sha256> is the SHA-256 of the full long socket path.
    • <CODEX_HOME>/app-server-control/app-server-control.sock was a symlink to that short socket.

    So the server is reachable, but the client still passes the long symlink path to connect(), and Rust std rejects it for length before the kernel could follow the link. Making the connect side compute the same fallback path (/tmp/codex-daemon-<uid>/sha256(<derived path>)) when the derived path exceeds the limit looks like the missing half of the fix.

    Workaround confirmed: move the real home to a short path and leave the long path as a symlink to it. Because find_codex_home() canonicalizes, the derived socket path becomes short (60 bytes here):

    mv "$LONG_HOME" ~/.codex-orca/<id> && ln -s ~/.codex-orca/<id> "$LONG_HOME"
    codex app-server daemon version
    # {"status":"running",...,"socketPath":"/Users/<user>/.codex-orca/<id>/app-server-control/app-server-control.sock","appServerVersion":"0.157.0"}

    The opposite symlink (short link pointing at the long home) does not help, as noted above.

  9. hpg-mheck commented on Sep 25, 2026

    @hpg-mheck

    Confirmed on Rocky Linux 10.2, x86_64, with codex-cli 0.157.0 installed from @openai/codex via npm. This blocks ordinary interactive startup with a project-local isolated HOME, not just explicit daemon commands.

    Our affected installation has a 111-byte advertised control socket pathname. Installation and codex --version succeeded, but plain interactive startup waited roughly a minute and then reported:

    Error: app server did not become ready on <CODEX_HOME>/app-server-control/app-server-control.sock
    failed to connect to <CODEX_HOME>/app-server-control/app-server-control.sock:
    path must be shorter than SUN_LEN
    

    Linux confirmation of the listener/client mismatch described above: after the failed launch, the daemon was still running. The long advertised socket pathname was a symlink to /tmp/codex-daemon-<uid>/<64-hex-digest>. The target was an actual socket with mode 0600; its physical pathname was only 87 bytes on this machine. The client nevertheless reported the overlong advertised pathname.

    I also tested codex app-server daemon version with fresh, credential-free temporary homes and exact socket-path byte lengths:

    Derived socket pathname Result
    107 bytes No such file or directory (os error 2), expected because this disposable home has no daemon
    108 bytes path must be shorter than SUN_LEN
    111 bytes path must be shorter than SUN_LEN

    Reproduction of the boundary, without starting a daemon or making model requests:

    python3 - /absolute/path/to/codex <<'PY'
    import os
    from pathlib import Path
    import subprocess
    import sys
    import tempfile
    
    suffix = "/app-server-control/app-server-control.sock"
    with tempfile.TemporaryDirectory(prefix="cw-uds-", dir="/tmp") as temporary:
        root = Path(temporary).resolve()
        for length in (107, 108, 111):
            padding = length - len(os.fsencode(root)) - 1 - len(suffix)
            context = root / ("x" * padding)
            context.mkdir(mode=0o700)
            env = {"PATH": os.environ["PATH"], "HOME": str(root),
                   "CODEX_HOME": str(context)}
            result = subprocess.run(
                [sys.argv[1], "app-server", "daemon", "version"],
                env=env, capture_output=True, text=True, timeout=10,
            )
            print(f"{length} bytes: exit {result.returncode}")
            print(result.stdout + result.stderr)
    PY

    Codex additionally warns about not creating PATH helper aliases under /tmp in this disposable reproduction; the original interactive failure occurs with persistent project-local state outside /tmp.

    Workaround verified: adding --no-daemon to the original launcher reached the actual interactive prompt with the configured model and project loaded, while retaining the same HOME, authentication, and session storage. It bypasses daemon functionality.

    The existing short physical socket makes a shared, security-checked client/server socket resolver look preferable to relocating persistent CODEX_HOME. A regression test should cover a real listener plus a client connecting through an overlong advertised alias, in addition to boundary-length checks.

  10. Kooooojun commented on Sep 25, 2026

    @Kooooojun

    補充確認:0.157.0/Ubuntu 24.04 WSL2/Windows Orca,以及搬移 home 的相容性限制

    此問題也會阻擋 Windows Orca 管理的 WSL Codex 帳號啟動。

    環境

    • Codex CLI 與 managed app-server:0.157.0
    • Ubuntu 24.04/WSL2,x86_64
    • Linux kernel:6.18.33.2-microsoft-standard-WSL2
    • Orca:1.4.211,Windows win32 10.0.26200 x64
    • Orca 管理的 CODEX_HOME 形式:/home/<user>/.local/share/orca/codex-accounts/<account-id>/home
    • 原始控制 socket 路徑實測為 133 bytes;以下路徑已去識別化,不代表遮罩後的字串長度。

    實際錯誤與更新差異

    執行 codex --yolo 後:

    Error: app server did not become ready on <CODEX_HOME>/app-server-control/app-server-control.sock
    Daemon used app-server:
      path: <CODEX_HOME>/packages/app-server-daemon/current/bin/codex
      version: 0.157.0: failed to connect to <CODEX_HOME>/app-server-control/app-server-control.sock: path must be shorter than SUN_LEN
    

    codex app-server daemon version 也會因同一路徑限制失敗。

    版本原始碼顯示,0.156.1 的 daemon_auto_start 為 experimental、預設 false,0.157.0 改成 stable、預設 true。這解釋了為何既有長目錄在更新後開始阻擋一般互動啟動,而不只是顯式 daemon 命令。

    隔離重現:短實體 socket 可以使用

    另以不含登入資料的臨時長 CODEX_HOME 啟動 codex app-server --listen unix://,實測:

    路徑/操作 結果
    衍生控制 socket alias,155 bytes Unix connect 失敗:AF_UNIX path too long
    alias 指向的實際 socket,87 bytes,位於 /tmp/codex-daemon-<uid>/<hash> WebSocket upgrade 與 JSON-RPC initialize 成功,服務回報 0.157.0

    此測試未發送模型 prompt;臨時服務已停止、測試目錄已清理。它支持前述 listener/client 路徑不一致的診斷:服務端可以提供短實體 socket,但預設客戶端仍嘗試連過長的 alias。

    重要限制:搬移實體 home 並留下 symlink 不適合此 Windows Orca 環境

    曾把帳號實體 home 搬到短路徑,並在 Orca 原位置留下指向短路徑的 Linux 絕對 symlink。當時:

    • 控制 socket 降為 99 bytes。
    • Linux 的 daemon version 回報 running;codex --yolo 能連上 daemon 並進入 Ready。
    • 但 Windows Orca 隨即無法對原 UNC home 執行 mkdir:
    ENOENT: no such file or directory, mkdir '\\wsl.localhost\Ubuntu-24.04\home\<user>\.local\share\orca\codex-accounts\<account-id>\home'
    

    該改動已完整撤回:home 恢復原位置的實體目錄。Windows Test-Path 與 System.IO.Directory.CreateDirectory 均再次成功,Orca 也恢復正常。因此,搬移持久帳號資料不是此跨平台整合環境的可行通用解法;此處只回報觀察到的行為,不推論所有 Windows/WSL symlink 均不可用。

    目前可用的 workaround

    保留原 Orca home,在既有 [features] 區段設定:

    [features]
    daemon_auto_start = false

    一般 Codex 與 Orca 可以使用,但這會放棄自動共用 daemon,並非根治。

    希望修正預設客戶端的 socket resolver,讓它在維持使用者/路徑安全檢查的前提下,與服務端使用同一個短實體 socket;不需要搬動 CODEX_HOME。建議回歸測試涵蓋超長 home 的 listener + client,以及在原帳號目錄完全不變的情況下恢復正常 daemon 連線。

  11. brennanb2025 commented on Sep 25, 2026

    @brennanb2025

    This is also hitting me, and since 0.157 it's severe: plain codex no longer starts at all. It isn't limited to the codex app-server daemon subcommands anymore. Every launch in a Codex home deeper than about 60 bytes (macOS) or 64 (Linux) fails with app server did not become ready ... path must be shorter than SUN_LEN. That covers every per-account home created by tools like Orca, so affected users get a CLI that refuses to start until they know to pass --no-daemon. It also leaves an orphaned daemon running after each failed launch. Since 0.157 turned on daemon auto-start by default, this is now a startup blocker, not an edge case.

    The server side already handles a deep CODEX_HOME: start_control_socket_acceptor binds a short socket at /tmp/codex-daemon-<uid>/<sha256> and publishes <CODEX_HOME>/app-server-control/app-server-control.sock as a symlink to it. The client side never gets that far. Every client connects through the long symlink path, and Rust's UnixStream::connect rejects any path longer than sun_path (104 bytes on macOS, 108 on Linux) before calling connect(2), so the kernel never follows the symlink.

    That affects every client on this path: the TUI's default-daemon probe, codex app-server daemon start (its readiness wait fails even though the daemon is up and bound), daemon version, app-server proxy, and the remote app-server client. On 0.157 the daemon is left running, unused, after plain codex fails.

    It starts once CODEX_HOME is longer than 60 bytes on macOS (64 on Linux), which tools that keep a per-account Codex home (Orca among them) reach easily.

    A possible fix: in codex_uds's Unix connect, when the path does not fit in sun_path, connect to the protected socket instead, but only if the rendezvous path is a symlink whose target is exactly the protected path recomputed the way the listener computes it, and the shared daemon directory is still user-owned with mode 0700. Paths that fit behave as before, and every caller is covered from one place.

  12. goodman-oai commented on Nov 16, 2026

    @goodman-oai
    Contributor

    Closing as completed. The long control-socket path fix shipped in 0.159.0 via #48772. On macOS with 0.169.0, codex app-server daemon version connected to a running app-server and returned its version with a 154-byte CODEX_HOME.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIapp-serverbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions