Repository navigation
Hold the app's daemon calls until the startup product check is over (held for design discussion) - #3639
Conversation
Code review — round 1 (pragmatic-code-reviewer, medium depth)Code Review SummaryPR #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 tonic 0.12.3 behaviour (checked in the registry source)
FindingsCritical IssuesNone. Suggested Improvements
Nitpicks
Testing notesEach test is isolated, with its own temp socket and client, and no environment variables. Requirements check
Verdict: APPROVE, with the improvements recommended. |
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 SummaryThe 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)
Findings[Important] 1. The release is tied to the attempt returning ( The check runs once, first, and only when a daemon already accepts on the socket. A daemon that is not bound yet, or is
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 ( Only the original attempt can release. If it hangs ( [Important] 3. Any plugin can end the hold (
[Suggestion] 4. A 2-second wall-clock bound in a correctness test (
[Suggestion] 5. The source-order test pins text, not behaviour ( It does not see the [Suggestion] 6. Outcomes without a test
[Nit] 7. What I checked and found sound
VerdictComment. 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
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
[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; |
There was a problem hiding this comment.
[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.
| 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(), |
There was a problem hiding this comment.
[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) { |
There was a problem hiding this comment.
[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), |
There was a problem hiding this comment.
[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() { |
There was a problem hiding this comment.
[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.
Address review — round 1Pushed Addressed
Not done here (documented)
Verification
Re-review needed: yes. When the hold ends changed (a second release point), which is a design change. |
f65a959 to
5015628
Compare
Code review — round 2 (re-review of
|
Address review — round 2 (also answers the implementation review above)Pushed The round-2 re-review approved. The implementation review on this PR, written against Addressed
Not done here (documented)
Verification
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. |
Code review — round 3 (re-review of
|
Address review — round 3Pushed Addressed
Verification
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: |
Code review — round 4 (narrow re-review of
|
Address review — round 4Pushed Addressed
Not done here (documented)
Verification
Re-review needed: no.
|
|
@malibio held for the design discussion. There's a summary and the open questions on #3623. 🤖 Generated with Claude Code |
|
@mstomar125 #3606 has landed, and I'm taking this PR and nodespace-docs#112 over to finish them, so please don't push to 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 |
Code review: round 5 (re-review of the owner's rework, head
|
Address review: round 5 (APPROVE)Addressed
Skipped
Re-Review DecisionDecision: 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. |
…held for design discussion)
c62d841 to
5524549
Compare
Closes #3623
At startup, the frontend's first calls can reach whichever daemon holds
daemon.sockbefore 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
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.UNAVAILABLEonly once the hold passesSTARTUP_HOLD_LIMIT, 2 minutes from the client's creation, a chosen bound. After that, calls fail at once until the hold ends.start_attemptruns 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:other_daemon;starting. The wait running out never ends the hold.evict_other_product_daemonboots out another product's daemon and never touches the hold, so there is no warm-launch early release.retry_daemon_start, so an overdue hold is recoverable. Outside Tauri, where there is no daemon to start, Retry re-reads the status.reset_incompatible_databaseall reachbring_up_daemononly throughstart_attempt.check_daemon_statusreportsstartingwhile holding anddaemon_down_statusonce overdue.probe_and_recoverdoes nothing while held.pub(crate), so an extension cannot end it.What changed
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.rsconnect_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()andconnect_lazy()build released clients.reconnect()keeps the hold.daemon_setup.rsstart_attempt,answering_daemon,start_outcome;ensure_daemon_runninggoes through them.start_daemon_and_reportreportscrate::daemon_status, so the event and the poll agree.lib.rs,coexistence.rs,incompatible_database.rsdaemon_statuswrapsstatus_unless_other_daemon; the reset's restart goes throughstart_daemon_and_report.commands/nodes.rsprobe_and_recoverreturnsfalsewithout probing while held.app-shell.svelte,daemon-status.tspackages/core/src/extensions.rs,behaviors/mod.rs,packages/daemon/src/services/extensions.rsTests
startup_ordering_tests.rs(22 tests) serves in-process stand-in daemons on a temporary Unix socket and drives the realget_nodeandlist_databasescommands 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:fixand clippy-D warnings: clean.cfg(windows)arm was read against its unix counterpart; only the darwin target is installed.Docs: nodespace-docs #112 (ADR-084 §4.3, Daemon Lifecycle).
🤖 Generated with Claude Code