Skip to content

Prompt hook: never reaches the running daemon when the umask is 0002 (Ubuntu's default) #3417

Open

Description

@inth3shadows

What happens

With a umask of 0002, the prompt hook never sends a prompt to the project's running daemon and always runs its own explore. That umask is the default for users on Ubuntu and other distributions that give each user a private group.

  • Expected: the hook connects to the daemon the project's MCP session started, as it does with umask 0022.
  • Actual: the hook treats the daemon as missing. codegraph init creates .codegraph/ as drwxrwxr-x under that umask, and the hook refuses a socket in a folder that its group can write to and that has no sticky bit.

Repro (main at eb992b5; not in the latest release v1.6.3, since the daemon path landed after it in #3395; codegraph --version 1.6.3 built from source; Node 22.23.5, Ubuntu 24.04)

The feature's own tests show it. On a fresh clone after npm ci:

(umask 0002; npx vitest run __tests__/daemon-proof.test.ts __tests__/prompt-hook-daemon.test.ts __tests__/prompt-hook-daemon-busy.test.ts)
 Test Files  3 failed (3)
      Tests  9 failed | 33 passed (42)

(umask 0022; npx vitest run __tests__/daemon-proof.test.ts __tests__/prompt-hook-daemon.test.ts __tests__/prompt-hook-daemon-busy.test.ts)
 Test Files  3 passed (3)
      Tests  42 passed (42)

The failures are all the same kind: expected { status: 'unavailable' } to deeply equal { status: 'answered', … }, and the end-to-end hook test injects its own explore instead of FROM THE DAEMON. This happens on every run.

The folder mode, from codegraph init -i in an empty project under umask 0002:

drwxrwxr-x <project>/.codegraph

Cause (verified by logging the check's inputs)

The hook checks the socket's folder before connecting (hook-client.ts#L66-L77). A folder with 0o022 bits set and no sticky bit counts as one where others can replace the socket. For the in-project socket, logging those inputs gave .codegraph/daemon.sock, socket owner and folder owner both this user, folder mode 775. So the check returns false and the loop moves on to the next candidate. The daemon never bound that one, because it only falls back to the temp-directory socket when binding inside the project fails (daemon.ts#L361).

.codegraph/ gets its mode from the umask, because it is created without one (directory.ts#L1030).

The folder check itself looks right, and a fix should keep it: someone who can write to the folder could move the daemon's socket aside and relay through their own. The daemon's proof would still match, since it is bound to the path, not to who listens there. What a fix needs is a socket both sides agree on that passes the check. One way is to skip the in-project candidate when its folder fails the check, the way an over-long path already skips it, so the daemon binds the temp-directory socket (/tmp has the sticky bit) and the hook finds it there.

Impact

This is no correctness bug: the hook still injects context. It loses what #3395 was for, though. Each prompt pays for a cold explore in the hook process instead of using the daemon's warm one. And on a machine with umask 0002, the suite fails 9 tests.

Related: #3284 (the feature request), #3395 (the PR that added the daemon path and this check).

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions