Repository navigation
Description
Overview
Add a GetRoots RPC to NodeService (or equivalent — see "Alternatives") and restore root_node_count to the nodespace diagnostics CLI subcommand.
Problem Statement
PR #1150 dropped root_node_count from the diagnostics report because the current gRPC surface has no honest way to compute it.
QueryNodesSimple returns NodeData rows with parent_id: None for every row, because the daemon's node_to_proto(n, None, None) call at packages/daemon/src/services/node_service.rs:417 doesn't attempt to populate the field — parentage is stored as a graph edge (relationship_type = "parent"), not a column on the node table.
A new integration test (diagnostics_collect_reports_counts_and_recency in packages/cli/tests/cli_integration.rs) caught that the pre-existing filter n.parent_id.as_deref().unwrap_or("").is_empty() evaluated to true for every row, making root_node_count == total_node_count always. The original Tauri implementation had the same latent bug — the migration to a gRPC-backed CLI exposed it.
Issue #1139's acceptance criteria explicitly require root node count in the diagnostics output. With no GetRoots-shaped RPC available, the only honest options were (a) report a wrong number, (b) drop the field, or (c) add the RPC. PR #1150 chose (b) with an inline comment seeding this follow-up; (c) is the proper fix.
Proposed Solution
Add a GetRoots RPC to NodeService that returns the list of nodes with no parent edge.
Proto
service NodeService {
...
rpc GetRoots(GetRootsRequest) returns (NodeListResponse);
}
message GetRootsRequest {
// 0 = use server default; unset / 0 returns all roots
uint32 limit = 1;
uint32 offset = 2;
}NodeListResponse is already defined and carries nodes + count.
Daemon handler
Wire to SurrealStore::get_children(None) — the store-layer method that already exists at packages/core/src/db/surreal_store.rs:1901 and returns nodes without a parent edge. Pass the optional limit/offset through NodeQuery.
CLI
Restore root_node_count to DiagnosticsReport. In collect(), replace the comment block at packages/cli/src/commands/diagnostics.rs:102-110 (which documents the structural impossibility under the current surface) with:
let root_node_count = match client.get_roots(GetRootsRequest { limit: 0, offset: 0 }).await {
Ok(response) => response.into_inner().nodes.len(),
Err(e) => {
errors.push(format!("GetRoots failed: {e}"));
0
}
};Re-add Root nodes: to print_human and root_node_count to print_json. Update the integration test to assert root_node_count == baseline.root_node_count + 1 (the one new root) and the in-line comment removal.
Alternatives Considered
-
Extend
NodeListResponse(andQueryNodesSimple) to carry parent IDs.
Means populatingparent_idinnode_to_protofor every node-list-returning RPC by joining against the relationship table at the daemon. Higher cost on the hot path ofQueryNodesSimple; out of proportion for a diagnostics need. Reject unless other consumers also need parent info. -
Compute roots client-side by paging through
QueryNodesSimpleand callingGetChildren(node_id)per result.
N+1 round-trips for a developer-tool feature. Reject. -
Add a counts-only RPC (
GetRootCount) that doesn't return node bodies.
Cheaper if diagnostics is the only consumer, but other clients (e.g. tree-view rendering) plausibly want the actual root list, so theGetRootsshape generalizes better. Mild preference forGetRoots.
Acceptance Criteria
-
GetRoots(or equivalent) RPC added toNodeServiceproto with appropriate request/response types - Daemon handler implemented in
packages/daemon/src/services/node_service.rs, wired toSurrealStore::get_children(None) -
nodespace diagnosticsrestores theRoot nodes:line androot_node_countJSON field - In-line comment in
collect()explaining the structural impossibility is removed - Integration test
diagnostics_collect_reports_counts_and_recencyasserts root count delta -
cargo buildsucceeds -
cargo test -p nodespace-clipasses (existing + updated assertions) -
cargo clippy --all-targets -- -D warnings -D clippy::unused-asyncclean
Dependencies
- Migrate diagnostics to nodespace CLI subcommand; remove Tauri diagnostics commands #1139 (closed by Migrate diagnostics to nodespace CLI subcommand (closes #1139) #1150) — diagnostics CLI subcommand must exist
Related
- PR Migrate diagnostics to nodespace CLI subcommand (closes #1139) #1150 — review thread that surfaced the gap
- Issue Migrate diagnostics to nodespace CLI subcommand; remove Tauri diagnostics commands #1139 acceptance criteria — restores the dropped "root node count" bullet
Activity
Address re-review: document RFC3339 lexicographic sort invariant
Address re-review: document RFC3339 lexicographic sort invariant
Migrate diagnostics to nodespace CLI subcommand (closes #1139) (#1150)
malibio commentedon May 18, 2026
Frontend baseline: 128 passed, 3916 tests. Starting implementation.
Add GetRoots RPC and restore root_node_count to diagnostics (#1165)
Migrate diagnostics to nodespace CLI subcommand (closes #1139) (#1150)
Add GetRoots RPC and restore root_node_count to diagnostics (#1165)