Repository navigation
Check the running daemon's executable against the app's profile at startup - #3403
Conversation
Automated pragmatic-code-review (medium)Review Type: Initial Review (covers commit 938aa9a; the follow-up commit 8b94f9e, a test-only de-flake, is covered by the re-review) Requirements Check (issue #3353)
What was checked and found sound
Code Review Findings 🟢 Suggestion: the health probe and the question can target two different sockets
🟢 Suggestion: a surviving daemon costs the full 5 s grace on every launch
🟢 Nit: the reconnect is applied to one stop path but not the other
🟢 Nit: typo in a test name
Recommendation: APPROVE The change is small, follows the issue closely, and is well isolated: the product check is pure, the service manager is injected, and the socket handling reuses the existing helper. Eviction cannot be triggered by a failed RPC. No blockers; all four findings are optional, the most worthwhile being the socket-consistency guard. |
8439525 to
6ea487e
Compare
Address-review summary (round 1)The review recommended APPROVE with four optional findings. Three were addressed, one was documented, and none was skipped. There was also one coordinator request and one rebase. ✅ Addressed
📝 Documented
Also in this round
Verification
Re-Review DecisionDecision: RE-REVIEW NEEDED Rationale: the round adds new logic (the same-socket guard and its helper), removes the reconnect, and changes a pre-existing test. The new commits since the first review should be checked. |
Automated pragmatic-code-review (medium) — re-reviewReview Type: Re-Review. Scope is Previous Review Summary
Verification
The de-flake (
Code Review Findings 🟢 Nit: the skip is silent
Recommendation: APPROVE |
Address-review summary (round 2)The re-review recommended APPROVE. All 4 earlier findings were confirmed resolved, and there was 1 new optional Nit. ✅ Addressed
⏭️ Skipped
Verification
Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: the only change is one log statement on an early-return path the re-review already verified. There is no logic change. |
…artup GetDaemonVersionResponse gains executable_path, which the daemon fills from its own current_exe() at run time; daemons built before the field report an empty string. On Unix, ensure_daemon_running asks a healthy daemon for that path through the managed GrpcClient with a 2 s timeout, and compares its file name (any .exe removed) with the active DaemonProfile's binary_name. A mismatch, or an empty report, boots out this build's service registration (launchctl bootout on macOS, systemctl --user stop on Linux), waits up to 5 s for the socket to clear, removes the socket file only if nothing answers on it, rebuilds the gRPC channel and goes straight to registration. A failed or timed-out RPC leaves today's flow unchanged. Windows is skipped. The socket-release wait is factored out of kill_running_daemon_within so both paths share remove_socket_if_stale. Co-Authored-By: Claude Opus 5.5 <[email protected]>
a_socket_nothing_answers_on_is_removed passed Duration::ZERO, so a single successful connect left the file in place. App-lib's unit tests share one process with tests that spawn subprocesses, and a child spawned while the test's listener was open can hold a copy of it briefly after the drop (on macOS std sets close-on-exec only after socket() returns), which made the assertion fail under load. A 5 s grace absorbs such a holder; a socket nothing answers on is still removed on the first connect attempt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The check probed the socket this app registers but asked its question through the managed GrpcClient, which dials NODESPACED_SOCKET when that is set. With an override, another daemon's answer could boot out this app's own registration. evict_other_product_daemon now returns early unless the client dials the registered socket. resolve_socket_path's fallback moves into default_socket_path(), which reads no environment, so a test can pin that without an override the two paths are the same and the check still runs on a normal launch. The channel rebuild after an eviction is dropped: tonic's lazy channel dials again on its next call, as it already does after the binary-update restart. Renames get_daemon_version's executable test (typo in its name). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every other branch of the startup check logs its outcome; the early return for a client that dials another socket now does too, naming both paths. Co-Authored-By: Claude Opus 5.5 <[email protected]>
f1acb7f to
978d76f
Compare
Closes #3353
Summary
The installed app now decides which daemon runs: at startup it asks the daemon answering on the socket which executable it runs, and evicts it when that is not the active
DaemonProfile's daemon binary.GetDaemonVersionResponsegainsstring executable_path = 2;(additive; daemons built before it report"").get_daemon_versionfills it fromstd::env::current_exe()at run time. It is still the onlyGetDaemonVersionResponseliteral in the workspace.packages/desktop-app/app-lib/src/daemon_setup.rs):product_check(reported: Option<&str>, profile: &DaemonProfile) -> ProductCheck(Match/Mismatch/Unknown). It compares the file name with one trailing.exeremoved.NonegivesUnknown, andSome("")givesMismatch.running_daemon_executable(client: &GrpcClient) -> Option<String>callsGetDaemonVersionwith a 2 s timeout. A failure or timeout givesNone.boot_out_command()/boot_out_service_registration():launchctl bootout gui/<uid>/<launch_agent_label()>.systemctl --user stop nodespace.service.cfg(test).evict_if_other_product(..)is the testable core. OnMismatchit boots out the registration, waits up to 5 s for the socket to clear, then removes the file only if nothing answers on it (remove_socket_if_stale).evict_other_product_daemon(app, socket)is the Unix-only startup step inensure_daemon_running. It runs right after the twoextract_sidecar_if_changedcalls and only when the socket isHealthy.binary_updatedkill and the healthy early returns, and goes straight torotate_daemon_logsand registration.MatchandUnknownkeep today's flow.Deviations from the issue text
packages/desktop-app/app-lib, notsrc-tauri.running_daemon_executabletakes&GrpcClient, not&AppHandle. The seam test can then drive it with the harness's client. The startup step looks up the managed client withapp.try_state::<GrpcClient>(). If the client is missing, the result isUnknownand nothing changes.boot_out_command()is pure and pinned by a test.boot_out_service_registration()runs it. This keeps the part that touches launchd or systemd small enough to read.kill_running_daemon_within's wait-then-remove tail is nowwait_for_socket_release, which both paths use. It deletes the socket only throughremove_socket_if_stale, as Add a single-instance daemon lock and export the launcher's argument list #3352's comment asks. A daemon that survives the boot-out keeps its socket: abrew servicesdaemon or one started by hand is not in the app's registration. The app's re-registered daemon then exits on the single-instance lock.GrpcClient, which dialsNODESPACED_SOCKETwhen it is set. So it is skipped unless the client dials the socket this app registers, the same rulelib.rsfollows for its daemon-status probes. Without the guard, an override pointing at another daemon would make that daemon's answer boot out this app's own registration.resolve_socket_path's fallback moves intodefault_socket_path(), which reads no environment, so a test can pin that without an override the two paths are identical, so the check does run on a normal launch.get_daemon_version_reports_its_own_executable_path) rather than extending the version test, so each test asserts one thing.SYNC:): ignored under the standing decision for this epic.Behaviour worth knowing
nodespace-clidaemon reports""and is treated as another product. As the issue intends, the app re-registers its own daemon, which exits on the lock, and the app keeps using the Homebrew daemon.""). The boot-out removes nothing of its, the socket never clears withinEVICTION_EXIT_GRACE, and the app's own daemon then exits on the lock. Without that wait, a daemon that survives cannot be told apart from one that is slow to exit. The cost recurs until that daemon is gone, which is what the user notice planned in Tell the user when another NodeSpace product's daemon is running or registered #3356 is for./proc/self/exethen reads… (deleted), which is aMismatch. The result is one stop-and-register, the same outcome thebinary_updatedpath already has, and the restarted daemon then reports a clean path.Ratchet (
bun run scripts/check-pro-boundary.ts)Passes. After the rebase onto
066fac40, the branch adds no delta at all againstorigin/main, and BASELINES is not edited.tenantWording−1, from rewording theget_daemon_versioncomment. Describe the access gate and daemon seams without naming the Pro daemon #3401 made the same rewording on main, so it is no longer part of this diff.editionBranchinghit. The test now goes throughdefault_socket_path(), a marker-free helper that holds the fallbackresolve_socket_pathalready had (a net-zero move), so the count stays at main's value.Tests
node_service.rs):get_daemon_version_reports_its_own_executable_pathassertsexecutable_path == current_exe()of the test process.product_checkunit tests (8) cover:.exe(bare and full path), and a different name in both directions;Mismatch, andNonegivesUnknown;nodespaced.old,nodespaced-extra,xnodespaced,nodespaced.exe.bak,nodespaced (deleted),.exe) areMismatch.gui/<uid>/<launch_agent_label()>(the Linux variant iscfg(target_os = "linux"));tests/it/daemon_executable_check_test.rs) spawns a realnodespaced:nodespaced;MatchforDaemonProfile::community()andMismatchfor acustom-daemonprofile;None/Unknown;Nonewithin the 2 s timeout, not a hang.launchctl/systemctlboot-out, which would act on this machine's own service manager. Reviewers should readboot_out_service_registration.Mutation checks (each must make its target tests fail)
executable_path: String::new()..._own_executable_pathtest and the seam test (got "", rebuiltnodespaced)None→Mismatcha_failed_report_is_unknown,an_unknown_report_changes_nothing, seam unhappy pathsSome("")→Unknownan_empty_report_is_a_mismatch_not_an_unknown, eviction test.exestripan_exe_suffix_is_ignoreda_full_path_matches_on_its_file_namestarts_with)lookalike_names_are_a_mismatcha_daemon_that_never_answers_is_unknown_after_the_timeout(outer 20 s bound)a_mismatched_or_empty_report_boots_out_and_clears_the_socketremove_fileinstead ofremove_socket_if_stalea_daemon_that_survives_the_boot_out_keeps_its_socketboot_out_names_this_builds_launchd_label_in_the_users_gui_domaina_matching_daemon_is_left_alone,an_unknown_report_changes_nothingdaemon_socket_relative()derives the debug variant wronglywithout_an_override_the_client_dials_the_socket_this_app_registersremove_socket_if_stalewithout itsremove_filea_socket_nothing_answers_on_is_removed(with the new 5 s grace)All 14 fail their target tests; all restored.
Also in this PR: de-flaking
a_socket_nothing_answers_on_is_removedassert!(!socket.exists())under load.UnixListener::bindsets close-on-exec only aftersocket()returns, so that child can keep the copy past its exec.connect()then succeeds, and withDuration::ZEROthe function returns without deleting.a_socket_that_stops_answering_within_the_grace_is_removeduses.remove_filecall removed, the test fails, in 0.00 s.a_socket_something_answers_on_is_left_alonestays at ZERO.remove_socket_if_stale(.., Duration::ZERO)call at the end ofwait_for_socket_release, which this PR moved out ofkill_running_daemon_within.check_daemon_socketforNotRunningfor up toexit_grace(5 s). That poll already absorbs a transient holder.NotRunninghas been seen, the closed listener cannot come back, because a copy of the fd only spreads from a live holder.Checks
cargo fmt -p nodespace-proto -p nodespace-daemon -p nodespace-app-lib: no changes.cargo clippy -p nodespace-proto -p nodespace-daemon -p nodespace-app-lib --all-targets -- -D warnings -D clippy::unused-async: clean.bun run test:changed: passed on the final headf1acb7fc, on top of066fac40(scoped to rust + scripts;rust:testworkspace nextest 60 s,test:scripts35 s). It also passed after each earlier push.🤖 Generated with Claude Code