Skip to content

Add GetRoots RPC and restore root_node_count to diagnostics - #1165

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1153-get-roots-rpc
May 18, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1153-get-roots-rpc

Conversation

@malibio

@malibio malibio commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds GetRoots RPC to NodeService proto with GetRootsRequest (limit/offset) returning NodeListResponse
  • Implements daemon handler in node_service.rs wired to CoreNodeService::get_roots() → SurrealStore::get_children(None)
  • Restores root_node_count to DiagnosticsReport, print_human, and print_json in the CLI diagnostics command
  • Updates diagnostics_collect_reports_counts_and_recency integration test to assert root_node_count == baseline + 1

Closes #1153

Test plan

  • cargo build -p nodespace-daemon -p nodespace-cli succeeds
  • cargo clippy --all-targets -- -D warnings -D clippy::unused-async clean (pre-existing nodespace-app error unrelated to this PR)
  • cargo test -p nodespace-cli — all 5 tests pass including diagnostics_collect_reports_counts_and_recency

🤖 Generated with Claude Code

@malibio

malibio commented May 18, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This PR is a clean, targeted fix for a well-diagnosed problem. The structural analysis in issue #1153 is accurate — parentage lives in the relationship table, not on the node row, so exposing a GetRoots RPC via SurrealStore::get_children(None) is the correct architectural lever. The change correctly threads the new capability from proto → core service → daemon handler → CLI, and the integration test delta assertion is exactly right. This is a net improvement and all acceptance criteria are met.

Two implementation issues should be addressed before merge, and one nit.


Findings

Improvements

[Improvement] packages/daemon/src/services/node_service.rs lines 316–327 — Pagination applied in application memory, not at the database layer

The daemon fetches the full root set from SurrealDB, then slices with .skip() / .truncate() in Rust. SurrealStore::get_children(None) does not accept a NodeQuery; it always returns every root node. For the current diagnostics use case (which passes limit: 0, offset: 0, i.e. "fetch all") this is functionally harmless. However, the proto contract advertises limit/offset as pagination controls, and a caller sending limit: 10 will get a correct-looking but potentially expensive response — all roots were fetched from the DB regardless.

This creates a misleading contract: the RPC signature implies server-side pagination but the implementation silently fetches everything first. The fix is either:

  1. Push limit/offset into SurrealStore::get_children (the preferred path — the existing query already has a simple SELECT * that is trivially extended with LIMIT $limit START AT $offset).
  2. Or document the limitation clearly in the proto comment and restrict the current call site to limit: 0 until the store layer is extended.

Given the diagnostics caller always passes limit: 0, option 2 is a valid short-term expedient if option 1 is out of scope for this PR.

[Improvement] packages/cli/src/commands/diagnostics.rs line 110 — nodes.len() ignores the count field; can silently under-count if a limit is ever set

Ok(response) => response.into_inner().nodes.len(),

The response carries both nodes (the page) and count. Currently limit: 0 means the daemon returns all roots and count == nodes.len(), so the result is correct. But nodes.len() will silently return only the page size if a future caller passes a non-zero limit. Prefer response.into_inner().count as usize — it reflects the server's authoritative total. This is consistent with the semantics all other callers on NodeListResponse should respect, and makes the diagnostics intent ("how many roots exist?") unambiguous.


Nitpicks

Nit: packages/core/src/services/node_service.rs line 3606 — get_roots lacks a doc comment

Every neighbouring public method on NodeService (get_children, get_descendants, etc.) has a /// doc block with # Arguments, # Returns, and a # Examples section. get_roots is undocumented. Not a blocker, but inconsistent with the local convention.

- diagnostics: use response.count instead of nodes.len() for root_node_count
  (count is the authoritative total; nodes.len() would silently under-count
  if a non-zero limit were ever passed)
- proto: document that GetRootsRequest limit/offset are applied in memory,
  not at the store layer; reference follow-up issue #1167
- core: add doc comment to get_roots

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented May 18, 2026

Copy link
Copy Markdown
Collaborator Author

Review Feedback Addressed

✅ Addressed (2/2 important findings):

  1. nodes.len() → count as usize in diagnostics.rs:110 — NodeListResponse.count is the authoritative total; nodes.len() would silently under-count if a non-zero limit were ever passed.

  2. In-memory pagination documented in GetRootsRequest proto comment, referencing follow-up issue Push GetRoots limit/offset pagination into SurrealStore::get_children #1167 for pushing LIMIT/START AT into SurrealStore::get_children. No current caller passes non-zero limit/offset so no behaviour change.

✅ Nit addressed: Added doc comment to get_roots in core service.

Follow-up issue created: #1167 — Push GetRoots limit/offset pagination into SurrealStore::get_children

@malibio
malibio merged commit b175296 into main May 18, 2026
@malibio
malibio deleted the worktree-issue-1153-get-roots-rpc branch May 18, 2026 22:14
malibio added a commit that referenced this pull request Jun 22, 2026
* Add GetRoots RPC and restore root_node_count to diagnostics (closes #1153)

Co-Authored-By: Claude <[email protected]>

* Address review: use count over nodes.len, document pagination limitation

- diagnostics: use response.count instead of nodes.len() for root_node_count
  (count is the authoritative total; nodes.len() would silently under-count
  if a non-zero limit were ever passed)
- proto: document that GetRootsRequest limit/offset are applied in memory,
  not at the store layer; reference follow-up issue #1167
- core: add doc comment to get_roots

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude <[email protected]>
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.

Add GetRoots RPC and restore root_node_count to nodespace diagnostics

1 participant