fix(daemon): keep the socket path under the AF_UNIX limit - #267
Merged
Conversation
The socket address is <runtime dir>/daemon.sock, but sun_path caps a unix socket at 104 bytes on macOS (108 on Linux) where ordinary files get PATH_MAX. A deep $HOME -- a sandbox, a container, a CI runner -- pushes past it, and bind() fails with "AF_UNIX path too long" surfacing as "Daemon process exited before it became ready", which reads like a broken install rather than a path-length problem. Fall back to a short temp-dir address keyed by a hash of the runtime dir when the natural path is too long, so distinct runtime dirs keep distinct sockets; the uid is in the name because /tmp is shared on Linux. Client and daemon both resolve through daemon_socket_path(), so they agree either way. Found by an eval agent working in a sandbox with a long $HOME; it lost several turns diagnosing the daemon before deducing the COCOINDEX_CODE_RUNTIME_DIR workaround. Note pytest's own tmp_path is ~118 bytes on macOS, so the overflow is not an exotic case. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LksW8LnigLAiFnrgLauW8M
junzh0u
marked this pull request as ready for review
August 5, 2026 04:21
Member
|
great fix, thanks @junzh0u ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The daemon socket lives at
<runtime dir>/daemon.sock, but a unix socket address is capped at 104 bytes on macOS/BSD (108 on Linux) where ordinary files get ~1024. A deep runtime dir — long$HOME, sandbox, container, CI workspace — makesbind()fail withOSError: AF_UNIX path too long, which reaches the user as "Daemon process exited before it became ready" and reads like a broken install. A home directory ~72 bytes deep is enough, since/.cocoindex_code/daemon.sockadds 28.When the natural path is over the limit, fall back to a short temp-dir address named
ccc-<uid>-<hash of runtime dir>.sock— hashed so daemons differing only byCOCOINDEX_CODE_RUNTIME_DIRkeep distinct sockets, uid because/tmpis shared on Linux. Below the limit, nothing changes.Validation
Real output, using the runtime dir from a sandbox that hit this:
Reproduce the original failure on macOS — fails before, starts after:
Worth knowing on review: the limit applies to the string passed to
bind(), not the path after symlink resolution (verified directly — a 102-byte/var/...address binds even though it resolves to 110 under/private). So the check measures the unresolved string.uv run pytest— 298 passed, 3 new (short path unchanged, fallback under the limit, two over-long runtime dirs don't collide)uv run prek run --all-files— passedOperational impact
None — no migration, no config change, no new setting. A daemon already running keeps its socket, since it was under the limit or it would not have started. Windows named pipes are unaffected; that branch only shares the new hash helper.
Independent of #243 (daemon startup races) — different files, different failure mode.
🤖 Generated with Claude Code