Repository navigation
Closed
Description
Overview
Implements the daemon core of ADR-053 (One Daemon, Multiple Local Databases — ../nodespace-docs/decisions/053-one-daemon-multiple-databases.md). The daemon currently opens exactly one database, resolved once at boot, with every service built as a per-process singleton. This issue makes the daemon serve N registered databases concurrently behind its existing single socket.
Problem Statement
resolve_db_path()(packages/daemon/src/lib.rs) reads only theNODESPACED_DB_PATHenv var (hard-coded into the launchd plist / systemd unit bydaemon_setup.rs) or the default path. Theactive_database_pathfield in~/.nodespace/daemon.tomlis written by the Settings UI but never read — "Open Database…" is a silent no-op.build_services()(packages/daemon/src/main.rs) constructs oneSqliteStore, oneNodeService, and oneServiceBundleper process. No gRPC request or event carries a database identifier.
Proposed Solution
Per ADR-053 §1–3: a DatabaseManager holding a registry plus a map of open per-database service sets, gRPC metadata routing with default-database fallback, and a new DatabaseService RPC surface. Greenfield rules — delete the dead machinery, no compatibility shims.
Implementation Approach
Registry and lifecycle
- Add
[[databases]]entries to~/.nodespace/daemon.toml:id(ULID),name,path,created_at,last_opened_at, plus adefault_databaseid. First boot with no registry auto-registers~/.nodespace/database/nodespace.dbunder a default (user-renamable) name. DatabaseManager:RwLock<HashMap<DatabaseId, Arc<DatabaseServices>>>+ registry. Databases open lazily on first request; local-only databases may idle-close. Handle registered-but-missing files by surfacing a "missing database" status — never auto-delete registry entries.- Refactor
build_services()intobuild_database_services(db_path, shared)(per-database:SqliteStore,NodeService+ seeding,NodeEmbeddingService,EmbeddingProcessor, agent event watcher,GraphContextAssembler, import handler) andbuild_shared_services()(process-global: embedding modelArc<EmbeddingService>, chatCompositeModelManager,PtySessionManager, settings, tray). sqlite-vec registration (ensure_sqlite_vec_registered) is already process-global and multi-database-safe — keep theOnceCellexactly as is.
Routing
- Tonic interceptor reads
x-ns-database-idmetadata, resolves viaDatabaseManager(lazy-open), injectsArc<DatabaseServices>as a request extension. Absent header → default database so existing clients keep working. - New
database_service.proto:List,Create(name, path?),Register(path),Remove(unregister only, never deletes files),SetDefault,Rename, plus per-database status (open/closed/missing/sync-bound). Add toBaseServicesso ADR-043's compile-time completeness extends it to the Pro daemon. - Every server-streamed event envelope gains
database_id.
Deletions (greenfield)
- Delete
active_database_pathfromDaemonConfigand itsUpdateDaemonConfighandling (packages/daemon/src/services/settings_service.rs). - Delete
NODESPACED_DB_PATHinjection from plist/systemd/Windows generation inpackages/desktop-app/src-tauri/src/daemon_setup.rs; keep the env var only as a test override mapping to a synthetic single-entry registry.
Acceptance Criteria
- Two databases can be created, registered, and served concurrently by one daemon process (integration test)
- Requests without the metadata header route to the default database; CLI and app work unchanged against it
-
DatabaseServiceRPCs work end-to-end (list/create/register/remove/set-default/rename/status) - Event streams carry
database_idand are filterable per database -
active_database_pathand the plistNODESPACED_DB_PATHinjection are gone - Named Pipe (Windows) path gets the same routing coverage as UDS
- Tests pass (bun run test:all)
- Code passes bun run quality:fix
Technical Specifications
Reference Files
- DB path resolution:
packages/daemon/src/lib.rs—resolve_db_path() - Service assembly:
packages/daemon/src/main.rs—build_services(), serve loops - Router factory:
packages/daemon/src/router.rs—BaseServices(ADR-043) - Settings service:
packages/daemon/src/services/settings_service.rs—DaemonConfig - Service files:
packages/desktop-app/src-tauri/src/daemon_setup.rs— plist/systemd writers - Store init:
packages/core/src/db/sqlite_store.rs—ensure_sqlite_vec_registered(),SqliteStore::new
Implementation Details
- User-facing term is "database" (ADR-053 §2). Avoid
Workspace*naming in core —WorkspaceContextinpackages/core/src/ops/context_ops.rsalready means AI prompt context. - The embedding model
Arc<EmbeddingService>is deliberately decoupled from stores (NodeEmbeddingService::newtakes model and store as separate args) — one model instance backs all databases. - Coordinate with the god-object split (Split the sqlite_store and node_service god-objects by concern #1503), daemon-readiness contract (Establish one daemon-readiness contract to stop per-call-site startup races #1525), and socket bind race (Close the UDS socket bind-to-chmod race in the daemon #1506) — they touch the same startup code; sequence to avoid double refactors.
Related Issues
- Split the sqlite_store and node_service god-objects by concern #1503
- Establish one daemon-readiness contract to stop per-call-site startup races #1525
- Close the UDS socket bind-to-chmod race in the daemon #1506
Non-Goals
Client UX (switcher, CLI flags), compute fairness, and sync lifecycle — follow-on issues.
Activity
mstomar125 commentedon Jul 7, 2026
Picked up now (2026-07-07) as a compiling foundation scaffold (DatabaseService proto + registry/
DatabaseManagertypes) → draft PR.The full implementation is XL / multi-day and is not landable today. It converts every service handler from a captured
Arc<CoreNodeService>to per-requestArc<DatabaseServices>resolution (all 6 impls + both streaming RPCs + every daemon integration test), plus a new 7-RPC proto service, a persistent registry with lazy-open/idle-close/missing-file lifecycle, thebuild_servicessplit,database_idevent-envelope plumbing, and greenfield deletions that ripple into the desktop Tauri commands and test harnesses.This is the ADR-053 foundation that #1533, #1534, #1535, and #1537 all depend on — sequencing it first is why the others are parked.
ADR-053 daemon multi-database: registry scaffold + build_services spl…
mstomar125 commentedon Jul 9, 2026
Progress update — daemon routing foundation landed (Stages 1–5)
The daemon-side foundation of ADR-053 is now on
mainacross four merged PRs. All of it is behavior-preserving for the current single-database product and touches no cross-repo contract (BaseServices/build_base_router/ service constructors are unchanged), sonodespaced-prois unaffected.Merged
DatabaseManager:databases.toml, ids, default) + splitbuild_services()intobuild_shared_services()(process-global: embedding model over a watch channel, PTY manager, settings) andbuild_database_services(db_path, &context)(per-database store/node-service/grpc/assembler/import + per-database embedding wiring).DatabaseManagergainsensure_default_registered,resolve_database_id(absent → default; unregistered → error), and lazyget_or_openthat builds + caches anArc<DatabaseServices>(double-checked).DbManagerLayer(a tower layer, installed only by the community serve loops) injects theDatabaseManagerinto request extensions;NodeServicehandlers resolvex-ns-database-idand route to the target database. The default database is opened through the manager and cloned intoBaseServices(never opened twice). Proven byroutes_requests_by_database_header(a node written to a second database is invisible to the default).ImportService,EmbeddingsService, andAgentSessionService(launch_sessiononly — thePtySessionManageris process-global; a session is addressed by id, not database).Acceptance criteria status
test:all/test:e2egreen on every PR;quality:fixclean.DatabaseServiceRPCs (list/create/register/remove/set-default/rename/status) — not started.database_id— not started.active_database_path+ plistNODESPACED_DB_PATHinjection — not started.Remaining work (gated)
DatabaseServicegRPC server — this is the reachable path that makes routing user-visible (until it exists, production always resolves to the single default, so routing is exercised only in tests). It adds a service toBaseServices, which under ADR-043 is a cross-repo change requiringnodespace-synclock-step — to be scheduled with sign-off, not landed unilaterally.LocalAgentServicerouting — deferred deliberately: its model manager is process-global (pending a hoist-to-shared refactor) while only chat-turn processing is per-database; it will be routed together with that refactor.database_id, and removal ofactive_database_path/NODESPACED_DB_PATH.Keeping this issue In Progress; the foundation is complete and the next step is the cross-repo
DatabaseServiceserver.mstomar125 commentedon Jul 9, 2026
Progress — DatabaseService gRPC server (the reachable multi-database path)
Building the piece that makes ADR-053 routing user-visible. Until now a client had no way to register a second database, so the Stage 1–5 routing was exercised only in tests; production always resolved to the single default.
Core — PR #1592 (open, CI running):
DatabaseServiceImplwrapping the existingDatabaseManager:List/Create/Register/Remove/SetDefault/Renameover the already-generated proto.x-ns-database-id. Wired intoBaseServices+build_base_router+ all four serve loops, cloning the manager already opened for the default (no double-open).fmt/clippy --all-targetsclean;cargo test -p nodespace-daemon51 lib (+3 new unit tests) + all integration suites green. New e2e over the real tonic transport (database_service_e2e.rs): theDbManagerLayerinjects the manager over the wire →Createregisters a 2nd database → a header-routedNodeServicewrite lands in it (visible with the header,NotFoundwithout — real isolation), the 2nd database flips toOpen, and an unregistered header is rejected.Cross-repo (ADR-043) — sync prepared, pending core merge:
Adding
databasetoBaseServicesis the intended compile-time contract. Thenodespaced-prochange is ready in the working tree: bump the core pin, seed aDatabaseManagerwith the active database as default, provideDatabaseServiceImpl. Design decision: the Pro daemon installs no routing layer — itsbuild_database_servicesbundle hides the rawNodeServicehandle the sync layer needs, and installing a layer over a manager it didn't build its bundle through would double-open the same SQLite file. So on Pro the service is a truthful registry view of the single active database (Listreports it); serving multiple local databases under one cloud-sync session is an explicit deferral (undefined tenant mapping). Pro's data/sync path is byte-for-byte unchanged. It lands as a coordinatednodespace-syncPR once #1592 merges.Acceptance criteria after this lands: ✅ DatabaseService RPCs. Remaining: event-envelope
database_idand removal of the single-databaseactive_database_path/NODESPACED_DB_PATHassumption — next.mstomar125 commentedon Jul 9, 2026
✅ DatabaseService server landed (core merged + sync lock-step PR up)
b82c899c). Independent review confirmed the adapter correctness, the unregister-onlyremove(no data-destruction path), the real transport-level e2e, and endorsed the design (compile-requiredBaseServicesfield + process-global/not-routed). CI green.nodespaced-probumps its core pin tob82c899cand providesDatabaseServiceImplbacked by a manager seeded with its active database. NoDbManagerLayeron Pro (its data/sync path is unchanged; multi-DB-under-one-cloud-session deferred). Validated: builds against the merged core, 45 tests green, clippy + fmt clean.Acceptance criteria: ✅ default-header routing · ✅ Windows serve-loop wiring · ✅ DatabaseService RPCs · 🟡 concurrent serving (unit + transport e2e) · ⬜ event
database_id· ⬜ removeactive_database_path.Next (to close this epic): event-envelope
database_idand migrating the Settings DB-path display toDatabaseService.Listso the vestigialactive_database_path/ plistNODESPACED_DB_PATHsingle-database assumption can be removed.mstomar125 commentedon Jul 9, 2026
✅ DatabaseService coordinated pair fully merged + Stage 6 (event database_id) up
b82c899c) + sync Implement OrderedListNode (Auto-Numbered Lists) #294 MERGED (f126d59) — the DatabaseService server and its ADR-043 lock-step land as a coherent pair with no half-wired window.nodespaced-pronow providesDatabaseServiceImpl(registry view of its single active DB; no routing layer; data/sync path unchanged).database_id): the protoNodeEventgains an additivedatabase_id, stamped onto everyWatchNodesevent by the routedNodeServiceImpl.new()is unchanged (Pro/tests unaffected). e2e proves each database's watch stream carries its own id. CI running.Acceptance criteria: ✅ default-header routing · ✅ Windows serve loops · ✅ DatabaseService RPCs · ✅ concurrent serving (unit + transport e2e) · 🟡 event
database_id(#1593 in review) · ⬜ removeactive_database_path+ plistNODESPACED_DB_PATHinjection (last criterion, in progress).mstomar125 commentedon Jul 9, 2026
✅ Stage 6 merged — core #1593 (
7fe5a896):WatchNodesevents now carry the serving database'sdatabase_id. Additive + non-breaking (Pro inherits the proto field on its next pin bump; its single-DB streams carry an empty id, as documented).Only remaining criterion: remove
active_database_path+ the plist/systemdNODESPACED_DB_PATHinjection (in progress — the daemon already defaults to the exact injected path, so removing the injection doesn't move the DB). Once that lands, all acceptance criteria are met and this epic closes.mstomar125 commentedon Jul 9, 2026
Stage 7 (last criterion) split into two — first half up as #1594
#1594 (open): removes the redundant
NODESPACED_DB_PATHinjection from the launchd plist + systemd unit. Verified safe — the daemon'sresolve_db_path()default is the identical path, so the DB location is unchanged.Remaining half — remove
active_database_path: scoped after investigation. Findings:active_database_path(indaemon.toml/ theSettingsServicedaemon-config RPCs) is vestigial — the daemon picks its database viaresolve_db_path()+ the registry and never reads it.select_new_database/reset_database_to_defaulttauri commands are therefore effectively no-ops (the daemon ignores the value they set), and their Settings→Database buttons are wired to those broken commands.Plan for that half: drop
active_database_pathfrom the settings proto + daemon config; re-source the path display fromDatabaseService.List(default entry) via a new tauri command (keeping the display working); delete or migrate the no-op select/reset commands + their buttons. This touches the settings proto + tauri command layer + the frontend (withbun run test), so it lands as its own focused change rather than being rushed — the multi-database capability (routing + DatabaseService + eventdatabase_id) is already fully merged; this is the config/UX cleanup tail. One UX call to confirm: under the registry model, "select database" should become "register + set default" — or the already-broken buttons are simply removed as dead code.mstomar125 commentedon Jul 9, 2026
Resolved — ADR-053 daemon core complete
The daemon now serves N registered databases concurrently behind its single socket, with a full
DatabaseServiceRPC surface, metadata-based routing (default-database fallback), and per-database event stamping. The Pro daemon (nodespaced-pro) providesDatabaseServicein lock-step via ADR-043's compile-time completeness.Acceptance criteria
packages/daemon/tests/database_service_e2e.rs::create_second_database_then_route_a_write_to_itdrives a real tonic transport with the DbManager tower layer +DatabaseService+NodeService, creates a second database, header-routes a write to it, and asserts isolation +NotFoundon an unknown id. (ADR-053 daemon multi-database: registry scaffold + build_services split (#1532) #1572, ADR-053: DatabaseService gRPC server (local-database registry) #1592)x-ns-database-id, falling back to the registry default when the header is absent. (ADR-053 daemon multi-database: registry scaffold + build_services split (#1532) #1572 stages 1–3, ADR-053 Stage 4: DatabaseManager lazy open + service-assembly extraction #1589 stage 4)DatabaseServiceRPCs end-to-end (list/create/register/remove/set-default/rename/status) —DatabaseServiceImplimplements all six RPCs plus per-database status; covered by unit tests (create_list_set_default_rename_remove_round_trip,mutations_on_unknown_id_are_not_found,register_reports_missing_for_absent_file) and the e2e test. (ADR-053: DatabaseService gRPC server (local-database registry) #1592)database_id, filterable per database —NodeEventgaineddatabase_id; the watch handler stamps each event with the serving database's id, verified bywatch_events_are_stamped_with_the_serving_database_id. (ADR-053: stamp WatchNodes events with the serving database id #1593)active_database_pathand the plistNODESPACED_DB_PATHinjection are gone — plist/systemd injection removed (ADR-053: stop injecting NODESPACED_DB_PATH from the daemon service definitions #1594); the vestigialactive_database_pathfield removed fromDaemonConfig/proto and its no-op Tauri commands/UI deleted, with the read-only path display re-sourced fromDatabaseService.List's default entry (Remove vestigial active_database_path daemon setting (ADR-053) #1595).bun run test:allpasses — green on CI for every PR in the epic, including Remove vestigial active_database_path daemon setting (ADR-053) #1595.bun run quality:fixclean —cargo fmt/clippy+ eslint/svelte-check clean across all PRs.Pro lock-step
nodespaced-proseeds a single-active-databaseDatabaseManagerand providesDatabaseServiceImpl(no routing layer — building the default bundle over a manager whose per-database services the Pro sync layer needs would double-open the same SQLite file; the second registered database is intentionally inert for now). (nodespace-sync Implement OrderedListNode (Auto-Numbered Lists) #294)PRs
DatabaseServicegRPC server + ADR-043 Pro lock-stepdatabase_idNODESPACED_DB_PATHinjectionactive_database_pathDeferred (non-goals per this issue / ADR-053)
Client UX (database switcher, CLI flags), compute fairness, sync lifecycle for the second database, and
local_agentper-database routing (bundled with a future model-manager hoist) are follow-on work, out of scope here.