Skip to content

Multi-database polish: tray database menu, multi-window, and docs reconciliation #1536

Closed

Description

@malibio

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.md describe the pre-Supabase backend; tenant-database-schema.md and sync-telemetry.md still 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's database_id to 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.md for 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.md against 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.md and sync-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 in src-tauri/src/lib.rs
  • Docs: ../nodespace-docs/architecture/, ../nodespace-docs/decisions/README.md

Dependencies

Related Issues

Non-Goals

New sync features; per-window theming; anything beyond routing existing events to the right window.

Activity

  1. added
    documentation
    on Jul 5, 2026
  2. mstomar125 commented on Jul 10, 2026

    @mstomar125
    Contributor

    Docs reconciliation slice done — committed directly to nodespace-docs main (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):

    • Full Supabase rewrites (were pre-Supabase / SurrealDB-based): billing-enforcement.md, data-deletion-offboarding.md, cloud-sync-error-handling.md — Worker-brokered signin + Workers-KV subscription state + Stripe webhooks; member_of RLS replacing the Stamped-ACL access_tags/held_tags model; offboarding = DROP SCHEMA tenant_{id} CASCADE.
    • ADR-045 (no cloud embeddings): removed the cloud embeddings table + HNSW index + RLS/grants from tenant-database-schema.md, and the embeddings telemetry category from sync-telemetry.md.
    • ADR-053 (N databases): added the metadata-routing / single-active-session / tenant=database=billable-unit model to daemon-cli-overview.md, data-layer.md, cloud-sync.md, system-overview.md.
    • ADR-051 (rate-limiting): rate-limiting.md re-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)

    1. billing-enforcement.md spells out KV subscription-record shape + session_version revocation in more detail than ADR-051 states — consistent with the ADR, but confirm it matches the intended Worker implementation.
    2. rate-limiting.md keeps 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)

    • Tray database submenu (packages/daemon/src/tray.rs) — list registered databases, indicate active/synced, "Open NodeSpace on ". Needs on-device validation.
    • Multi-window (optional) — window-per-database routing off the event database_id; can be split into its own issue if it grows.
  3. mstomar125 commented on Jul 10, 2026

    @mstomar125
    Contributor

    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/muda menu rebuilds are platform-sensitive (the tray is deliberately built inside the event-loop Init for 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)

    • Thread Arc<DatabaseManager> into tray::run's seed closure (already in scope at main.rs where tray::run is called). At Init, fetch the initial DatabaseManager::list() -> RegistrySnapshot (bridge the async call via the tokio runtime handle) and build a "Databases" submenu: one MenuItem per registered database, labeled with the name + an active/synced marker (active = default/selected, synced = has a bound tenant). Keep a MenuId -> DatabaseId map on TrayState.
    • On a submenu click, open_ui() gains a target: spawn the UI child with NODESPACE_INITIAL_DATABASE=<id> in its env (reuse the existing "open if absent, else leave to OS focus" logic).
    • Live updates: add TrayEvent::DatabasesChanged(RegistrySnapshot), pushed from the DatabaseService register / remove / set_default handlers (mirror the existing RpcStateChanged → Status-label pattern), and rebuild the submenu on receipt.

    Frontend (packages/desktop-app)

    • On boot, read the initial-database selection (expose the daemon env/field via a small Tauri command) and, if set, call 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_id to 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-docs bcd142c); this issue stays open for the tray work above.

  4. mstomar125 commented on Aug 11, 2026

    @mstomar125
    Contributor

    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.

    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::run owns a !Send main-thread event loop seeded before the gRPC server starts, and builds a static menu with no access to DatabaseManager — 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_database from #1533), so "Open NodeSpace on X" can select the database rather than needing a whole new startup path.

  5. self-assigned this
    on Aug 12, 2026
  6. mstomar125 commented on Aug 12, 2026

    @mstomar125
    Contributor

    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::run owns the main thread and is already running before the gRPC side builds the DatabaseManager — 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 sets NODESPACE_INITIAL_DATABASE on 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.

    ⚠️ Correction for anyone reading the 2026-07-10 design comment: it states Arc<DatabaseManager> is "already in scope at main.rs where tray::run is 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_reaper closes idle databases during normal use, so an open marker would be confidently wrong most of the time, which is worse than absent. default and synced change 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cleanupdocumentationui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions