Repository navigation
Desktop: live database switcher + client-side routing (ADR-053) - #1598
Conversation
Wire the desktop app to the daemon's local-database registry so a user can create, register, rename, remove, and switch between local databases from the sidebar and Settings. - GrpcClient stamps the x-ns-database-id routing header via a concrete DatabaseIdInterceptor on the routed data-plane clients (node, import, embeddings, agent_session); settings, local_agent, and database_service stay unrouted. set_active_database rebuilds only the routed clients over the same channel and bumps a generation the node-event watcher observes to re-open its WatchNodes stream against the newly-active database. - Move DATABASE_ID_HEADER into nodespace-proto (the shared wire crate) and re-export it from the daemon so client and server share one canonical key. - New database Tauri commands (list/create/register/set_default/rename/remove/ set_active) wrapping DatabaseService. - The watcher now rides the shared GrpcClient and stamps each event's originating database_id onto the Tauri payload; the frontend drops events tagged for a database it is no longer viewing. - database.svelte.ts store: load/switchTo/create/register/rename/setDefault/ remove. Switching flushes pending writes, re-points the routed clients, clears the node and structure-tree caches, resets the workspace to the new database's daily journal, and reloads the sidebar. - database-switcher.svelte in the sidebar header and a database management section in Settings, both driven by the store and reusing the design-system dropdown, dialog, input, and button primitives. - Delete the orphaned restart_app command. Implements the desktop half of #1533. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
APPROVE (confirming re-review) Independently traced the switch/re-subscribe path end-to-end and verified the risky areas. The switch/re-subscribe path is race-free at the Rust level. Also verified:
Four non-blocking review findings addressed in this commit:
Validation: Community build unchanged: a fresh install has one default database; with no switch the routed clients carry an empty interceptor and behavior is identical to before. |
|
APPROVE (post-merge — opened and merged between watcher polls; reviewing for the record). Well-designed and defensively coded; the two things most likely to break here are both handled correctly. The event-filtering guard is correct AND community-safeThe risk with
The switch flow orders writes safely
Honestly-flagged residual race (documented + deferred — acceptable)The code comments a known narrow race: a read (e.g. Other checks
Follow-up (matches the impl's own note)No live GUI run was possible headless — the flush/clear/reset/reload + watcher re-subscribe path is unit- and type-checked but not click-tested on a two-database build. Recommend a manual click-test on a build with 2 registered databases (switch back-and-forth, confirm no cross-DB node bleed in the tree or search, confirm pending edits land in the right DB) before relying on it in a demo. Non-blocking. Net: correct, community-safe desktop slice of #1533. Approve. |
Summary
Desktop half of ADR-053 "One Daemon, Multiple Local Databases" (#1533). Adds a sidebar database switcher and client-side
x-ns-database-idrouting to the Tauri app, so a user can create, register, switch, and manage local databases live — no restart. Builds on the merged daemon side (#1532) and CLI half (#1597).This is the desktop slice; it does not close #1533 (any remaining polish tracked separately).
Changes
GrpcClientrouting (services/grpc_client.rs) — a concreteDatabaseIdInterceptor(mirroring the CLI's) stampsx-ns-database-idon the routed data-plane clients (node/import/embeddings/agent_session); settings/local_agent/database_service stay unrouted.set_active_database(id)rebuilds only the routed clients over the same channel (no reconnect) and bumps a generationwatch;subscribe_active_database()feeds the watcher.for_iddegrades an unparseable id to no-routing rather than poisoning requests.DATABASE_ID_HEADERmoved topackages/proto/src/lib.rsand re-exported from the daemon'sdb_routing.rs, so the daemon and every client (CLI, desktop) reference one canonical key.nodespace_daemon::DATABASE_ID_HEADERstill resolves (re-export), so the CLI is unaffected.watcher.rs) — now rides the sharedGrpcClient's routed node client (soWatchNodescarries the active-database header) andselect!s on the generationwatch, re-opening the stream immediately on a switch. Each event's originatingdatabase_idis threaded onto the Tauri payloads.commands/database.rs) —list_databases,create_database,register_database,set_default_database,rename_database,remove_database,set_active_database.database.svelte.tsstore (load,switchTo= flush pending → re-point → clear caches → reset workspace → reload, plus create/register/rename/setDefault/remove);database-switcher.sveltein the sidebar header (active db + local/synced glyph; dropdown lists databases with New…/Open…);database-name-dialog.svelte(New/Rename);database-settings.svelterewritten as a management list; and anisActiveDatabaseEventdatabase_idguard on all six node/relationship listeners intauri-sync-listener.ts(empty id = Pro single-db = always applies).restart_appcommand + its registration (zero callers after the earlier database-settings cleanup;graceful_shutdownis retained).Validation
bun run test: 3965 passed / 151 files (baseline 3952/150; +13 newdatabase.test.ts, zero regressions).bun run quality:fix/ svelte-check: 0 errors / 0 warnings.cargo build --bin nodespaced --bin nodespacesucceeds;cargo clippy -p nodespace-app --testsandcargo check -p nodespace-app --testsclean;cargo fmt --checkclean.Notes
watcher::runsignature gained aGrpcClientparam (it rides the shared channel now instead of opening its own); the twooptimistic_echo_race_test.rscall sites were updated.