Repository navigation
List databases in the tray and open the app on the one picked (#1536) - #2039
Conversation
The tray offered a single "Open NodeSpace" that always landed on whatever database the app last had, even though the daemon has served several since ADR-053. It now carries a Databases submenu listing every registered database, marked with the two facts that matter — whether it is open, and whether it syncs to a cloud tenant — and picking one opens the app on it. The registry cannot be handed to the tray at startup: the tray loop owns the main thread and is running before the gRPC side builds the DatabaseManager. So the tray is told instead, over the same event proxy the Status label already uses. A snapshot that arrives before the tray finishes initializing is held and applied once it does, so the two starting in either order is fine. Labelling is a plain function over a registry snapshot, so the rules — open, synced, and a missing file being listed-but-unselectable rather than silently dropped — are decided somewhere tests can reach without a display. For the launch itself the daemon sets NODESPACE_INITIAL_DATABASE on the process it spawns, and the app treats it as the highest-precedence choice for that launch only; a plain "Open NodeSpace" leaves it unset so the remembered selection still wins. An id naming a database that is no longer registered is ignored rather than leaving the app with no selection. Two honest limits: a database added or removed later does not refresh the submenu until the daemon restarts, since only the initial snapshot is pushed so far; and picking a database while the app is already running does not re-point it, because the initial database is read at startup and switching an open window needs a focus signal that does not exist yet. Multi-window and the docs pass that were bundled here are split out separately. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Review caught that the label's "open" marker is wrong more often than right. The submenu is rendered once at daemon boot, and the idle reaper closes databases during normal use, so the marker froze at whatever was open at startup. The issue asks the menu to indicate state, so a confidently-stale marker is worse than none: the label now carries the facts the registry actually keeps — which database is the default, and which sync — and a test pins the deliberate absence of the open marker so restoring it forces a decision about live refresh. Also from review: - The doc block above open_ui was left attached to the function inserted beneath it, so rebuild_databases_menu described spawning the UI and open_ui had no doc at all. Moved back, and extended to state what open_ui actually does when the app is already running. - A failed removal during a rebuild orphaned menu items: the drain emptied the tracking list regardless, leaving items visible but unclickable and duplicated on the next rebuild. Removal failures are now logged and the list cleared unconditionally, and enablement is computed on the way out so a partial rebuild cannot leave reachable items behind a greyed-out parent. - The launch-time database is answered once per process. It described a launch, but was re-read on every call, so switching database in-app and reloading the webview would have snapped back to the tray's choice. - The desktop side spells the env var out because it cannot depend on the daemon crate; it now names the constant to keep the two in step. Test hygiene, which this session has otherwise been spent fixing: the two new tests installed a persistent mock implementation and left a remembered id in localStorage, and the file's beforeEach used clearAllMocks (calls only) with no storage reset — so both leaked into every later test in the file. One later test was passing only because the leftover id happened to match. Reset the mock and clear storage at the source. Refreshing the menu live, restoring the open marker, and making a pick do something when the app is already running are filed as a follow-up. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The previous round "fixed" a latent concern by consuming the launch-time database id on first read. Review found that made the common case wrong: a second load() runs on every launch, so the second read got nothing, resolved to the remembered database, and overwrote the tray's pick — nondeterministically, depending on which load finished last. Picking a database in the tray would have silently opened a different one. The concern it addressed was latent — nothing reloads the webview today — so the cure was worse than the disease. The read answers consistently again, and the reason is written down next to it, along with where to consume it (at apply time in the store) if a reload path ever appears. Kept from that round: load() now re-checks that no selection was made while it was suspended before assigning, so concurrent loads cannot overwrite each other or hydrate the settings node twice. A test pins that two concurrent loads land on the tray's pick. Also from re-review: rebuild_databases_menu never fails, so it no longer returns a Result that both call sites were pointlessly matching on; the label doc no longer calls registry-persisted facts "stable" when the default is user-mutable too; and two test fixtures named after status markers are renamed so the assertion reads unambiguously. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
APPROVE (self-review, mstomar125) Three rounds, and the second one is the instructive part. Pass 1 confirmed the lifecycle work — Pass 2 caught that one of my fixes made things worse. Consuming the launch-id on first read — meant to stop a webview reload re-applying it — broke the common case: a second Kept from that round: On the new concurrency test, honestly: with the read stable again it passes without the guard too, since both loads see the same value. It pins the outcome — re-introducing a consume-once read fails there rather than silently in the product — and the test says that rather than implying it proves the guard. One AC note: the issue says "indicate active/synced". The daemon's only literal "active" notion is the compute scheduler's, which is as volatile as
|
Summary
The tray offered a single "Open NodeSpace" that always landed on whatever database the app last had — even though the daemon has served several since ADR-053. It now carries a Databases submenu listing every registered database, marked with the two facts that matter (open, synced), and picking one opens the app on it.
Scope here is the tray slice only; multi-window (#2033) and the docs pass (#2034) were split out.
The constraint that shaped it
The registry can't be handed to the tray at startup:
tray::runowns the main thread with a!Sendtaoloop, and it's already running before the gRPC side builds theDatabaseManager(main.rs:178seeds the tray; the manager appears at:281, inside the spawned task).Arc<DatabaseManager>is "already in scope wheretray::runis called." It isn't — that shaped the wrong plan, so noting it here.So the tray is told instead, over the same
EventLoopProxythe Status label already uses (TrayEvent::DatabasesChanged). A snapshot arriving before the tray finishes initializing is held and applied once it does, so the two starting in either order is fine.Testability
Labelling is a plain function over a
RegistrySnapshot, so the rules live somewhere tests can reach without a display: open/synced markers, and a missing file being listed-but-unselectable rather than silently dropped (a vanished database should say so, not disappear). 4 Rust tests cover the labels, the missing case, id/order preservation, and the empty registry.Launch path
The daemon sets
NODESPACE_INITIAL_DATABASEon the process it spawns, and the app treats it as the highest-precedence choice for that launch only — a plain "Open NodeSpace" leaves it unset so the remembered selection still wins. An id naming a database that's no longer registered is ignored rather than leaving the app with no selection. Precedence is nowrequested ?? remembered ?? default ?? first, each validated against the registered list.Two honest limits
Verification
Frontend 201 files / 4573 tests;
cargo test -p nodespace-daemon+clippy --all-targetsclean; lint +svelte-checkclean. I confirmed the launch-precedence test fails against the pre-change code (the second precedence test is a guard — it passes either way, by design).Unblocks #1535's remaining tenant/database picker work.
Part of #1536.
🤖 Generated with Claude Code