Repository navigation
Closed
Closed
Copy link
Labels
Description
Overview
Final slice of ADR-053 (../nodespace-docs/decisions/053-one-daemon-multiple-databases.md): surface databases in the tray, optionally open databases in separate windows, and reconcile the architecture docs that still describe the single-database world (plus pre-existing sync-doc drift).
Problem Statement
- The daemon tray has a single "Open NodeSpace" entry that relaunches one UI on the implicit database.
- The app is single-window; all backend emits target
get_webview_window("main"). - Several docs still describe superseded architecture:
billing-enforcement.md,data-deletion-offboarding.md,cloud-sync-error-handling.mddescribe the pre-Supabase backend;tenant-database-schema.mdandsync-telemetry.mdstill model the cloud embeddings table removed by ADR-045; daemon/data-layer docs describe one database per daemon.
Proposed Solution
Tray database submenu; window-per-database built on the database_id already present in event streams; a docs pass that rewrites the drifted files against the current Supabase + per-database-billing architecture.
Implementation Approach
Tray
- Database submenu in
packages/daemon/src/tray.rs: list registered databases, indicate active/synced, "Open NodeSpace on ".
Multi-window (optional within this issue — split if it grows)
- Window label = database id; each window pins its own database id and stamps it on calls.
- Replace hardcoded
get_webview_window("main")emits with routing by the event'sdatabase_idto the matching window (fallback: focused window). - Window state (size/position) persisted per database.
Docs (nodespace-docs, direct commits to main)
- Update
architecture/daemon-cli-overview.md,daemon-cli-lifecycle.md,daemon-cli-protocol.md,data-layer.md,cloud-sync.mdfor the N-database model, metadata routing, single-active sync, and per-database identity/billing. - Rewrite
billing-enforcement.md,data-deletion-offboarding.md,cloud-sync-error-handling.mdagainst Supabase (ADR-036) with tenant = database = billable unit (ADR-053) — the old branch rewrite was still SurrealDB-based and was discarded. - Remove embeddings-table remnants from
tenant-database-schema.mdandsync-telemetry.md(ADR-045).
Acceptance Criteria
- Tray lists databases and opens the app on the chosen one
- (If multi-window kept in scope) two windows on two databases operate concurrently without event cross-talk
- No architecture doc describes the single-database daemon, the SurrealDB backend, or a cloud embeddings table
- Docs contain no ticket references (docs standard)
- Tests pass (bun run test:all)
- Code passes bun run quality:fix
Technical Specifications
Reference Files
- Tray:
packages/daemon/src/tray.rs—open_ui,NODESPACE_UI_BINARY - Window config:
packages/desktop-app/src-tauri/tauri.conf.json; emits insrc-tauri/src/lib.rs - Docs:
../nodespace-docs/architecture/,../nodespace-docs/decisions/README.md
Dependencies
- CLI and desktop app: multiple databases with a live, restart-free switcher #1533
- Per-database cloud sync: runtime tenant binding and single-active session lifecycle #1535
Related Issues
- Daemon database manager: registry, per-database services, and gRPC routing #1532
- Per-database compute scoping: embedding queues, agent watchers, and idle eviction #1534
Non-Goals
New sync features; per-window theming; anything beyond routing existing events to the right window.
Activity
mstomar125 commentedon Jul 10, 2026
Docs reconciliation slice done — committed directly to
nodespace-docsmain (bcd142c), per this issue's direct-to-main plan. Tray submenu and multi-window remain; leaving this issue open.Docs reconciled (11 files,
architecture/)Rewrote/updated the drifted docs against the current ADRs (036 Supabase, 037 access, 045 no-cloud-embeddings, 051 rate-limiting, 053 N-databases):
billing-enforcement.md,data-deletion-offboarding.md,cloud-sync-error-handling.md— Worker-brokered signin + Workers-KV subscription state + Stripe webhooks;member_ofRLS replacing the Stamped-ACLaccess_tags/held_tagsmodel; offboarding =DROP SCHEMA tenant_{id} CASCADE.embeddingstable + HNSW index + RLS/grants fromtenant-database-schema.md, and theembeddingstelemetry category fromsync-telemetry.md.daemon-cli-overview.md,data-layer.md,cloud-sync.md,system-overview.md.rate-limiting.mdre-grounded on PostgREST (HTTP write path) + Realtime pull WebSocket, edge ruleset, Managed Challenge on the credential endpoint, deferred per-tenant write proxy.schema-migration-strategy.md: schema-per-tenant Postgres migrations (numbered.sql, idempotency guards,CREATE INDEX CONCURRENTLY).Verified: no live-architecture SurrealDB/old-model/cloud-embeddings drift remains (only history lines, explicit negations, and ADR-reference lines); no ticket numbers introduced.
Two spots worth a human skim (not blockers)
billing-enforcement.mdspells out KV subscription-record shape +session_versionrevocation in more detail than ADR-051 states — consistent with the ADR, but confirm it matches the intended Worker implementation.rate-limiting.mdkeeps the docs' existing endpoint labels (/auth/token,/provision,/invite/accept) rather than ADR-051's literal/token,/authorize,/members/invite— internally consistent across the docs; flag if you want them normalized to the ADR spelling.Remaining in this issue (open)
packages/daemon/src/tray.rs) — list registered databases, indicate active/synced, "Open NodeSpace on ". Needs on-device validation.database_id; can be split into its own issue if it grows.mstomar125 commentedon Jul 10, 2026
Tray submenu + multi-window — deferred to a co-validated session (design/seams below).
Unlike the docs slice (landed) and the other ADR-053 follow-ons this cycle (backend/frontend, all with headless test proof), the tray's core behavior — submenu populates, active/synced indicators render, a click spawns the UI on the right database, and the list updates live on register/remove — has no headless correctness proof and dynamic
tray-icon/mudamenu rebuilds are platform-sensitive (the tray is deliberately built inside the event-loopInitfor this reason). So this is device-validation-gated; building it blind risks shipping something that compiles but doesn't actually work. Holding it for a session where the UI can be exercised on-device.The implementation is scoped and ready — the seams all exist:
Tray (
packages/daemon/src/tray.rs)Arc<DatabaseManager>intotray::run's seed closure (already in scope atmain.rswheretray::runis called). AtInit, fetch the initialDatabaseManager::list() -> RegistrySnapshot(bridge the async call via the tokio runtime handle) and build a "Databases" submenu: oneMenuItemper registered database, labeled with the name + an active/synced marker (active = default/selected, synced = has a bound tenant). Keep aMenuId -> DatabaseIdmap onTrayState.open_ui()gains a target: spawn the UI child withNODESPACE_INITIAL_DATABASE=<id>in its env (reuse the existing "open if absent, else leave to OS focus" logic).TrayEvent::DatabasesChanged(RegistrySnapshot), pushed from theDatabaseServiceregister / remove / set_default handlers (mirror the existingRpcStateChanged→ Status-label pattern), and rebuild the submenu on receipt.Frontend (
packages/desktop-app)databaseStore.switchTo(id)before first paint. This is vitest-testable and is the single-window interpretation of "Open NodeSpace on " (launch/focus the one window + switch), which needs no multi-window.Multi-window (optional) — recommend splitting into its own issue. Window label = database id, route each event by its
database_idto the matching window (fallback: focused window), persist per-database window state. This is a larger, design-heavier change than the tray submenu and the issue already flags it as splittable; keeping it out of the tray slice keeps that slice shippable.On-device validation (Monday): submenu lists all registered databases with correct active/synced markers; clicking "Open on " launches/focuses the UI on that database; registering/removing a database updates the submenu live; Quit still fully shuts down.
Docs slice remains landed (
nodespace-docsbcd142c); this issue stays open for the tray work above.mstomar125 commentedon Aug 11, 2026
Splitting this, per the issue's own note that multi-window should be split if it grows. Three genuinely separable pieces were bundled here, and the docs pass (a different repo) was the largest single chunk.
database_idinstead of the hardcoded"main"window.Dependency note: this issue lists #1535 as a dependency, but that relationship is effectively inverted now. #1535's runtime tenant binding and single-active sync landed and were validated headless across three tenants; its own remaining work is explicitly "tenant/database picker UI + per-DB sync pill (needs the tray DB menu #1536)". So this is the unblocker, not the blocked one.
Shape of the remaining tray work, from a read of the current code:
tray::runowns a!Sendmain-thread event loop seeded before the gRPC server starts, and builds a static menu with no access toDatabaseManager— so the real work is getting a registry snapshot (and change notifications) into that loop and rebuilding the submenu when the registry changes. The launch side is lighter than it looks: the app already supports switching databases at runtime (set_active_database/subscribe_active_databasefrom #1533), so "Open NodeSpace on X" can select the database rather than needing a whole new startup path.List databases in the tray and open the app on the one picked (#1536) (…
mstomar125 commentedon Aug 12, 2026
Resolved in #2039 (merged to
main). With multi-window (#2033) and the docs pass (#2034) split out, the tray deliverable this issue kept is done: the tray lists every registered database and opens the app on the one picked.How it works. The registry can't be handed to the tray at startup —
tray::runowns the main thread and is already running before the gRPC side builds theDatabaseManager— so the tray is told, over the same event proxy the Status label uses. A snapshot arriving before the tray finishes initializing is held and applied once it does. Picking a database setsNODESPACE_INITIAL_DATABASEon the spawned app, which treats it as the highest-precedence choice for that launch only; a plain "Open NodeSpace" leaves it unset so the remembered selection still wins.Arc<DatabaseManager>is "already in scope at main.rs wheretray::runis called." It isn't — the manager is built later, inside the spawned task. That shaped the wrong plan.On the "indicate active/synced" criterion — ticked, but on a different fact than it names. The label shows default · synced, not open. Review established that a marker rendered once at daemon boot goes stale fast:
spawn_idle_reapercloses idle databases during normal use, so an open marker would be confidently wrong most of the time, which is worse than absent.defaultandsyncedchange only on explicit user action. A test pins the deliberate absence so restoring the open marker forces the live-refresh decision.Two limits, tracked in #2040: the submenu is rendered once at daemon boot, so a database added/removed/renamed later doesn't appear until restart; and picking a database while the app is already running is a no-op — worse, if the app was launched outside the tray there's no child to notice and the click spawns a second window instead.
Unblocks #1535's remaining tenant/database picker work.
Review caught three majors (the stale marker, a misattached doc, an item-orphaning rebuild path) and then caught that one of my own fixes broke the headline behaviour — consuming the launch id on first read made a concurrent
load()overwrite the tray's pick with the remembered database. Reverted; the concern it addressed was latent.