Skip to content

Create managed databases beside the manager's registry, not under the ambient home (closes #3780) - #3781

Merged
malibio merged 1 commit into
mainfrom
issue-3780-managed-db-registry-dir
Oct 13, 2026
Merged

malibio merged 1 commit into
mainfrom
issue-3780-managed-db-registry-dir

Conversation

@malibio

@malibio malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

DatabaseManager::create(name, None) placed the file under the ambient nodespace_dir()/database/, which follows NODESPACE_HOME or else the real home, even when the manager was loaded from a registry elsewhere. An in-process manager in a test therefore wrote into ~/.nodespace/database/: every run of packages/cli/tests/it/mcp_integration.rs (its create_database helper passes path: None three times) left three ULID-named ~1 MB databases there. 243 had accumulated on one machine.

The managed directory is now database/ beside the manager's own registry file. In the daemon the registry is <nodespace dir>/databases.toml, so the path is unchanged there; a manager loaded from a temp registry stays inside it by construction, and no test needs to remember to isolate.

Test plan

  • create_without_a_path_stays_beside_the_registry (new)
  • mcp_integration run: no new file in the real ~/.nodespace/database/
  • bun run test:changed (rust:test 316s)
  • bun run quality:fix

🤖 Generated with Claude Code

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Review Type: Pragmatic code review (initial), PR #3781, closes #3780.
Verdict: APPROVE. A small, atomic, correct fix that removes an ambient-home dependency from DatabaseManager::create. Production behaviour is unchanged.

Requirements Check

  • create with no path places the file under the registry's directory, with a test (create_without_a_path_stays_beside_the_registry, passes locally via nextest).
  • Running mcp_integration leaves ~/.nodespace/database/ unchanged. By construction: its in-process manager loads databases.toml from a temp dir, so path: None now resolves inside it. I did not run the CLI suite or the live app.
  • bun run test:changed / quality:fix clean: not verified by me; the merge gate covers it.

Verification of the points raised

  1. Production path unchanged. The only non-test constructor is open_default_database (packages/daemon/src/main.rs:104). All four production call sites (main.rs:1711, 1794, 1938, 2056) pass DatabaseManager::default_registry_path(), which is nodespace_dir()?.join("databases.toml"). So <registry dir>/database equals the old nodespace_dir()?.join("database") (both follow NODESPACE_HOME). NODESPACED_DB_PATH only moves the default database file (resolve_db_path) and never the registry, so managed databases stay under <nodespace dir>/database exactly as before. No tray/lib.rs/CLI code constructs a manager from a registry outside the nodespace dir. The remaining DatabaseManager::load callers are all tests.
  2. No-parent / relative registry path. parent() returns Some("") for a bare relative name, so the result is database/<id>.db relative to the CWD, the same place the registry itself lives; consistent. parent() is None only for / or an empty path, which cannot happen for a real registry file; the unwrap_or_else(|| Path::new("")) fallback is harmless (see Nit).
  3. Directory creation and rollback. build_database_services (assembly.rs) calls create_dir_owner_only(parent) before SqliteStore::new, so <registry dir>/database is created owner-only on demand. The path.exists() guard and the rollback (close + remove_database_files) are untouched and operate on the same resolved path.
  4. Other ambient writers. No other nodespace_dir() use in database_manager.rs or database_service.rs writes a database file. default_registry_path and resolve_db_path are the intended defaults. incompatible_database.rs writes a marker (not a database file) under nodespace_dir() and is unrelated.
  5. Other tests. Every other test that loads a manager uses a temp registry and either passes explicit paths (database_service.rs, per_db_*) or now lands inside the temp dir. Only mcp_integration.rs uses path: None through the gRPC layer, which is the case this fixes. Nothing relies on the old location.
  6. Test quality. The test would fail on the old code (the file would land under the ambient home, not <tempdir>/database), so it genuinely discriminates. It checks the parent directory and that the file exists.
  7. AGENTS.md rules. No compat shim, no issue numbers in comments, no Sync wording, no node-type/schema surface touched.

Findings

Critical Issues

None.

Suggested Improvements

None blocking.

Nitpicks

  • Nit: packages/daemon/src/services/database_manager.rs (managed_database_dir): the parent().unwrap_or_else(|| Path::new("")) fallback would silently resolve to a CWD-relative directory if a registry path ever had no parent. It is unreachable in practice; if you want it loud, make it return Result and anyhow! on None. Not worth blocking.
  • Nit: the test could also assert the returned entry is listed by mgr.list() so it covers registration, but create's existing tests already cover that.

Recommendation

APPROVE.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Review response

Addressed: 0 of 2 (both nits skipped, no code change)

  • ⏭️ managed_database_dir falls back to Path::new("") when the registry path has no parent. Skipped: only / or an empty path has no parent, and every production caller passes <nodespace dir>/databases.toml. Making it an error would add a failure mode for a case that cannot occur. Revisit if a registry location ever becomes user-supplied.
  • ⏭️ Also assert the entry appears in mgr.list(). Skipped: registration after create is covered by the existing create tests; this test's one job is where the file lands.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The review approved with no findings requiring change, and no code changed since it. bun run test:changed passed before the push.

🤖 Generated with Claude Code

… ambient home (closes #3780)

DatabaseManager::create with no path used nodespace_dir(), which follows
NODESPACE_HOME or else the real home, so an in-process manager over a temp
registry wrote ULID-named databases into ~/.nodespace/database/ (three per run
of mcp_integration). The directory is now database/ beside the registry file,
which is the same path in the daemon (<nodespace dir>/databases.toml).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@malibio
malibio force-pushed the issue-3780-managed-db-registry-dir branch from 00eca4e to 140a689 Compare October 13, 2026 11:20
@malibio
malibio merged commit f753eba into main Oct 13, 2026
@malibio
malibio deleted the issue-3780-managed-db-registry-dir branch October 13, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant