Skip to content

Bundle nodespaced and nodespace CLI in Tauri DMG with launchd agent registration #1179

Closed

Description

@malibio

Overview

The CI/CD pipeline produces a `.dmg` via `tauri build`. Currently only the Tauri app is bundled. `nodespaced` (the daemon) and `nodespace` (the CLI) need to be included in the `.dmg` and `nodespaced` must be registered as a launchd user agent so it starts at login and survives UI window close.

Problem Statement

Under ADR-031, `nodespaced` owns the RocksDB lock, all business logic, the system tray, and background compute (embeddings, local agent). The Tauri app is a thin gRPC client. If `nodespaced` is not running before the Tauri app launches, the UI cannot connect and all operations fail.

A sidecar approach (Tauri spawns `nodespaced` as a child process) would tie the daemon lifecycle to the UI window — defeating the purpose of the daemon architecture. The daemon must survive UI close so the local agent, embeddings, and (future) sync continue running headlessly.

The correct macOS pattern is a launchd user agent: registered in `~/Library/LaunchAgents/`, starts at login, restarts on crash, independent of any window.

Proposed Solution

  • Bundle `nodespaced` and `nodespace` as Tauri sidecar binaries inside the `.app`
  • On first launch, the Tauri app extracts both binaries to `/.nodespace/bin/` and writes a launchd plist to `/Library/LaunchAgents/app.nodespace.daemon.plist`
  • Load the plist via `launchctl load` so `nodespaced` starts immediately (no reboot required)
  • On subsequent launches, check if `nodespaced` is already running before attempting to start it
  • Add `~/.nodespace/bin` to `$PATH` suggestion in first-run UI so `nodespace` CLI is accessible from the terminal

Acceptance Criteria

  • `nodespaced` binary bundled as Tauri sidecar in `tauri.conf.json`
  • `nodespace` CLI binary bundled as Tauri sidecar in `tauri.conf.json`
  • On first launch, both binaries extracted to `~/.nodespace/bin/`
  • launchd plist written to `~/Library/LaunchAgents/app.nodespace.daemon.plist` on first launch
  • Plist uses correct socket path (`~/.nodespace/daemon.sock`) matching Switch nodespaced IPC transport from TCP to Unix Domain Sockets #1176
  • `launchctl load` called after plist write — daemon starts without requiring logout/login
  • Subsequent launches detect running daemon (check socket exists + gRPC ping) before attempting start
  • Tauri app shows clear error state if daemon is not reachable after 5s timeout
  • `tauri build` succeeds and `.dmg` contains all three binaries
  • CI/CD pipeline builds and signs all three binaries
  • `bun run quality:fix` passes

Technical Specifications

Reference Files

  • `packages/desktop-app/src-tauri/tauri.conf.json` — add `externalBin` entries for sidecars
  • `packages/desktop-app/src-tauri/src/main.rs` — first-launch setup logic
  • `packages/daemon/src/main.rs` — socket path must match plist `NODESPACED_SOCKET` env var (from Switch nodespaced IPC transport from TCP to Unix Domain Sockets #1176)
  • `packages/cli/Cargo.toml` — CLI binary name: `nodespace`

launchd plist template

```xml

Label app.nodespace.daemon ProgramArguments /Users/USERNAME/.nodespace/bin/nodespaced EnvironmentVariables NODESPACED_SOCKET /Users/USERNAME/.nodespace/daemon.sock NODESPACED_DB_PATH /Users/USERNAME/.nodespace/database/nodespace RunAtLoad KeepAlive StandardOutPath /Users/USERNAME/.nodespace/logs/nodespaced.log StandardErrorPath /Users/USERNAME/.nodespace/logs/nodespaced-error.log \`\`\`

Tauri sidecar configuration (`tauri.conf.json`)

```json
{
"tauri": {
"bundle": {
"externalBin": [
"bin/nodespaced",
"bin/nodespace"
]
}
}
}
```

First-launch setup sequence (Tauri `setup` hook)

  1. Check if `~/.nodespace/bin/nodespaced` exists and matches current version
  2. If not: extract sidecar binaries to `~/.nodespace/bin/`, set `chmod +x`
  3. Check if `~/Library/LaunchAgents/app.nodespace.daemon.plist` exists
  4. If not: write plist with resolved home directory paths, call `launchctl load`
  5. Wait up to 5s for `~/.nodespace/daemon.sock` to appear
  6. Ping daemon via gRPC `GetDiagnostics` — show error state if unreachable

CLI PATH guidance

First-run UI shows a one-time notice:

"Add NodeSpace CLI to your terminal: add `~/.nodespace/bin` to your `$PATH`"
With a copy button for the shell export line. No automatic `$PATH` mutation.

Dependencies

Related Issues

Non-Goals

  • Windows installer (separate issue when Windows target is concrete)
  • Homebrew formula (future)
  • Auto-update mechanism (Tauri updater is separate)
  • Remote/multi-user daemon access

Activity

  1. malibio commented on May 19, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 129 passed, 3921 tests

  2. self-assigned this
    on May 19, 2026
  3. malibio commented on May 19, 2026

    @malibio
    CollaboratorAuthor

    Code Review — PR Branch worktree-issue-1179-bundle-nodespaced-launchd

    No PR has been created yet. Posting this review as an issue comment so it is on record before merge.


    Overall Assessment

    This is a well-structured implementation that correctly solves the core problem: registering nodespaced as a launchd user agent so it survives UI window close. The module decomposition (daemon_setup.rs) is clean, the error-handling philosophy (non-fatal with UI emission) is appropriate for a setup hook, and the CI step correctly gates sidecar builds to macOS. There are several issues that need to be addressed before merge — one blocker, two improvements, and a few nits.


    Findings

    [Critical/Blocker]

    daemon_setup.rs has no #[cfg(target_os = "macos")] guard — will fail to compile on Windows

    daemon_setup.rs uses tokio::net::UnixStream, std::os::unix::fs::PermissionsExt, libc::getuid(), and hard-codes Library/LaunchAgents/ — all macOS/Unix-only APIs. The module is declared unconditionally in lib.rs:

    pub mod daemon_setup;  // lib.rs line 28 — no cfg guard

    The Windows build matrix in release.yml will attempt to compile this module. tokio::net::UnixStream is not available on Windows, std::os::unix::fs::PermissionsExt does not exist there, and libc::getuid is not a Windows symbol. This will produce a compile error on the Windows runner.

    Fix: Add #[cfg(target_os = "macos")] (or #[cfg(unix)]) to the module declaration in lib.rs and to all call sites that reference daemon_setup:

    // lib.rs
    #[cfg(target_os = "macos")]
    pub mod daemon_setup;

    And wrap the setup call and the Tauri command registration accordingly.


    [Improvement]

    Committed empty binary placeholders are fragile and will cause signing failures on macOS

    Four empty (0-byte) files are committed to packages/desktop-app/src-tauri/binaries/. Tauri's externalBin bundler copies these files into the .app bundle. Apple's codesign will then attempt to sign the empty files as Mach-O binaries. A 0-byte file is not a valid Mach-O, so notarization will fail at the staple step.

    The CI workflow correctly overwrites these files before tauri build, so a properly-sequenced CI run will work. But the commit itself represents a hazard:

    • A local developer running tauri build without the CI pre-step will embed the empty files, causing an opaque signing failure.
    • A future CI change that reorders steps (e.g. Dependabot bumping tauri-action) could silently re-introduce the bug.

    Recommended fix: Add packages/desktop-app/src-tauri/binaries/nodespace* to .gitignore and add a build.rs check (or a CI pre-check step) that aborts with a helpful message if the files are still empty at build time. The CI workflow already builds the real binaries into that path — they just should not be tracked in git.


    Binary extraction always overwrites on every non-healthy launch; should be version-gated

    The acceptance criterion explicitly states: "check if ~/.nodespace/bin/nodespaced exists and matches current version." The current extract_sidecar unconditionally copies the bundle binary to the destination whenever the socket is not healthy — including on app version upgrades where the daemon crashed for an unrelated reason. Unnecessary binary extraction on every crash restart has two drawbacks:

    1. It overwrites a running binary on disk while launchd may have the old fd open (benign on macOS due to HFS+ semantics, but fragile).
    2. A future Windows or Linux port will not have this guarantee.

    Recommended fix: Before copying, compare the source and destination sizes (cheap) or a SHA-256 digest (correct). Only extract if they differ. This also satisfies the stated acceptance criterion.


    [Nit]

    launchctl load -w is a legacy interface on macOS 10.11+

    Apple deprecated the load/unload subcommands in favour of bootstrap/bootout (macOS 10.11) and formally documented kickstart as the restart mechanism. The current code already uses kickstart for the reload path, which is correct. The initial load call should ideally use:

    launchctl bootstrap gui/501 ~/Library/LaunchAgents/app.nodespace.daemon.plist

    This is a minor robustness concern — load still works on all macOS versions in scope (14.0+), but the deprecation warning in macOS 15 server logs may confuse operators.


    Nit: plist_path.parent().unwrap() in write_plist

    plist_path is always constructed as launch_agents_dir(&home).join(PLIST_FILENAME), so .parent() will never be None. However, .unwrap() is a code smell in production Rust. Replace with .ok_or_else(|| anyhow::anyhow!("plist path has no parent"))?) for consistency with the rest of the error handling in this file.


    Nit: Socket path duplicated across three locations

    The literal .nodespace/daemon.sock / .nodespace/daemon.sock appears independently in:

    • daemon_setup.rs:23 (DAEMON_SOCKET_PATH constant)
    • lib.rs:53 (check_daemon_status command — hardcoded inline)
    • watcher.rs:63-64 (separate resolution helper)

    The constant in daemon_setup.rs is not re-used in lib.rs or watcher.rs. Extract to a shared constants.rs or re-export from daemon_setup so a future socket path change is a one-line edit.


    Acceptance Criteria Status

    Criterion Status
    nodespaced binary bundled as Tauri sidecar PASS
    nodespace CLI binary bundled as Tauri sidecar PASS
    Both binaries extracted to ~/.nodespace/bin/ on first launch PASS
    launchd plist written to ~/Library/LaunchAgents/ on first launch PASS
    Plist uses correct socket path (~/.nodespace/daemon.sock) PASS
    launchctl load called after plist write PASS
    Subsequent launches detect running daemon (socket exists + check) PASS (socket check only — no gRPC ping, which is fine per inline comment)
    Tauri app shows clear error state if daemon not reachable after 5s PARTIAL — backend emits daemon-status event but frontend app-shell.svelte has no listener; the event is silently dropped
    tauri build succeeds and .dmg contains all three binaries UNTESTABLE locally (empty placeholders); CI should pass
    CI/CD pipeline builds and signs all three binaries PASS (macOS); Windows compile guard needed
    bun run quality:fix passes Not verified in this review

    The missing frontend error state ("daemon-status" event emitted but not consumed) means the app will silently proceed to a blank/broken state if the daemon does not come up. The issue spec requires a "clear error state" — this is an incomplete acceptance criterion, but it is lower severity than the Windows compile blocker since macOS is the only target for this release.


    Summary

    Block on: Platform guard for daemon_setup module (Windows compile failure).
    Fix before merge: Empty binary placeholders in git (signing/notarization hazard).
    Nice to have before merge: Version-gated binary extraction; frontend daemon error state.
    Post-merge: Socket path constant deduplication; launchctl bootstrap migration; unwrap cleanup.

  4. added 2 commits that reference this issue on Jun 22, 2026
    7e74880
    f3b3598
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions