Skip to content

Check the running daemon's executable against the app's DaemonProfile at startup #3353

Closed

Description

@mstomar125

Summary

Core's side of ADR-084 §4.3 (proposed): the installed app decides which daemon runs.

  1. The daemon reports its executable. GetDaemonVersionResponse gains string executable_path = 2;. NodeServiceImpl::get_daemon_version fills it at run time from the process's own std::env::current_exe().
    • The Pro daemon serves core's GetDaemonVersion through core's router, so it reports its own path with no Pro code in core.
    • A daemon built before this change reports an empty string.
  2. The app compares that executable with its profile. In ensure_daemon_running, once the sidecar is extracted and the socket answers, the app asks the running daemon for executable_path. It compares the path's file name, without any .exe, with daemon_profile::active().binary_name.
    • Match: use the running daemon, as today.
    • Mismatch, including an empty value: boot out the app's service registration, wait for the socket to clear, and continue into the existing register path. To boot it out:
      • on macOS, run launchctl bootout gui/<uid>/<launch_agent_label()>;
      • on Linux, run systemctl --user stop nodespace.service.
    • The RPC fails or times out: the result is unknown. Log it and keep today's behaviour.
  3. Windows is skipped. Windows has no second product (ADR-084 §8) and no label to boot out.

Context

  • Why the app needs this. Under the shared identity (Delete the in-core Pro daemon profile, NODESPACE_PRO_* switch and tauri.pro.conf.json #3354), both products register app.nodespace.daemon on daemon.sock. After a hand replacement (core's .dmg dragged over Pro), or with a stale registration, the fast path would use the other product's daemon.
  • Why a bootout. The existing kill path signals only the app's own installed binary (process_argv0_matches). Evicting another product's daemon needs the bootout.
  • The check is generic. It runs in the app and compares only against the app's own profile.
  • GetDaemonVersion today:
    • proto: node_service.proto 716-721;
    • daemon: services/node_service.rs 1353-1361, with its test at ~4291;
    • app: commands/database.rs 18-35. That command still returns the version string, and the frontend's version badge uses it.
  • Which client to call it with. The app's managed GrpcClient exists before the startup task runs (lib.rs ~466). Use it with a 2 s timeout.
  • Why the pin gate. Suppose a Pro build from core HEAD talks to a pinned Pro daemon that lacks the field. It would see an empty value, evict its own daemon at every launch, and pay about 9 s of model load each time. With one pin, the Pro daemon at the same revision fills the field.
  • Why Add a single-instance daemon lock and export the launcher's argument list #3352 comes first. After the eviction and re-registration, a daemon outside the registration may still hold the socket, for example an older brew services daemon. The app's own daemon must then exit on the lock rather than fight for the socket. Tell the user when another NodeSpace product's daemon is running or registered #3356 tells the user.
  • An intended change for the free app. A running daemon from an older nodespace-cli formula reports an empty path, so it counts as another product. The app re-registers its own daemon, which exits on the lock, and the app keeps using the Homebrew daemon until the formula updates.

Scope

  • packages/proto/proto/node_service.proto: add the field with this comment: "the serving process's own executable path, for the app's product check; empty from daemons built before this field existed".
  • packages/daemon/src/services/node_service.rs get_daemon_version:
    • Set executable_path to std::env::current_exe().map(|p| p.to_string_lossy().into_owned()).unwrap_or_default().
    • This is the only GetDaemonVersionResponse struct literal in the workspace.
  • packages/desktop-app/src-tauri/src/daemon_setup.rs:
    • A pure fn product_check(reported: Option<&str>, profile: &DaemonProfile) -> ProductCheck, where ProductCheck is Match, Mismatch or Unknown:
      • None (the RPC failed) gives Unknown;
      • Some("") gives Mismatch;
      • otherwise, compare the file stem, with any .exe stripped.
    • async fn running_daemon_executable(app: &AppHandle) -> Option<String>, which calls GetDaemonVersion through the managed GrpcClient with a 2 s timeout.
    • fn boot_out_service_registration(), with the macOS and Linux bodies above. Keep it small, so the reviewer can read it.
    • Wiring in ensure_daemon_running (unix only):
      1. Right after the two extract_sidecar_if_changed calls, if check_daemon_socket reports Healthy, run the check.
      2. On Mismatch:
        • log both names;
        • call boot_out_service_registration();
        • wait up to 5 s for NotRunning, as kill_running_daemon does, then remove a stale socket file;
        • skip the binary_updated kill and the healthy early returns, and go straight to rotate_daemon_logs and registration.
      3. Match and Unknown keep today's flow.
  • Docs: comments name no product.

Out of scope

Steps

  1. Run the startup sequence, and assign the issue at pickup. Confirm the pin gate is met.
  2. Add the proto field, the daemon code and the daemon test.
  3. Add the pure check and its tests, the RPC helper, and the bootout.
  4. Wire the check into ensure_daemon_running.
  5. Run bun run scripts/check-pro-boundary.ts and paste BASELINES.
  6. Run bun run test:changed and bun run quality:fix, push, and open the PR. Code comments must not cite GitHub issue numbers.

Acceptance criteria

  • GetDaemonVersion returns executable_path, and the daemon test asserts that it equals the test process's current_exe().
  • When the daemon matches, startup takes today's fast path: no bootout and no respawn.
  • When the report is mismatched or empty, the app boots out its registration and registers its own daemon.
  • An RPC failure changes nothing.
  • bun run scripts/check-pro-boundary.ts passes, with BASELINES pasted. No change is expected.

Tests and verification

  • Unit tests for product_check: the same name, a full path, a .exe suffix, a different name, an empty string, and None.
  • Daemon unit test: extend get_daemon_version_reports_the_daemon_crate_version.
  • ADR-048 seam test. The test-support harness spawns a real nodespaced. Assert that:
    • the RPC returns a path whose file name is nodespaced;
    • product_check gives Match for DaemonProfile::community();
    • product_check gives Mismatch for a profile named custom-daemon.
  • The bootout is not run in tests, because it would touch the real launchd. The reviewer reads it instead.
  • Commands:
    • bun run test:changed
    • cargo clippy -p nodespace-proto -p nodespace-daemon -p nodespace-app --all-targets -- -D warnings -D clippy::unused-async
  • Optional manual check on a dev Mac:
    1. Start a debug build, and confirm the daemon is not respawned.
    2. Stop the app, and point the dev plist at a differently named copy of the daemon binary.
    3. Start the app again. It re-registers nodespaced.

Dependencies

Risks and rollback

  • A false mismatch makes the app restart the daemon at every launch. The Match test and the manual check guard against it.
  • Rollback: revert the PR. The proto field is additive.

Plan key: C8.10 (pro-boundary DAG).

🤖 Generated with Claude Code

Activity

  1. added
    pro-boundary
    on Sep 30, 2026
  2. self-assigned this
    on Sep 30, 2026
  3. mstomar125 commented on Sep 30, 2026

    @mstomar125
    ContributorAuthor

    Heads-up from the #3352 work (PR #3388, not merged yet): it adds remove_socket_if_stale(socket_path, grace) in packages/desktop-app/app-lib/src/daemon_setup.rs. It deletes the daemon socket file only once nothing accepts connections on it, and kill_running_daemon / kill_stale_daemon_sync now use it. With the single-instance lock, deleting the socket of a daemon that is still serving (a brew services daemon, one started by hand) leaves it alive, holding the lock and unreachable, and the app's replacement daemon exits 0 without serving. The step here that removes a stale socket file after waiting for NotRunning should use the same helper rather than an unconditional remove_file. Staleness is decided by connecting, not by probing the lock, because a lock probe makes a daemon that starts at that moment see the lock held and exit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

pro-boundary

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions