`codex app-server daemon` commands fail with `path must be shorter than SUN_LEN` when CODEX_HOME is a deep path (macOS)
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:
- An override for the control socket directory — a config key (e.g.
app_server.control_socket_dir), an environment variable, or a--sockflag on thedaemonsubcommands (matching the existingcodex app-server proxy --sock). - 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 withControlPath %C. - At minimum, a clearer error message that names
CODEX_HOMElength as the cause and suggests a workaround.
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.rsinDaemon::from_environment()for lifecycle commands such asversion,start,stop, etc.AppServerTransport::from_listen_url("unix://"), so the default Unix listener path has the same long-CODEX_HOMEexposure.codex app-server proxywhen--sockis 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:
- Keep the current
$CODEX_HOME/app-server-control/app-server-control.sockpath while it is short enough. - 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. - Keep the startup/operation lock and pid/settings state under
CODEX_HOME; only the UDS rendezvous path needs to move. - Add coverage in
codex-rs/app-server-transport/src/transport/unix_socket_tests.rsfor a deepCODEX_HOMEand 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.