Repository navigation
ADR-053 daemon multi-database: registry scaffold + build_services split (#1532) - #1572
mstomar125 merged 2 commits into
Conversation
Foundation scaffold for the daemon-side of ADR-053 ("One Daemon, Multiple
Local Databases"). Adds the DatabaseService gRPC surface and the database
registry/manager types without touching service assembly, routing, or the
Pro daemon lock-step — those land in later stages.
## Completed in This Session
- [x] Stage 1 (proto): new packages/proto/proto/database_service.proto with
DatabaseService { List, Create(name, path?), Register(path), Remove
(unregister-only, never deletes files), SetDefault, Rename } and a
DatabaseStatus enum (Open/Closed/Missing) surfaced in List/DatabaseInfo.
Added to the compile list in build.rs and re-exported the generated
client/server + messages from packages/proto/src/lib.rs, mirroring the
SettingsService re-exports. node_service.proto / settings_service.proto
untouched.
- [x] Stage 2 (registry + manager types): new
packages/daemon/src/services/database_manager.rs with a DatabaseId ULID
newtype, serde DatabaseEntry{id,name,path,created_at,last_opened_at}, a
Registry{databases, default_database} that loads/saves a dedicated
~/.nodespace/databases.toml (kept separate from SettingsService's
daemon.toml so the [capture] section is never clobbered), and a
DatabaseManager { registry: RwLock<Registry>, open: RwLock<HashMap<
DatabaseId, ()>> }. Method stubs list/create/register/remove/set_default/
rename mutate and persist the registry; get_or_open returns a clear
"not yet wired" anyhow error (no todo!()/unimplemented!()). Registered in
services/mod.rs.
## Remaining Work
- [ ] Stage 3: split build_services() into build_shared_services()
(process-global: embedding model, chat CompositeModelManager,
PtySessionManager, settings, tray) and build_database_services(db_path,
shared) (per-database: SqliteStore, NodeService + seeding,
NodeEmbeddingService, EmbeddingProcessor, agent watcher,
GraphContextAssembler, import handler). Coordinate with the god-object
split so the refactor is not done twice.
- [ ] Stage 4: tonic interceptor reading x-ns-database-id metadata, resolving
via DatabaseManager::get_or_open (lazy open), injecting the per-database
service set as a request extension. Absent header routes to the default
database so existing single-database clients keep working.
- [ ] Stage 5: implement the DatabaseService gRPC handler over DatabaseManager
and add DatabaseServiceServer to BaseServices in router.rs. This extends
ADR-043's compile-time completeness to the Pro daemon, so land it in
lock-step with nodespace-sync's nodespaced-pro.
- [ ] Stage 6: add database_id to every server-streamed event envelope and make
the streams filterable per database.
- [ ] Stage 7: greenfield deletions — drop active_database_path from
DaemonConfig and its UpdateDaemonConfig handling; delete the
NODESPACED_DB_PATH injection from the plist/systemd/Windows writers in
daemon_setup.rs (keep the env var only as a test override mapping to a
synthetic single-entry registry); give the Windows Named Pipe path the
same routing coverage as the UDS path.
## Current State
- Files added: packages/proto/proto/database_service.proto,
packages/daemon/src/services/database_manager.rs
- Files modified: packages/proto/build.rs, packages/proto/src/lib.rs,
packages/daemon/src/services/mod.rs, packages/daemon/Cargo.toml (ulid dep),
Cargo.lock
- Build: cargo build -p nodespace-proto -p nodespace-daemon — clean
- Lint: cargo clippy -p nodespace-daemon --all-targets -- -D warnings — clean
- Format: cargo fmt --all --check — clean
- Known issues: none. The scaffold compiles and is not yet wired into main.rs
service assembly, the router, or the interceptor — intentionally, to keep
compilation and the sync lock-step green.
- Dependencies: added ulid = "1" for ULID DatabaseId generation.
## Context for Next Session
The registry/manager and proto surface are the low-risk foundation of ADR-053.
The manager persists to its own databases.toml and never touches daemon.toml.
get_or_open is the seam for the per-database service split (Stage 3) and the
routing interceptor (Stage 4); wiring DatabaseServiceServer into BaseServices
(Stage 5) is the point that requires a coordinated nodespace-sync change.
## Acceptance Criteria Status
- [ ] Two databases served concurrently by one daemon (Stages 3-5)
- [ ] Header-less requests route to the default database (Stage 4)
- [ ] DatabaseService RPCs work end-to-end (Stage 5; proto + manager scaffolded)
- [ ] Event streams carry database_id (Stage 6)
- [ ] active_database_path and the plist NODESPACED_DB_PATH injection removed
(Stage 7)
- [ ] Named Pipe path gets the same routing coverage as UDS (Stage 7)
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Splits the daemon's single build_services() into build_shared_services()
(process-global) and build_database_services(db_path, &shared) (per-database),
the seam the multi-database routing needs. Behavior-preserving for the single
default database served today.
## Completed in This Session
- [x] SharedServices { pty_manager, settings, model, has_model } +
build_shared_services(): PTY manager and daemon settings are now
process-global, and the embedding model is loaded ONCE for the whole
process and published over a tokio watch channel.
- [x] DatabaseServices + build_database_services(db_path, &shared): per-database
SqliteStore, NodeService (+ seeding), gRPC handlers, GraphContextAssembler,
import, local-agent event watcher, and the per-database embedding state.
Consumes the shared PtySessionManager instead of constructing its own.
- [x] Embedding model decoupled from stores (ADR-053 "one model backs all
databases"): load_embedding_model_bg split into
load_shared_embedding_model_bg (loads the raw model once, publishes over
watch) and wire_database_embeddings_bg (awaits the shared model, then wires
that database's NodeEmbeddingService + EmbeddingProcessor and the waker).
- [x] All four serve loops (headless/tray x unix/windows) call
build_shared_services then build_database_services; settings now comes from
the shared set. cargo fmt/clippy (-D warnings) clean; daemon tests 71/71
(incl. grpc_round_trip + agent_session end-to-end).
## Remaining Work
- [ ] Hoist the chat CompositeModelManager to shared: it is currently built
inside LocalAgentServiceImpl::new (per-database), not in build_services,
so sharing it needs a LocalAgentServiceImpl constructor change — deferred
to keep this a focused split. Per-database is behaviorally identical for
the single database served today.
- [ ] Stage 4: tonic interceptor reading x-ns-database-id, resolving via
DatabaseManager::get_or_open (store the DatabaseServices in the manager's
open-map, replacing the () placeholder), injecting the per-database set as
a request extension; absent header routes to the default database.
- [ ] Stage 5: DatabaseService gRPC handler + DatabaseServiceServer on
BaseServices (needs the nodespace-sync lock-step).
- [ ] Stage 6: database_id on event envelopes. Stage 7: drop active_database_path
/ NODESPACED_DB_PATH; Windows Named Pipe routing parity.
## Current State
- Files modified: packages/daemon/src/main.rs (+139/-58).
- Build/tests: cargo build -p nodespace-daemon clean; fmt + clippy -D warnings
clean; cargo test -p nodespace-daemon 71/71 pass.
- Known issues: none. The split is behavior-preserving for one database; the
DatabaseManager open-map still holds () (wired in Stage 4).
## Context for Next Session
build_shared_services / build_database_services are the seam Stage 4 routes
through. The shared model handoff uses a watch::Receiver<Option<Arc<EmbeddingService>>>
so each database's wiring task awaits the one model. Next: store DatabaseServices
in DatabaseManager.open and add the x-ns-database-id interceptor.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
APPROVE Reviewed the full diff at Stage 1–2 scaffold — dormant + data-safe:
Stage 3
Staging discipline (healthy): Stage 5 (the CI green — |
Foundation for ADR-053 (One Daemon, Multiple Local Databases). Two incremental, low-risk stages of #1532; the multi-database routing that consumes them lands next.
Stage 1–2 — proto + registry (dormant scaffold)
packages/proto/proto/database_service.proto:DatabaseService { List, Create(name, path?), Register(path), Remove (unregister-only, never deletes files), SetDefault, Rename }+ aDatabaseStatusenum (Open/Closed/Missing). Wired intobuild.rsand re-exported frompackages/proto/src/lib.rs.packages/daemon/src/services/database_manager.rs:DatabaseId(ULID) +DatabaseEntry+ aRegistrypersisted to a dedicated~/.nodespace/databases.toml(kept separate fromSettingsService'sdaemon.toml), and aDatabaseManagerholding the registry plus an open-databases map. Registry mutations (create/register/remove/set_default/rename) are implemented and persist;get_or_openreturns a clear "not yet wired" error (notodo!()), since the per-database service set it hands back is assembled in Stage 3+.The scaffold compiles and is not yet wired into service assembly or routing — intentional, to keep the sync lock-step green until Stage 5.
Stage 3 — split
build_services()into shared + per-databaseThe seam the routing needs.
build_services()becomes:build_shared_services()→ process-global (PtySessionManager, daemon settings) plus the embedding model loaded once for the whole process and published over atokio::watchchannel.build_database_services(db_path, &shared)→ per-databaseSqliteStore,NodeService(+seeding), gRPC handlers,GraphContextAssembler, import, local-agent watcher, and per-database embedding state — consuming the shared PTY manager rather than making its own.load_shared_embedding_model_bg(loads the raw model once, publishes overwatch) andwire_database_embeddings_bg(each database awaits the shared model, then wires its ownNodeEmbeddingService+EmbeddingProcessor+ waker).build_shared_servicesthenbuild_database_services; settings now comes from the shared set.Behavior-preserving for the single default database served today.
Verification
cargo build/fmt/clippy -p nodespace-daemon --all-targets -- -D warningsclean.cargo test -p nodespace-daemon71/71 — includinggrpc_round_tripandagent_sessionend-to-end suites that exercise the assembled services.main.Not in this PR (follow-on, tracked under #1532)
CompositeModelManagerto shared (it's built insideLocalAgentServiceImpl::new, per-database — needs a constructor change; behaviorally identical for one database).x-ns-database-idinterceptor + storingDatabaseServicesinDatabaseManager.open.DatabaseServicehandler +DatabaseServiceServeronBaseServices(needs the nodespace-sync lock-step). Stages 6–7:database_idon event envelopes; dropactive_database_path/NODESPACED_DB_PATH+ Windows pipe parity.Part of #1532.