Skip to content

Make NODESPACE_HOME alone isolate a daemon: the socket follows it, agents get the daemon's socket, and the app stops reading it #3640

Closed

Description

@malibio

Overview

NODESPACE_HOME is a test setting for the daemon and the CLI: it lets a test, the e2e harness or an eval run nodespaced with its state away from the user's ~/.nodespace. It is never needed to run NodeSpace, and the desktop app does not read it. Three things keep it from doing that job on its own.

Problem Statement

1. The default socket ignores it. The daemon (default_socket_path_for in packages/daemon/src/main.rs) and the CLI (resolve_socket_path in packages/cli/src/lib.rs) build the default socket from $HOME. With NODESPACE_HOME set and NODESPACED_SOCKET unset:

  • nodespaced binds $HOME/.nodespace/daemon.sock and writes its single-instance lock beside it, in the user's real home;
  • nodespace <command> dials that real-home socket, so it reaches whichever daemon is there, which may be the user's own;
  • nodespace uninstall (which follows NODESPACE_HOME) cleans sockets in the redirected home, where none were created.

Nothing fails today because every harness also sets NODESPACED_SOCKET.

2. An agent the daemon starts loses the daemon's socket. A terminal agent's environment is cleared to HOME, PATH, TERM, SHELL, LANG, USER, TMPDIR plus its auth variables (BASE_ENV_ALLOWLIST and apply_env_allowlist in packages/agent/src/pty/session.rs). Neither NODESPACED_SOCKET nor NODESPACE_HOME reaches it, so a nodespace command the agent runs falls back to the user's real socket. An isolated daemon's agent session then reads and writes the user's real database.

3. The desktop app reads it in one place. packages/desktop-app/app-lib/src/bundled_model.rs holds a copy of the home rule and copies the bundled embedding model under NODESPACE_HOME, while the daemon the app registers looks under the user's home.

Proposed Solution

  • The daemon and the CLI resolve the default socket, and the lock beside it, under the shared home rule (nodespace_daemon::nodespace_dir()). NODESPACED_SOCKET and --socket stay the overrides above it.
  • The daemon gives every agent it starts the path of the socket it is serving, as NODESPACED_SOCKET, whatever its own environment held.
  • The app's read of NODESPACE_HOME is removed: it copies the model under the user's home. The app's socket and daemon management are unchanged; they use the user's home.

Documentation

  • daemon-cli-protocol.md: the transport section lists the paths that follow NODESPACE_HOME and names the socket as the exception.
  • daemon-cli-lifecycle.md: the embedding-model section says the app's copy follows NODESPACE_HOME, with a caveat about the registered daemon.
  • ADR-033: the socket default and the NODESPACED_SOCKET override.
  • ADR-052 §3: the socket's mode is the local-authorization boundary; the directory it is created in stays owner-only.
  • ADR-032: the terminal agent's environment.
  • Updates, pushed with the change: daemon-cli-protocol.md (remove the "socket is the exception" paragraph; add that NODESPACE_HOME is a test setting, never needed to run NodeSpace, and that the desktop app does not read it); daemon-cli-lifecycle.md (the embedding-model section: the app copies under the user's home, and the caveat goes); development/agent-eval.md if its isolation recipe changes.

Architecture Impact

Extends ADR-033 and reverses nothing: with NODESPACE_HOME unset every path is what it is today. No new ADR.

Acceptance Criteria

  • The daemon and the CLI resolve the default socket under the shared home rule, so NODESPACE_HOME alone isolates it. The lock file follows the socket.
  • NODESPACED_SOCKET and --socket still override it.
  • With NODESPACE_HOME unset, every path is what it is today.
  • A test with HOME at a temp "real" home and NODESPACE_HOME at another proves the daemon creates no socket or lock file in the real home and the CLI does not dial one there. Mutation-checked.
  • An agent the daemon starts has NODESPACED_SOCKET set to the socket that daemon serves, including when the daemon's own environment had none. A test launches a stand-in agent and reads its environment.
  • The desktop app contains no read of NODESPACE_HOME; a test launches the model copy with the variable set and finds the model under the user's home. The app/daemon socket agreement test still holds for both build flavours.
  • The docs above are updated in the same change.
  • bun run quality:fix and bun run test:changed pass.

Technical Specifications

Reference Files

  • packages/daemon/src/lib.rs: nodespace_home(), nodespace_home_override(), nodespace_dir(), the shared rule.
  • packages/daemon/src/main.rs: socket_path, default_socket_path_for.
  • packages/cli/src/lib.rs: resolve_socket_path, discover_socket_in.
  • packages/agent/src/pty/session.rs: BASE_ENV_ALLOWLIST, apply_env_allowlist; the launch path that builds the agent's command.
  • packages/desktop-app/app-lib/src/bundled_model.rs: nodespace_home, the app's copy of the rule, to remove.
  • packages/proto/src/socket.rs: daemon_socket_relative returns a home-relative path; incompatible_database_name returns a bare filename joined onto the state directory, which is the shape to follow.
  • packages/cli/tests/it/home_isolation.rs: the two-home test harness to reuse.

Implementation Details

  • default_socket_path_for reads no environment so a plain test can check both flavours; keep that by passing the home in.
  • The daemon knows the socket it bound; pass that path down to the session launch instead of re-deriving it.
  • Windows uses a machine-global named pipe with nothing under the home, so the socket part is unaffected there.
  • The service registration (LaunchAgents plist, systemd unit) and the UI pid file belong to the app and stay under the user's home.

Related Issues

Activity

  1. changed the title [-]Make the daemon's default socket path follow NODESPACE_HOME[/-] [+]Make NODESPACE_HOME alone isolate a daemon: the socket follows it, agents get the daemon's socket, and the app stops reading it[/+] on Oct 5, 2026
  2. self-assigned this
    on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions