Skip to content

Hold the app's daemon calls until the startup product check is over (held for design discussion) - #3639

Merged
malibio merged 1 commit into
mainfrom
issue-3623-product-check-ordering
Oct 6, 2026
Merged

malibio merged 1 commit into
mainfrom
issue-3623-product-check-ordering

Conversation

@mstomar125

@mstomar125 mstomar125 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3623

At startup, the frontend's first calls can reach whichever daemon holds daemon.sock before the launcher's product check (ADR-084 §4.3) has booted out another product's daemon. With this PR the app holds every call on its shared gRPC channel until the daemon that answers has passed that check. The docs PR records the decision and compares the placements.

How it works

  • The hold lives in the shared channel's connector. While held, the connector does not dial, so nothing on the channel reaches any daemon: core's commands, the watcher, the token stream, and extensions through GrpcClient::channel(). The product check asks on a one-shot connection of its own. The guarantee covers the app's own channel only; the CLI, the skill and agent sessions dial the socket themselves.
  • Held calls queue. They fail with UNAVAILABLE only once the hold passes STARTUP_HOLD_LIMIT, 2 minutes from the client's creation, a chosen bound. After that, calls fail at once until the hold ends.
  • The hold ends only at the end of a start attempt. start_attempt runs the launcher's steps, then waits up to 30 s for a daemon on the dialed socket, asking it every 250 ms which executable it runs:
    • this app's binary, or nothing on the socket: the hold ends;
    • another binary: the hold stays on and the status is other_daemon;
    • no answer to the question: the hold stays on and the status is starting. The wait running out never ends the hold.
  • The first step only evicts. evict_other_product_daemon boots out another product's daemon and never touches the hold, so there is no warm-launch early release.
  • Retry runs a new start attempt. Both Retry buttons (not-running banner, other-daemon notice) call retry_daemon_start, so an overdue hold is recoverable. Outside Tauri, where there is no daemon to start, Retry re-reads the status.
  • Every start goes through it. Startup, Retry and reset_incompatible_database all reach bring_up_daemon only through start_attempt.
  • Status and probe. check_daemon_status reports starting while holding and daemon_down_status once overdue. probe_and_recover does nothing while held.
  • Crate-private. The hold API is pub(crate), so an extension cannot end it.
  • A failed start while another product's daemon answers reports that daemon rather than the error.

What changed

Where Change
services/startup_hold.rs (new) StartupHold, a latch shared by a client and its connector: held, released, or overdue (derived). wait() queues and fails only past the limit.
services/grpc_client.rs The lazy channel's connector awaits the hold (UDS and named pipe). connect_lazy_held() builds the app's own client; dial_once() gives a one-shot connection outside the hold (on Windows it retries while the pipe is busy). connect() and connect_lazy() build released clients. reconnect() keeps the hold.
daemon_setup.rs start_attempt, answering_daemon, start_outcome; ensure_daemon_running goes through them. start_daemon_and_report reports crate::daemon_status, so the event and the poll agree.
lib.rs, coexistence.rs, incompatible_database.rs Held client at setup; daemon_status wraps status_unless_other_daemon; the reset's restart goes through start_daemon_and_report.
commands/nodes.rs probe_and_recover returns false without probing while held.
app-shell.svelte, daemon-status.ts Retry starts the daemon again, with a busy state.
packages/core/src/extensions.rs, behaviors/mod.rs, packages/daemon/src/services/extensions.rs Comments no longer frame a change as an extension API version.

Tests

startup_ordering_tests.rs (22 tests) serves in-process stand-in daemons on a temporary Unix socket and drives the real get_node and list_databases commands on a mock app. No wall-clock assertions: paused time or explicit signalling. Two wiring tests read source because the real launcher cannot run in tests. A new frontend test covers the banner's Retry, and a service test covers the non-Tauri fallback.

Each production change was mutation-checked (the fix removed, at least one test fails): release at attempt return, an unanswered check passing, no re-ask, an overdue hold not released, held calls failing at once, a failed start waiting out the wait, a failed start beside another daemon reporting the error, the launcher outside the attempt, nothing-answering keeping the hold, and the Retry button reverted.

  • nextest run -p nodespace-app-lib: 427 passed, 1 skipped. bun run test:changed, quality:fix and clippy -D warnings: clean.
  • Not compiled here: Windows. Every cfg(windows) arm was read against its unix counterpart; only the darwin target is installed.
  • Known limit: start attempts do not exclude one another, so a start step with no timeout that hangs also holds up Retry.

Docs: nodespace-docs #112 (ADR-084 §4.3, Daemon Lifecycle).

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Code review — round 1 (pragmatic-code-reviewer, medium depth)

Code Review Summary

PR #3639: hold the app's daemon calls until the startup product check is over. A sound change that leaves the code healthier than before. The hold sits in the shared channel's connector, so every caller on the channel waits: core commands, the watcher, the token stream, and extensions through channel(). Putting it there needs no type changes and closes the window the issue describes. Everything below was checked by reading the code only; nothing was built or run.

tonic 0.12.3 behaviour (checked in the registry source)

  • connect_with_connector_lazy with no connect_timeout gives a channel built as Buffer(1024) over Reconnect { is_lazy: true }. While the connector future waits on the hold, Reconnect::poll_ready stays in Connecting, so requests queue in the buffer. On release, one connection is dialed and every queued request goes out on it over HTTP/2.
  • After the deadline, the lazy Reconnect stores the connector error, returns it for one call, and goes back to Idle. The buffer worker takes the next request, which starts a new connector call. That call's wait() fails on its first poll, since timeout_at has already elapsed (at most one timer tick). Queued calls therefore fail one after another, each almost at once; none waits out another period.
  • release() uses send_replace, so it works with no receivers. wait_for checks the current value first, so a release cannot be missed.
  • Nothing in the start attempt uses the managed client. check_daemon_socket is a raw connect, the product check goes through dial_once, and no guard or lock is held across an RPC. No deadlock path found.

Findings

Critical Issues

None.

Suggested Improvements

  • [Improvement] lib.rs: no test covers the line that turns the feature on. If app.manage(GrpcClient::connect_lazy_held()) went back to connect_lazy(), the suite would stay green. The same is true if connect_lazy_held() built its client with StartupHold::released(). Two cheap fixes: a test that connect_lazy_held() reports Holding, and a source-text check on the app.manage(...) line.
  • [Improvement] release_hold_after and the docs: the hold lasts the whole start attempt, not just the check, so every warm launch gets slower.
    • With this app's daemon already running, the check returns Match at once. The boot calls still wait for create_dir_all and both extract_sidecar_if_changed calls, and on macOS the latter spawn codesign --verify --strict and the quarantine checks.
    • The docs line "The hold is usually short: the check runs as soon as the bundled model is in place" is inaccurate.
    • For the design discussion: release as soon as the check keeps the running daemon, and hold through the whole attempt only otherwise.
  • [Improvement] Interaction with Install coexistence checks and other-product notices (ADR-084 §4.3, §5) #3606.
    • (a) Its start_daemon_and_report emits daemon-status itself. Release between the attempt and the emit, so healthy is never pushed while check_daemon_status still says starting. Doing it there also gives Reset and Retry their release.
    • (b) The survivor row needs a refused transition on StartupHold. daemon_status_of would also hide other_daemon behind starting. Either shape the latch for this now, or note it as Install coexistence checks and other-product notices (ADR-084 §4.3, §5) #3606's job.

Nitpicks

  • Nit: the held client is managed under cfg(any(unix, windows)) but released only under cfg(any(target_os = "macos", "linux", "windows")). Align the two.
  • Nit: the daemon_status_of / STARTUP_HOLD_LIMIT docs.
    • "the banner and its Retry show" suggests Retry can recover an overdue hold, but on main it cannot.
    • "bounded well under" overstates it: the launchctl bootout/bootstrap calls have no timeout of their own.
  • Nit: home_dir()? can fail before the check runs, so "the check comes before every other step that can fail" is not literally true.
  • Nit: daemon_status_of can be pub(crate).

Testing notes

Each test is isolated, with its own temp socket and client, and no environment variables. SETTLE only guards negative checks, so it cannot cause false failures. The assertions that matter are deterministic.

Requirements check

  1. Document the startup ordering: met in nodespace-docs#112, with the "hold is usually short" sentence still to correct.
  2. Hold or queue calls without tripping the probe's rebuild: met.
  3. A mock daemon reporting another product receives no routed call: met.

Verdict: APPROVE, with the improvements recommended.

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Implementation review (with the design in NodeSpaceAI/nodespace-docs#112)

Automated review prepared for the design discussion. Comment only; the decision is the owner's. Reviewed at e3398fd. Nothing was built or run, as this is a shared machine; claims marked verified were checked by reading the code at that commit and tonic 0.12.3's source.

Summary

The latch and its wiring are correct, and the tests prove the main claim. What needs to change follows from the design review: the hold is released because the attempt returned, not because the answering daemon was checked, and once the limit passes nothing can release it.

Requirements (issue #3623)

Acceptance criterion Status
Document the startup ordering Met by docs#112, with the corrections in its review
Hold or queue data-plane calls without tripping the wedged-channel rebuild Met (verified in probe_and_recover, daemon_status_of, and the frontend poll, which probes only on healthy)
A test with a mock daemon reporting another product shows no routed call reaches it Met: no_boot_call_reaches_another_products_daemon… asserts that daemon saw exactly [GetDaemonVersion]
The issue's own case "a leftover daemon outside the shared launchd label" Not met by this PR alone: after the attempt the survivor is used, as the PR body says

Findings

[Important] 1. The release is tied to the attempt returning (daemon_setup.rs:727-729, :758)

The check runs once, first, and only when a daemon already accepts on the socket. A daemon that is not bound yet, or is Starting, at that moment is never asked, and the hold ends with it answering:

  • Linux: a unit already active with another binary and still loading its model. No socket, so no check; systemctl --user enable --now leaves an active unit alone; it binds; wait_for_daemon_or_refusal returns Healthy; release_hold_after releases; the queued boot calls go to it.
  • Any platform: a hand-started daemon still loading, or the "was starting, now healthy" early return a few lines below the check.

Recommendation: gate the release on a check of the daemon answering at the end of the attempt (the post-registration check of #3606), and keep the first-step check for eviction only. Principle: enforce the invariant where it is relied on.

[Important] 2. An overdue hold is terminal (lib.rs:147, startup_hold.rs:22)

Only the original attempt can release. If it hangs (launchctl/systemctl run with blocking .output() and no timeout) or panics, the state stays Overdue, the status stays not_running, every call fails, and the banner's Retry only re-reads that status (refreshDaemonStatus). The app is down until restarted, even with its own healthy daemon on the socket; on main that app works. reset_incompatible_database also calls ensure_daemon_running outside release_hold_after, so a successful restart from there emits healthy while the channel stays shut. Recommendation: route every caller of ensure_daemon_running through the releasing wrapper, and let Retry run a new attempt. Not releasing on a panic is the right call; log it.

[Important] 3. Any plugin can end the hold (grpc_client.rs:346)

release_startup_hold, startup_hold, connect_lazy_held and release_hold_after are pub, and GrpcClient is what extensions receive (DaemonReady.grpc, and State<GrpcClient> in any plugin command). The release point is single in fact (verified: one non-test caller) but only by convention. Make the release pub(crate). Principle: least privilege.

[Suggestion] 4. A 2-second wall-clock bound in a correctness test (startup_ordering_tests.rs:377)

probe_and_recover does no I/O while held, but a 2 s bound can still be missed under merge-gate load. The assertions after it (no rebuild hook ran, the daemon saw nothing) already catch a probe sent into the held channel, so PROMPTLY loses nothing. The 300 ms SETTLE sleeps are fine: under load they can only pass vacuously, and the final seen == [VERSION] is the real proof.

[Suggestion] 5. The source-order test pins text, not behaviour (daemon_setup.rs:4125)

It does not see the home_dir()? return ahead of the check, or the early return Ok(Healthy) after a Starting probe. With finding 1 it is no longer needed.

[Suggestion] 6. Outcomes without a test

  • The check goes unanswered and the calls then flow (the integration test covers running_daemon_executable returning None, not what the channel does next).
  • Nothing answers after the attempt: a released channel fails with UNAVAILABLE.
  • Windows: the ordering tests are cfg(unix), and connect_lazy/lazy_at on Windows changed shape. I could not check that it compiles.

[Nit] 7. Overdue => "not_running" (lib.rs:147) bypasses daemon_down_status(), so a standing incompatible-database refusal is reported as plain not-running.

What I checked and found sound

  • No lost wakeup: wait() subscribes and wait_for reads the current value first; send_replace works with no receivers.
  • Cancellation: the connector future belongs to the channel's buffer worker, not to a request, so a dropped call cannot strand the others. No lock is held across the wait.
  • Bounded queue: tonic's 1024-request buffer with backpressure. Past the deadline each queued call fails in turn, as UNAVAILABLE.
  • Rebuild: reconnect() reuses the latch, so it neither re-arms nor bypasses the hold.
  • No other dial path in the app outside the connector, the bare socket probes and the check's own connection.
  • Project rules: no file in WATCHED_PATHS touched, no compatibility code, no lint suppression, no product names or issue numbers in code or comments.

Verdict

Comment. I would not merge as it stands: land #3606 first, rebase onto it, gate the release on its post-registration check, and make an overdue hold recoverable. On the extension API version I recommend a minor bump; the reasoning is in the docs review.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated implementation review for the owner's design discussion. Verdict: comment only, not an approval. The latch, its wiring and the tests are sound. I would not merge as it stands: land #3606 first, gate the release on its post-registration check, and make an overdue hold recoverable. Full report is in the summary comment on this PR; inline notes below.

) -> T {
use tauri::Manager;

let outcome = attempt.await;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Important] The release follows the attempt, not a check of the daemon that is answering now. With the check done once at the top (line 758), a daemon that binds later in the attempt is used unchecked: on Linux, an active unit with another binary still loading its model is left alone by enable --now, binds, and wait_for_daemon_or_refusal returns Healthy. Gate this on a check made here, at the end (the post-registration check of #3606).

// the app's calls wait for this attempt to end. Windows has no second
// binary to tell apart.
#[cfg(unix)]
let evicted = evict_other_product_daemon(&socket_path).await;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Important] evict_other_product_daemon returns false without asking when the socket is absent or Starting. The "was starting, now healthy" early return below then uses that daemon unchecked.

Comment thread packages/desktop-app/app-lib/src/lib.rs Outdated
pub async fn daemon_status_of(client: &services::GrpcClient) -> String {
match client.startup_hold() {
services::StartupHoldState::Holding => "starting".to_string(),
services::StartupHoldState::Overdue => "not_running".to_string(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Important] Overdue is terminal: only the original attempt releases, and the banner's Retry only re-reads this status. A hung launchctl (blocking .output(), no timeout) or a panic leaves the app down until restarted, even with its own daemon healthy. reset_incompatible_database also calls ensure_daemon_running outside release_hold_after. Nit: this bypasses daemon_down_status().

Self::from_channel(channel)
/// Ends the startup hold: calls waiting on the channel go out, and later
/// ones dial at once. Called once the launcher's start attempt is over.
pub fn release_startup_hold(&self) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Important] pub on a type extensions receive (DaemonReady.grpc, State<GrpcClient> in any plugin command), so any plugin can end the hold. The release point is single only by convention. Make it pub(crate), with connect_lazy_held and release_hold_after.

// Well under the probe's own 5-second timeout: a held probe would sit it
// out and then rebuild.
let recovered = tokio::time::timeout(
Duration::from_secs(2),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] A 2 s wall-clock bound in a correctness test can be missed under merge-gate load. The assertions that follow (no rebuild hook, nothing seen by the daemon) already catch a probe sent into the held channel, so PROMPTLY loses nothing.

/// only because the check of which daemon holds the socket comes before
/// every step of the attempt that can fail.
#[test]
fn the_start_checks_the_running_daemon_before_any_step_that_can_fail() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] This pins source order, not behaviour: it does not see the home_dir()? return ahead of the check or the early return Ok(Healthy) after a Starting probe. If the release is gated on a check at the release point, the test is not needed.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review — round 1

Pushed f65a959b (code) and nodespace-docs 08374c3 (docs).

Addressed

  • [Improvement] Hold covers the whole attempt, so warm launches get slower. Implemented the reviewer's proposal. On every warm macOS launch extract_sidecar_if_changed runs codesign --verify --strict and the quarantine check on both sidecars, so the cost was real.
    • check_running_daemon (formerly evict_other_product_daemon) now ends the hold itself when the check keeps the daemon on the socket: a match, an unanswered check, or a client dialing another socket.
    • With nothing on the socket, or after an eviction, release_hold_after still ends it when the attempt returns, so those calls reach the daemon the attempt starts.
    • The function now takes the app, the dialed socket, the profile and the boot-out, so the ordering tests drive the production decision instead of an inline copy. evict_if_other_product is private again.
    • The docs PR's "When the hold ends" section and the ADR-084 amendment are updated, and the inaccurate "usually short" sentence is gone.
  • [Improvement] No test covers the wiring. Added the_apps_own_client_is_built_held and the_app_manages_its_own_client_held, caught by mutations M17 and M18.
  • Nit: cfg trap. The held client is managed only on macOS/Linux/Windows, the targets whose setup task runs the start attempt; other targets keep connect_lazy().
  • Nits: doc wording. The hold limit's bound now says the service-manager calls have no timeout of their own. The overdue status no longer claims Retry recovers. The home-directory exception is stated. daemon_status_of is pub(crate).
  • New tests: a cold start keeps the hold until the attempt ends; another dialed socket ends it at once without asking the registered daemon; a matching daemon's boot calls finish while the attempt is still running.

Not done here (documented)

  • [Improvement] Install coexistence checks and other-product notices (ADR-084 §4.3, §5) #3606 interplay, (a) release before the emit and (b) a refused transition plus letting other_daemon through daemon_status_of. On main nothing would use either piece, so adding them now would be dead code. The PR body's "Interaction with open work" now lists exactly what that rebase needs, and the docs PR lists it as an open question.

Verification

  • cargo clippy -p nodespace-app-lib --all-targets -- -D warnings -D clippy::unused-async: clean. cargo fmt --check: clean.
  • cargo nextest run -p nodespace-app-lib --lib: 352/352 pass. --test it daemon_executable_check_test::unhappy_paths: 2/2 pass.
  • Mutation check re-run on the new head: all 19 mutations caught (table in the PR body).
  • Push check passed.

Re-review needed: yes. When the hold ends changed (a second release point), which is a design change.

@mstomar125
mstomar125 force-pushed the issue-3623-product-check-ordering branch from f65a959 to 5015628 Compare October 5, 2026 16:49
@mstomar125

Copy link
Copy Markdown
Contributor Author

Code review — round 2 (re-review of f65a959b, pragmatic-code-reviewer, medium depth)

Re-review Summary

The new release point is correct and covered. check_running_daemon ends the hold right after a check that keeps the daemon on the socket. It does not end it when nothing is on the socket, when the socket is Starting, or after an eviction.

Compared with ending the hold at the end of the attempt, no outcome sends calls to a different daemon; only the timing changes:

  • Unknown: the rest of the attempt does nothing to that daemon.
  • binary_updated after a Match: the calls reach this product's daemon before it restarts.
  • Override: the plist pins the registered socket.

Release is idempotent, and the cfg split and tests are sound. boot_calls_wait_for_the_check_only… really proves the release comes before the attempt ends: its oneshot deadlocks until PROMPTLY without it.

Round-1 findings: status

  1. Wiring test: addressed (M17, M18).
  2. Hold covers the whole attempt: addressed. Some comments are still stale (below).
  3. Install coexistence checks and other-product notices (ADR-084 §4.3, §5) #3606 interplay: deferred with a documented reason. Acceptable.
    4–7. Nits: addressed.

New findings

Critical Issues

None.

Suggested Improvements

  • [Improvement] Stale comments. Five comments and one docs sentence still say the hold ends only when the attempt is over:
    • lib.rs, the setup-task comment;
    • GrpcClient::release_startup_hold;
    • running_daemon_executable;
    • the held_client doc;
    • daemon_status_of's "has not yet checked";
    • extension-points.md.
  • [Improvement] The docs' survivor row and the ADR-084 amendment disagree with the code on this branch. Both say the hold stays shut. Here, release_hold_after ends the hold when the attempt returns and the calls reach the survivor. Either mark them as depending on Install coexistence checks and other-product notices (ADR-084 §4.3, §5) #3606, or hold docs#112 until that lands.

Nitpicks

  • Nit: check_running_daemon's doc and the docs' first row should mention a sidecar-update restart (same product).
  • Nit: STARTUP_HOLD_LIMIT should name all unbounded subprocesses (codesign, lsof), not just the service manager.
  • Nit: the docs' Unknown row should say "an error, or none within 2 seconds".
  • Nit: no_boot_out() can't fail a test by itself, because the eviction runs it on spawn_blocking and ignores the JoinError. Rename or redocument it.

Verdict: APPROVE.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review — round 2 (also answers the implementation review above)

Pushed 5015628a, rebased onto 9bf187ab, and nodespace-docs 009012c.

The round-2 re-review approved. The implementation review on this PR, written against e3398fd, found a gap that round 1's early release did not close: the hold ended because the attempt returned, not because the daemon answering had been checked. This round makes the hold open only for a daemon that passed the check.

Addressed

  • Impl. review [Important] 1 (release tied to the attempt returning), and round 2's survivor-row mismatch.
    • settle_hold_after replaces release_hold_after. After the attempt it asks the daemon then answering on the dialed socket (settle_startup_hold). It opens the hold only for this app's daemon; any other answer, or none, shuts it, and calls fail at once.
    • This covers a daemon not bound at the first check (a Linux unit still loading, a hand-started daemon), a Starting socket, an unanswered check, and the survivor.
    • check_running_daemon still releases early, but only on a Match. An unanswered check or another dialed socket now waits for the settle.
    • The setup task reports healthy only when the hold is open.
    • Tests: …survives_the_boot_out, …binds_during_the_start, with_another_dialed_socket….
  • Impl. review [Important] 2 (an overdue hold is terminal).
    • While the hold is shut or overdue, check_daemon_status asks the daemon again and opens the hold when this app's daemon answers. The frontend's poll and Retry run it.
    • The database reset's ensure_daemon_running now goes through settle_hold_after too.
    • Tests: a_hold_shut_with_nothing_answering_opens…, an_overdue_hold_opens…, a_status_check_never_opens….
  • Impl. review [Important] 3 (any plugin can end the hold). release_startup_hold, the new shut_startup_hold and settle_hold_after are crate-only. startup_hold() stays a read.
  • Impl. review [Suggestion] 4. The probe test uses PROMPTLY instead of a 2-second bound. Its assertions still catch a probe sent into the held channel (M14).
  • Impl. review [Suggestion] 5. The source-order test is removed: the gate no longer depends on step order.
  • Impl. review [Nit] 7. Down statuses go through daemon_down_status().
  • Round 2 [Improvement] stale comments. All six are updated, including extension-points.md.
  • Round 2 nits.
    • check_running_daemon's doc mentions the sidecar-update restart.
    • STARTUP_HOLD_LIMIT names codesign and lsof.
    • The docs' Unknown row says "an error, or none within 2 seconds".
    • no_boot_out is now unexpected_boot_out, documented as unable to fail a test itself, with each caller asserting nothing was evicted.

Not done here (documented)

Verification

  • cargo clippy -p nodespace-app-lib --all-targets -- -D warnings -D clippy::unused-async: clean. cargo fmt --check: clean.
  • cargo nextest run -p nodespace-app-lib --lib: 359/359 on the rebased head. --test it daemon_executable_check_test::unhappy_paths: 2/2.
  • Mutation check re-run: all 23 caught (table in the PR body). Push check passed.

Re-review needed: yes. The gate's semantics changed: a new Shut state, the settle after the attempt, and the re-ask from the status check.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Code review — round 3 (re-review of 5015628a + dd1a4ca9, pragmatic-code-reviewer, medium depth)

Re-review Summary

The gate redesign is correct, and it closes the gap the implementation review found. The hold opens only on a Match, at one of three points: the early check, the settle after the attempt, and the status re-ask while the hold is shut or overdue. A non-match or no answer shuts it. Nothing was found that reaches a daemon which did not pass, apart from the accepted check-then-dial gap and a same-product restart after a sidecar update.

Latch. It moves only towards Released (shut() changes only Holding; release() works from any state), so concurrent settles are safe and no wakeup is lost.

tonic behaviour for a shut hold. Queued calls drain as UNAVAILABLE, and the buffer is never poisoned.

Status and probe. The probe is skipped while not released. The status cannot flap, since a shut hold only ever changes to Released. The reset path still works.

Earlier findings: status

  • Implementation review:
    • 1–5 and 7: addressed.
    • 6: partly. Nothing tests an unanswered first check (Improvement 2 below), and Windows is deferred.
  • Round 2: all addressed (stale comments, survivor row and amendment, nits).

New findings

Critical Issues

None.

Suggested Improvements

  1. [Improvement] Windows: the settle's one-shot pipe dial has no ERROR_PIPE_BUSY (231) retry. Every Windows launch now goes through the settle. A dial that lands between two pipe instances shuts the hold for up to 15 seconds. Retry the open on 231 inside the 2-second timeout, using tokio's documented NamedPipeClient loop. This was inferred from reading, and the outcome heals itself on the next poll.
  2. [Improvement] Nothing tests that an unanswered first check no longer opens the hold. A mutation that releases early on != Mismatch would survive the suite. Add a stand-in daemon that answers GetDaemonVersion with an error.
  3. [Improvement] Make the read-only hold API crate-only. That covers startup_hold(), connect_lazy_held(), StartupHold, StartupHoldState and STARTUP_HOLD_LIMIT. With it, GrpcClient's public surface does not grow, which simplifies the extension-API version question.

Nitpicks

  • Log volume while shut: two warns every 15 seconds. Warn only when the hold first shuts.
  • check_daemon_status's app: unused on non-desktop targets.
  • The shut unit test doesn't prove "at once": under the paused clock, a missing notify would still pass. Assert the error kind.
  • a_status_check_never_opens…: it calls settle_startup_hold directly, so rename it.
  • Stale wording: the module doc says "Windows has no such check"; the comment above app.manage(...) and the hold field doc still speak of the start attempt.
  • Docs#112:
    • the survivor row's "a new start" should say a relaunch, until a Retry that runs a new attempt lands;
    • the ADR amendment should say calls wait while the attempt runs, and a later status check can open a shut or overdue hold;
    • the extension-points wording;
    • the PR body (its extension-points description, and the missing synchronous-setup placement row).

Docs PR against the code

The section matches the code apart from the nits above.

Verdict: APPROVE. Improvements 1–3 are recommended.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review — round 3

Pushed 640d14cf (code) and nodespace-docs 2b04c74.

Addressed

  • [Improvement] 1, Windows ERROR_PIPE_BUSY.
    • pipe_channel, which backs dial_once and GrpcClient::connect(), now opens through open_pipe_when_free. That is tokio's documented loop: retry every 50 ms while raw_os_error() == 231. It is bounded by the product check's 2-second timeout.
    • The lazy channel's connector is unchanged.
    • It is cfg(windows) and not compiled on this machine. The release workflow's Windows build is the first to compile it.
  • [Improvement] 2, an untested unanswered first check.
    • MockDaemon::serve_without_saying answers GetDaemonVersion with UNAVAILABLE.
    • The new test an_unanswered_first_check_opens_nothing_and_the_settle_shuts_the_hold covers it: the hold is still Holding after the first check, nothing is evicted, and it is Shut after the settle. It catches M24 (an early release on != Mismatch).
  • [Improvement] 3, a crate-only hold API. StartupHold, StartupHoldState, STARTUP_HOLD_LIMIT, connect_lazy_held() and startup_hold() are crate-only, so GrpcClient's public surface is unchanged. Docs open question 2 now says so.
  • Nit: log volume. shut() reports whether it shut the hold, and the settle warns only then, logging later re-asks at debug. The status check also re-asks only when a daemon accepts on the socket, so a shut hold with nothing there dials nothing and logs nothing per poll.
  • Nit: check_daemon_status's app. The cfg now sits on the match arm, so app is used on every target.
  • Nit: the shut test. It asserts ErrorKind::ConnectionRefused for the waiting call and for a later one, and catches M25 (a shut that doesn't notify).
  • Nit: a test name. a_status_check_never_opens… is now a_re_ask_never_opens….
  • Nit: stale wording. Fixed in the module doc ("no such eviction"), the comment above app.manage(...), and the hold field doc.
  • Docs nits.
    • The survivor row says a relaunch starts the app's own daemon, and why: it exited cleanly on the lock, and the service manager restarts only a crash.
    • The ADR-084 amendment says calls wait while the launcher runs and later status checks can still open the channel.
    • The status bullet says a re-ask needs a daemon accepting on the socket.
    • The extension-points wording is fixed.
    • The PR body now has the extension-points description and the synchronous-setup placement row.

Verification

  • cargo clippy -p nodespace-app-lib --all-targets -- -D warnings -D clippy::unused-async: clean. cargo fmt --check: clean.
  • cargo nextest run -p nodespace-app-lib --lib: 360/360. --test it daemon_executable_check_test::unhappy_paths: 2/2.
  • Mutation check re-run on this head: all 25 caught (table in the PR body). Push check passed.

Re-review needed: yes, narrowly. The Windows retry is new code that can't be compiled here, and the status re-ask now depends on whether the socket accepts. Scope: 640d14cf only.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Code review — round 4 (narrow re-review of 640d14cf + docs 2b04c74, pragmatic-code-reviewer, medium depth)

Re-review Summary

Every round-3 finding is addressed, and nothing blocks.

Windows code, read as a compiler would. Nothing compiled here, and I found nothing that would fail under clippy --all-targets -D warnings:

  • ClientOptions::open takes impl AsRef<OsStr> in tokio 1.52.3.
  • The connector future is Send: across the await it holds &str, Sleep and an io::Result<NamedPipeClient>.
  • There are no unused imports, and Duration is used elsewhere.
  • Every other cfg(windows) item the PR touches resolves.

The retry is needed. The daemon creates the next pipe instance only when its accept stream is polled again. A warm Windows launch hits that window: the probe opens and drops a pipe, then the settle dials straight away.

Status. Re-asking only when the socket is healthy leaves no shut or overdue hold stranded. The busy-pipe and slow-accept cases self-heal on the next poll, and the warn-once holds.

Visibility. GrpcClient gains no pub items against main, and nothing crate-private leaks into a pub signature.

Tests and docs. The new test and mock are sound, and so is the stronger shut test. docs#112 at 2b04c74 matches the code.

Round-3 findings: status

All addressed: the Windows retry, the unanswered-check test (M24), the crate-only API, the log volume, app's use, the shut test (M25), the test name, the stale wording, and the docs nits.

New findings

Critical Issues

None.

Suggested Improvements

  1. [Improvement] Compile the Windows code before merge. Nothing compiles cfg(windows) before release.yml does. A workflow_dispatch with platform=windows-x86 builds and only uploads artifacts.
  2. [Improvement] Nothing tests the down-status branch of daemon_status_of. A mutation that returns the socket status there would survive, so the status would read "healthy" while every call fails.

Nitpicks

  • Nit: open_pipe_when_free has no bound of its own, which matters for the untimed GrpcClient::connect().
  • Nit: shut()'s bool return is untested.
  • Nit: the literal 231 is written out twice; share one constant.
  • Nit: a daemon that accepts but never answers still logs one warning per poll from running_daemon_executable.
  • Nit (docs): "every status check asks again" is missing its "when a daemon accepts" condition in two places.

Verdict: APPROVE.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review — round 4

Pushed 89b00207 (code) and nodespace-docs a2ffb04.

Addressed

  • [Improvement] 2, the down-status branch. daemon_status_of is split. held_daemon_status returns None when a daemon answers but has not passed the check, and daemon_status_of reports that as down through daemon_down_status(). The split keeps the test off the marker file in the real home directory. a_re_ask_never_opens… now asserts None after a re-ask against another product's daemon. That catches the new mutation M26, which returns the socket status there.
  • Nit: unbounded busy-pipe retry. open_pipe_when_free stops after 2 seconds of its own (PIPE_BUSY_WAIT) and then returns the busy error, so GrpcClient::connect() can't hang on a pipe that stays busy.
  • Nit: the literal 231. One cfg(windows) constant, grpc_client::ERROR_PIPE_BUSY, now serves open_pipe_when_free and check_daemon_socket.
  • Nit: shut()'s return. The shut test asserts shut() is true once and then false. The released-hold test asserts it is false.
  • Nit (docs): the "every status check" wording. Both places now say "that finds a daemon accepting on the socket".

Not done here (documented)

  • [Improvement] 1, a Windows build before merge. I did not dispatch release.yml: triggering a release workflow is outside this task and is the owner's call. The PR body states that the cfg(windows) code was checked by reading only, and gives the exact dispatch command for a pre-merge Windows build.
  • Nit: one warning per poll from running_daemon_executable for a daemon that accepts but never answers. Left as it is: it is that function's existing diagnostic, it is also the first check's, and that case is rare.

Verification

  • cargo clippy -p nodespace-app-lib --all-targets -- -D warnings -D clippy::unused-async: clean. cargo fmt --check: clean.
  • cargo nextest run -p nodespace-app-lib --lib: 360/360. --test it daemon_executable_check_test::unhappy_paths: 2/2.
  • Mutation check re-run on this head: all 26 caught. Push check passed.

Re-review needed: no.

  • Each change here is small and was asked for directly: a pure split of one function, one test assertion, a deadline guard and a shared constant.
  • The macOS changes are covered by tests and mutations, and the round-4 review read the same Windows pattern and found it sound.
  • What remains, a compiled Windows build, is an owner decision before merge, not a review question.

@mstomar125

Copy link
Copy Markdown
Contributor Author

@malibio held for the design discussion. There's a summary and the open questions on #3623.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

@mstomar125 #3606 has landed, and I'm taking this PR and nodespace-docs#112 over to finish them, so please don't push to issue-3623-product-check-ordering (either repo) until I post here that it's done.

I'll rework it to the decisions posted on nodespace-docs#112: the hold ends only when the daemon answering at the end of the start attempt has reported this app's binary, or nothing answers; an unanswered check keeps holding and is asked again; a hold past its limit is recoverable through Retry; every caller that starts the daemon goes through the releasing wrapper; the release functions are pub(crate); no extension API version.

@malibio

malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Code review: round 5 (re-review of the owner's rework, head c60a2ea2e, pragmatic-code-reviewer)

Summary

The rework does what the decisions on docs#112 say. I found no blocker. Three small improvements and some nits follow. The PR body is stale and has to be rewritten before merge.

I read the full diff against origin/main for daemon_setup.rs, startup_hold.rs, grpc_client.rs, lib.rs, coexistence.rs, incompatible_database.rs and commands/nodes.rs, and the frontend Retry change. Nothing was compiled or run in this review. I relied on the stated results: nextest 427, clippy, test:changed.

Decided behaviour against the code

  1. Queue, then UNAVAILABLE past the limit: met.
    • StartupHold::wait blocks on the latch with timeout_at(deadline) and fails only at the limit.
    • A release lets waiting calls through.
    • The 2-minute limit is documented as "a chosen bound, not a derived one", and the doc names the untimed steps (service manager, codesign, lsof, sidecar copies).
  2. An unanswered check keeps holding: met.
    • answering_daemon treats ProductCheck::Unknown as "ask again on the next 250 ms poll" inside the 30 s wait.
    • Unchecked never releases.
    • Retry runs a new attempt that asks again.
    • No timeout path ends the hold.
  3. No extension API version: met. The three non_exhaustive comments are reworded (behaviors/mod.rs, core/extensions.rs, daemon/extensions.rs). Nothing in the diff adds an apiVersion or API-version wording.
  4. When the hold ends: met.
    • start_attempt releases only on ThisApp or Nobody, and only after bring_up has returned and answering_daemon has asked whoever answers at the end.
    • The top-of-attempt check, evict_other_product_daemon, only evicts and never touches the hold.
    • On Retry, retry_daemon_start calls start_daemon_and_report, which calls ensure_daemon_running, which runs start_attempt. A hold past its limit is therefore recoverable.
    • The three callers all go through that one function: startup (lib.rs), Retry (coexistence.rs) and reset_incompatible_database.
    • release_startup_hold, startup_hold, StartupHold, STARTUP_HOLD_LIMIT and connect_lazy_held are pub(crate).
    • start_attempt and answering_daemon are pub(crate). ensure_daemon_running stays pub, but it is safe: it releases only through the check.
    • The module doc and the GrpcClient docs say the guarantee covers the app's own channel only.
    • I found no app-side NODESPACE_HOME reasoning. The dialed != socket_path skip is justified by NODESPACED_SOCKET alone, which is what the decision allowed.
  5. The two confirmed behaviour changes are what the code does. There is no warm-launch early release. A failed bring_up waits zero seconds, asks whoever answers once, and Answering::Other returns Ok with the other-daemon record, so it reports other_daemon.

Integration with #3606

  • record_outcome replaces the other-daemon record only after the attempt has its answer, so a concurrent poll keeps the last outcome.
  • start_daemon_and_report returns the status crate::daemon_status reports. That goes through status_unless_other_daemon, so it cannot disagree with the 15 s poll.
  • reset_incompatible_database now returns the String directly, which is consistent.
  • The reconnect() paths reuse self.hold, so a channel rebuild cannot bypass an active hold.

Races and release paths

  • release() is a monotone send_replace(true), so overlapping attempts (startup and Retry) are safe. An attempt cannot release early: each one releases only on its own end-of-attempt answer.
  • No path leaves the hold on forever. Past the limit, calls fail at once and the status turns "not running", which shows Retry.
  • Accepted by decision, worth knowing: Nobody releases. If another product's daemon binds after that release, the channel is open to it. A later check does not re-shut a released hold.

Windows cfg arms (read only)

I found nothing that would fail to compile.

  • evicted has a cfg(not(unix)) arm.
  • answering_daemon, start_attempt and check_daemon_socket take the pipe name as a Path, which is consistent with resolve_socket_path on Windows.
  • connect_lazy, lazy_at, channel_lazy and dial_once have unix and windows arms, and reconnect passes the hold in both.
  • ERROR_PIPE_BUSY and PIPE_BUSY_WAIT are windows-only and used only there.
  • The remaining StartupHoldState and startup_hold() uses are unconditional.

Findings

Critical

None.

Suggested improvements

  1. [Improvement] The PR body describes the old design.
    • It still describes the warm-launch early release, settle_hold_after, the Shut state, and the status check re-asking the daemon.
    • It lists 360 tests, 26 mutations and check-pro-boundary.ts. It does not describe the end-of-attempt rule, Retry-as-recovery, or the guarantee being limited to the app's own channel.
    • It says "Pro", and the script is now check-sync-boundary.ts.
    • Rewrite it to the final behaviour. The test table and mutation table are stale too.
  2. [Improvement] Retry no longer works outside Tauri.
    • app-shell.svelte now calls retryDaemonStart(), which calls invoke('retry_daemon_start').
    • The daemon-status.ts comment itself says refreshDaemonStatus is "for a source with no push transport", and the harness and dev-proxy sources are that case. Retry there now throws and only logs, where it used to re-pull the status.
    • Guard retryDaemonStart with isTauri() and fall back to refreshDaemonStatus(), as getOtherDaemon guards itself. Add a test for it.
  3. [Improvement] The Retry spinner can stall.
    • If a start step that has no timeout hangs, which is the case the 2-minute limit exists for, a second start attempt probably hangs behind it, and the banner's Retry sits at "Retrying…" with nothing to tell the user.
    • Nothing stops overlapping attempts either. Each window disables only its own button.
    • This is acceptable for now, but say so in the doc.

Nitpicks

  • Nit: every_start_of_the_daemon_goes_through_the_start_attempt and the_app_manages_its_own_client_held read source. I judge that acceptable, because the real launcher drives the service manager and the wiring cannot be exercised otherwise, and the comments say so. It is brittle in two places: the "\n}\n" slice and the exact cfg string. If either breaks, say so in the assertion message so the failure points at the wiring and not at the test.
  • Nit: the tests use virtual time (start_paused) for the limit, and SETTLE (300 ms real) is only a "still pending" window, so there is no wall-clock assertion. I have no objection.
  • Nit: connect_lazy is now pub for any(unix, windows) but the app calls it only on other targets. If that is test-only, consider whether it should stay pub.

Rules

  • No lint suppression, no #[allow(dead_code)] and no issue numbers in comments or docs in the diff.
  • No "Pro" wording in code, and no extension API version wording.
  • No migration or compatibility code.

Verdict: APPROVE once the PR body is rewritten. The two improvements on Retry are optional before merge. Re-review needed: no.

@malibio

malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Address review: round 5 (APPROVE)

Addressed

  • Retry outside Tauri: retryDaemonStart re-reads the status when there is no Tauri behind it (harness, dev proxy), with a service test that fails when the guard is removed.
  • PR body rewritten to the final behaviour (end-of-attempt rule, Retry as recovery, own-channel scope, test and mutation summary, check-sync-boundary.ts, no "Pro" wording).
  • Overlapping start attempts and a hung untimed step stalling Retry are stated in the Daemon Lifecycle section of docs Add MCP stdio server for AI agent access #112.

Skipped

  • connect_lazy visibility: the extension fixture tests and the targets that don't hold still call it, so it stays pub. Revisit if those callers go.
  • Source-reading wiring tests: left as they are, since the real launcher can't run in tests. The reviewer found them acceptable.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: the only code change is a small guard with a test; the rest is the PR body and docs. Latest main (#3673) merged in cleanly. nextest -p nodespace-app-lib: 427 passed, 1 skipped (after rebuilding sidecars); frontend, scripts and browser tiers passed.

@malibio
malibio force-pushed the issue-3623-product-check-ordering branch from c62d841 to 5524549 Compare October 6, 2026 11:42
@malibio
malibio merged commit a1c0783 into main Oct 6, 2026
@malibio
malibio deleted the issue-3623-product-check-ordering branch October 6, 2026 11:42
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.

Hold the app's data-plane calls until the daemon product check passes

2 participants