Skip to content

Check the running daemon's executable against the app's profile at startup - #3403

Merged
mstomar125 merged 4 commits into
mainfrom
issue-3353-daemon-product-check
Oct 1, 2026
Merged

mstomar125 merged 4 commits into
mainfrom
issue-3353-daemon-product-check

Conversation

@mstomar125

@mstomar125 mstomar125 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Proto: GetDaemonVersionResponse gains string executable_path = 2; (additive; daemons built before it report "").
  • Daemon: get_daemon_version fills it from std::env::current_exe() at run time. It is still the only GetDaemonVersionResponse literal in the workspace.
  • App (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 .exe removed. None gives Unknown, and Some("") gives Mismatch.
    • running_daemon_executable(client: &GrpcClient) -> Option<String> calls GetDaemonVersion with a 2 s timeout. A failure or timeout gives None.
    • boot_out_command() / boot_out_service_registration():
      • macOS runs launchctl bootout gui/<uid>/<launch_agent_label()>.
      • Linux runs systemctl --user stop nodespace.service.
      • It is not run under cfg(test).
    • evict_if_other_product(..) is the testable core. On Mismatch it 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 in ensure_daemon_running. It runs right after the two extract_sidecar_if_changed calls and only when the socket is Healthy.
      • On eviction it skips the binary_updated kill and the healthy early returns, and goes straight to rotate_daemon_logs and registration.
      • Match and Unknown keep today's flow.
      • Windows is skipped.

Deviations from the issue text

  • Path: after the crate split the code is in packages/desktop-app/app-lib, not src-tauri.
  • running_daemon_executable takes &GrpcClient, not &AppHandle. The seam test can then drive it with the harness's client. The startup step looks up the managed client with app.try_state::<GrpcClient>(). If the client is missing, the result is Unknown and nothing changes.
  • The boot-out is two functions. 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.
  • The socket wait is shared. kill_running_daemon_within's wait-then-remove tail is now wait_for_socket_release, which both paths use. It deletes the socket only through remove_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: a brew services daemon 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.
  • Same socket for the probe and the question. The startup step asks through the managed GrpcClient, which dials NODESPACED_SOCKET when it is set. So it is skipped unless the client dials the socket this app registers, the same rule lib.rs follows 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 into default_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.
  • No channel rebuild after an eviction. tonic's lazy channel replaces a dead connection on its next call, which the existing binary-update restart already relies on. That keeps both stop paths the same.
  • Daemon test: a sibling test (get_daemon_version_reports_its_own_executable_path) rather than extending the version test, so each test asserts one thing.
  • Pin gate (SYNC:): ignored under the standing decision for this epic.

Behaviour worth knowing

  • Empty report. An older nodespace-cli daemon 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.
  • A foreign daemon that survives the boot-out costs about 5 s on every launch (for example, an older Homebrew-service daemon that reports ""). The boot-out removes nothing of its, the socket never clears within EVICTION_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.
  • Linux, binary replaced under a running daemon. /proc/self/exe then reads … (deleted), which is a Mismatch. The result is one stop-and-register, the same outcome the binary_updated path 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 against origin/main, and BASELINES is not edited.

  • The one change I had made earlier was tenantWording −1, from rewording the get_daemon_version comment. 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.
  • My first draft of the socket-agreement test called the edition check directly, which added one editionBranching hit. The test now goes through default_socket_path(), a marker-free helper that holds the fallback resolve_socket_path already had (a net-zero move), so the count stays at main's value.
BASELINES (unchanged by this PR):
  proCommands: 275, proSyncModule: 368, proProtocol: 95, proEvents: 81,
  membershipService: 54, editionBranching: 113, cloudBindState: 203,
  cloudSyncHooks: 4, cloudWording: 72, tenantWording: 463, proWording: 281,
  proNamedFiles: 18

Counts, origin/main (066fac40) == this branch:
  proCommands 271, proSyncModule 368, proProtocol 91, proEvents 81,
  membershipService 54, editionBranching 96, cloudBindState 202,
  cloudSyncHooks 0, cloudWording 50, tenantWording 439, proWording 243,
  proNamedFiles 18

✅ No count is above its baseline.

Tests

  • Daemon (node_service.rs): get_daemon_version_reports_its_own_executable_path asserts executable_path == current_exe() of the test process.
  • product_check unit tests (8) cover:
    • the same name, a full path, .exe (bare and full path), and a different name in both directions;
    • an empty string gives Mismatch, and None gives Unknown;
    • only the file name counts;
    • lookalikes (nodespaced.old, nodespaced-extra, xnodespaced, nodespaced.exe.bak, nodespaced (deleted), .exe) are Mismatch.
  • Eviction unit tests (6) use a closure for the service manager and real Unix sockets for the daemons:
    • a match is left alone (no boot-out, socket kept);
    • unknown changes nothing;
    • a mismatched or empty report boots out once and the stale socket is removed;
    • a daemon that survives the boot-out keeps its socket;
    • the macOS boot-out command names gui/<uid>/<launch_agent_label()> (the Linux variant is cfg(target_os = "linux"));
    • without an override, the client's default socket is the socket this app registers, so the same-socket guard does not switch the check off.
  • ADR-048 seam test (tests/it/daemon_executable_check_test.rs) spawns a real nodespaced:
    • the RPC returns a path whose file name is nodespaced;
    • Match for DaemonProfile::community() and Mismatch for a custom-daemon profile;
    • an unreachable socket gives None / Unknown;
    • a socket that accepts but never answers gives None within the 2 s timeout, not a hang.
  • Not run in tests: the real launchctl / systemctl boot-out, which would act on this machine's own service manager. Reviewers should read boot_out_service_registration.

Mutation checks (each must make its target tests fail)

# Mutation Caught by
M1 daemon reports executable_path: String::new() daemon ..._own_executable_path test and the seam test (got "", rebuilt nodespaced)
M2 None → Mismatch a_failed_report_is_unknown, an_unknown_report_changes_nothing, seam unhappy paths
M3 Some("") → Unknown an_empty_report_is_a_mismatch_not_an_unknown, eviction test
M4 no .exe strip an_exe_suffix_is_ignored
M5 whole path compared, not file name a_full_path_matches_on_its_file_name
M6 prefix match (starts_with) lookalike_names_are_a_mismatch
M7 no 2 s RPC timeout seam a_daemon_that_never_answers_is_unknown_after_the_timeout (outer 20 s bound)
M8 no socket wait after boot-out a_mismatched_or_empty_report_boots_out_and_clears_the_socket
M9 unconditional remove_file instead of remove_socket_if_stale a_daemon_that_survives_the_boot_out_keeps_its_socket
M10 hard-coded launchd label boot_out_names_this_builds_launchd_label_in_the_users_gui_domain
M11 mismatch skips the boot-out eviction test
M12 every report treated as a mismatch a_matching_daemon_is_left_alone, an_unknown_report_changes_nothing
M13 daemon_socket_relative() derives the debug variant wrongly without_an_override_the_client_dials_the_socket_this_app_registers
M14 remove_socket_if_stale without its remove_file a_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_removed

  • Failure. It failed a merge gate at assert!(!socket.exists()) under load.
  • Cause. App-lib's unit tests run in one libtest process, and other tests in it spawn subprocesses.
    • A child spawned while the test's listener is open can keep a copy of the listener after the test drops it.
    • On macOS, std's UnixListener::bind sets close-on-exec only after socket() returns, so that child can keep the copy past its exec.
    • connect() then succeeds, and with Duration::ZERO the function returns without deleting.
  • Fix. The test now passes a 5 s grace, the same value its sibling a_socket_that_stops_answering_within_the_grace_is_removed uses.
    • The test's meaning is unchanged: nothing answers, so the file is removed. That happens on the first connect attempt, so the grace costs nothing unless a child still holds the listener.
    • Mutation check: with the remove_file call removed, the test fails, in 0.00 s.
  • Not changed. a_socket_something_answers_on_is_left_alone stays at ZERO.
  • Production call left at ZERO. That is the remove_socket_if_stale(.., Duration::ZERO) call at the end of wait_for_socket_release, which this PR moved out of kill_running_daemon_within.
    • Before that call, the loop polls check_daemon_socket for NotRunning for up to exit_grace (5 s). That poll already absorbs a transient holder.
    • Once NotRunning has been seen, the closed listener cannot come back, because a copy of the fd only spreads from a live holder.
    • If something still answers when the deadline passes, the socket is kept, which is the intended behaviour.

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 head f1acb7fc, on top of 066fac40 (scoped to rust + scripts; rust:test workspace nextest 60 s, test:scripts 35 s). It also passed after each earlier push.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

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)

  • ✅ GetDaemonVersion returns executable_path, and a daemon test asserts it equals current_exe(). The issue asked to extend the existing version test. The PR adds a sibling test instead (get_daemon_version_reports_the_serving_processs_own_executable), which is a sound choice: one assertion per test.
  • ✅ A matching daemon takes the fast path, with no boot-out and no respawn.
    • evict_if_other_product returns false on Match. ensure_daemon_running then falls into the original else if binary_updated / healthy early-return chain unchanged.
    • The only additions are one RPC on a healthy socket, plus up to 2 s if that RPC times out.
  • ✅ A mismatched or empty report boots out the registration and registers the app's own daemon.
    • On evicted, the binary_updated kill and both healthy early returns are skipped. Control goes to rotate_daemon_logs and then registration.
    • The registration path still runs daemon-reload before enable --now on Linux. On macOS it still uses the bootstrap retry ladder.
  • ✅ An RPC failure changes nothing. None gives Unknown, which gives false. The seam tests cover an unreachable socket and a socket that accepts but never answers (bounded by the 2 s timeout).
  • ✅ check-pro-boundary.ts passes. It was re-run on this branch. No count is above its baseline, and tenantWording is 452, matching the PR.
  • ✅ The deviations listed in the PR are sound:
    • &GrpcClient instead of &AppHandle, which makes the RPC helper testable;
    • the pure boot_out_command with a thin runner around it;
    • the shared wait_for_socket_release, which uses remove_socket_if_stale as the issue comment asked;
    • the app-lib path after the crate split.

What was checked and found sound

  • Can a daemon this app installed be falsely classed as Mismatch on a normal launch? No path was found where this happens on every launch.
    • The installed file: it is sidecar_install_path(bin_dir, daemon_binary_name()), where daemon_binary_name() is daemon_profile::active().binary_name. That is the same profile the check compares against.
    • What the daemon reports: the plist's ProgramArguments[0] and the unit's ExecStart both point at that file. It is a real file, written by copy and then rename, not a symlink.
      • On macOS, current_exe() returns the path from _NSGetExecutablePath without canonicalizing it, so the file name is nodespaced.
      • On Linux, /proc/self/exe resolves to the same regular file.
    • Other installs: the .pkg installs /usr/local/bin/nodespaced, and Homebrew uses symlinks named nodespaced. Both match.
    • Linux (deleted) case: this happens only after extract_sidecar_if_changed has replaced the binary, which is the binary_updated restart anyway. It costs one restart.
  • The socket-wait refactor: wait_for_socket_release is the old tail of kill_running_daemon_within, moved verbatim. The kill path behaves the same.
  • The boot-out code:
    • launchctl bootout gui/<uid>/<launch_agent_label()> is the correct service-target form. get_uid is gated to macOS, matching the call.
    • systemctl --user stop nodespace.service is correct, and a stop requested through systemd does not trigger Restart=.
    • Under cfg(test) only the log line remains. No integration test reaches ensure_daemon_running.
  • GrpcClient::reconnect() after eviction: correct and harmless.
    • The watcher, token stream and probe all capture the client after ensure_daemon_running returns.
    • The client id and database routing are preserved across the rebuild.
  • Windows compile:
    • The shared items (ProductCheck, product_check, running_daemon_executable, PRODUCT_CHECK_TIMEOUT) are used, so none is dead on Windows.
    • Everything that touches the service manager or the socket file is cfg(unix).
    • #[cfg(not(unix))] let evicted = false; keeps the chain intact.
    • The eviction tests are cfg(all(test, unix)).
  • Project rules: no issue numbers, no product wording, no lint suppression and no dead_code allowances in the added lines.

Code Review Findings

🟢 Suggestion: the health probe and the question can target two different sockets
📁 packages/desktop-app/app-lib/src/daemon_setup.rs:721-746

  • The problem:
    • evict_other_product_daemon gates on check_daemon_socket(socket_path). That is home.join(daemon_socket_relative()), the default socket, and it ignores the override.
    • It then asks the managed GrpcClient, which dials resolve_socket_path() and does honour NODESPACED_SOCKET.
    • Elsewhere the codebase guards exactly this pattern on purpose (lib.rs:118 and lib.rs:707: "Probe the SAME socket the gRPC client dials").
  • The effect: with an override pointing at a differently named daemon, the app would boot out and restart its own registered default daemon on every launch, because of another daemon's answer.
  • Why it is not a blocker: it needs an env override plus a differently named daemon, which is rare and dev-only.
  • Cheap fix: treat the check as Unknown when resolve_socket_path() != socket_path.
  • Principle: check and act on the same resource.

🟢 Suggestion: a surviving daemon costs the full 5 s grace on every launch
📁 packages/desktop-app/app-lib/src/daemon_setup.rs:688-711

  • The scenario: an older-formula Homebrew daemon that reports "", or any foreign daemon outside the app's registration.
  • What each launch then does:
    • runs the boot-out, which removes nothing useful;
    • waits the full EVICTION_EXIT_GRACE, because the socket never clears;
    • bootstraps a daemon that exits on the lock.
  • The cost: every launch shows "starting" about 5 s longer until the foreign daemon goes away.
  • What to do: this is inherent to the design, since a survivor cannot be told apart from a daemon that is slow to exit without waiting. Worth one line under "Behaviour worth knowing" in the PR.

🟢 Nit: the reconnect is applied to one stop path but not the other
📁 packages/desktop-app/app-lib/src/daemon_setup.rs:716-745

  • The asymmetry: the check now dials the lazy channel on every healthy launch. So the path where the binary was updated and the daemon matched also stops a daemon the channel is connected to, without a reconnect().
  • Both paths work today: tonic's channel re-dials on the next call by itself, so the doc line "so it is rebuilt to dial whatever answers next" overstates necessity.
  • Fix: either reconnect after both stop paths, or soften the comment.

🟢 Nit: typo in a test name
📁 packages/daemon/src/services/node_service.rs:4309

  • get_daemon_version_reports_the_serving_processs_own_executable has three s's in "processs".

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.

@mstomar125
mstomar125 force-pushed the issue-3353-daemon-product-check branch 2 times, most recently from 8439525 to 6ea487e Compare October 1, 2026 07:21
@mstomar125

Copy link
Copy Markdown
Contributor Author

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

  1. 🟢 The probe and the question could hit different sockets (daemon_setup.rs, evict_other_product_daemon). Verified: the probe used home.join(daemon_socket_relative()), while the managed client dials resolve_socket_path(), which honours NODESPACED_SOCKET.
    • Fix: the step now returns early, as no check, unless the client dials the socket this app registers. This is the same rule lib.rs follows for its status probes.
    • Supporting change: resolve_socket_path's fallback moves into a new default_socket_path() (grpc_client.rs, a net-zero move of the existing line). It reads no environment.
    • New test: without_an_override_the_client_dials_the_socket_this_app_registers pins that the two paths agree, so the guard cannot silently switch the check off. Mutation: deriving the debug variant wrongly in daemon_socket_relative() makes it fail.
    • No unit test exercises the guard line itself. It is a path-equality early return in glue code that needs a Wry AppHandle and the process-global env var, so review covers it.
  2. 🟢 Nit: reconnect on only one stop path. I dropped the eviction path's GrpcClient::reconnect() rather than softening its comment. tonic's lazy channel replaces a dead connection in poll_ready on its next call, which the binary-update restart path already relies on, so both stop paths now behave the same. The doc comment says so.
  3. 🟢 Nit: typo. The test is renamed to get_daemon_version_reports_its_own_executable_path.

📝 Documented

  1. 🟢 A surviving foreign daemon costs about 5 s on every launch. This is now under "Behaviour worth knowing" in the PR body: it is inherent, it recurs until that daemon is gone, and the user notice planned in Tell the user when another NodeSpace product's daemon is running or registered #3356 covers it.

Also in this round

  • Coordinator request: de-flake stale_socket_removal_tests::a_socket_nothing_answers_on_is_removed (commit "Give the stale-socket removal test a grace for transient holders").
    • Cause: confirmed. Unit tests in the same process spawn subprocesses, and on macOS std sets close-on-exec only after socket(), so a child can keep the dropped listener alive. With Duration::ZERO, one successful connect() left the file in place.
    • Fix: the test now uses a 5 s grace. It costs nothing when nothing answers.
    • Mutation: removing remove_file still fails the test.
    • Left as is: a_socket_something_answers_on_is_left_alone stays at ZERO. So does the production ZERO call at the end of wait_for_socket_release, because the NotRunning poll before it already absorbs a transient holder (reasoning in the PR body).
  • Rebased onto 066fac40.
    • One conflict, in the get_daemon_version comment, which Describe the access gate and daemon seams without naming the Pro daemon #3401 had already reworded on main. It is resolved to main's wording plus the executable sentence.
    • The ratchet now shows no delta against main.
    • A first draft of the new socket test added one editionBranching hit. I caught it with --changed and removed it with the default_socket_path() helper.

Verification

  • cargo fmt for the 3 crates: 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 on the final branch: passed (rust + scripts tiers).
  • Mutation pass: 14 of 14 mutations caught (table in the PR body).

Re-Review Decision

Decision: 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.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Automated pragmatic-code-review (medium) — re-review

Review Type: Re-Review. Scope is 9ffcdf74 (conflict resolution only), a03a629e and 6ea487e2, at HEAD 6ea487e2 on origin/main 066fac40.

Previous Review Summary

  • Previous recommendations: 4, all 🟢.
  • Addressed: 4. Three were fixed in code, and the survivor cost is now under "Behaviour worth knowing" in the PR body.
  • Not addressed: 0.
  • New issues found: 0 blocking, and 1 optional Nit.

Verification

  1. Without NODESPACED_SOCKET, the guard passes.
    • Both paths are dirs::home_dir() joined with nodespace_proto::socket::daemon_socket_relative(cfg!(debug_assertions), is_pro_build()), so they are equal PathBufs.
    • The /tmp fallback cannot apply, because ensure_daemon_running already returns an error without a home directory.
    • An override naming the default path is still equal, so the check runs.
    • A mismatch could only skip the check, which is the safe direction.
    • The new test pins that the two builders agree. The guard line itself is a trivial early return, and I read it.
  2. Dropping reconnect() is safe.
    • tonic's lazy Channel has a Reconnect service that dials again when poll_ready finds the connection closed.
    • The next call comes after boot-out, registration and wait_for_daemon_or_refusal.
    • In the survivor case the connection still points at a live daemon.
    • This is the same behaviour the binary_updated restart already relies on.
  3. No Pro, edition or tenant wording, and no #NNNN.
    • default_socket_path()'s is_pro_build() call is a moved context line, not a new one.
    • The ratchet on this branch and on 066fac40 matches on all 12 counts: zero delta.
    • The conflict resolution keeps main's "not database-scoped" wording.
  4. Nothing is newly broken.
    • default_socket_path is cfg(unix) pub(crate), and Windows keeps its own resolver.
    • The new test is in a cfg(all(test, unix)) module.
    • The PathBuf != &Path comparison uses the standard PartialEq impl.

The de-flake (a03a629e)

  • The diagnosis is correct. On Apple targets std creates the socket without SOCK_CLOEXEC and sets close-on-exec afterwards. A concurrent Command::spawn (posix_spawn, without POSIX_SPAWN_CLOEXEC_DEFAULT) inherits the descriptor and keeps the listener alive until that child exits.
  • The 5 s grace is a sound bound for the short-lived children app-lib unit tests spawn. It is not a timing assertion.
  • The production ZERO call at the end of wait_for_socket_release is sound. The NotRunning poll before it is the grace, and a respawn that rebinds in between is left alone. The same reasoning covers a_mismatched_or_empty_report_boots_out_and_clears_the_socket.

Code Review Findings

🟢 Nit: the skip is silent
📁 packages/desktop-app/app-lib/src/daemon_setup.rs:729-731

  • When the client dials another socket, the guard returns false with no log, while every other branch of this step logs.
  • A one-line tracing::debug! or info! naming both paths would explain why the check didn't run in an override setup.

Recommendation: APPROVE

@mstomar125

Copy link
Copy Markdown
Contributor Author

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

  • 🟢 Nit: the skip is silent (daemon_setup.rs, evict_other_product_daemon). The same-socket early return now logs at info with both paths (dialed, registered), matching the other branches of the step, which all log. This is commit f1acb7fc.

⏭️ Skipped

  • None.

Verification

  • cargo clippy -p nodespace-app-lib --all-targets -- -D warnings -D clippy::unused-async: clean.
  • product_ unit tests: 14 of 14 passed.
  • The ratchet shows no delta against origin/main 066fac40.
  • bun run test:changed on f1acb7fc: passed.

Re-Review Decision

Decision: 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.

mstomar125 and others added 4 commits October 1, 2026 09:44
…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]>
@mstomar125
mstomar125 force-pushed the issue-3353-daemon-product-check branch from f1acb7f to 978d76f Compare October 1, 2026 07:44
@mstomar125
mstomar125 merged commit 86b7190 into main Oct 1, 2026
@mstomar125
mstomar125 deleted the issue-3353-daemon-product-check branch October 1, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant