Skip to content

Add GetRoots RPC and restore root_node_count to nodespace diagnostics #1153

Closed

Description

@malibio

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

  1. Extend NodeListResponse (and QueryNodesSimple) to carry parent IDs.
    Means populating parent_id in node_to_proto for every node-list-returning RPC by joining against the relationship table at the daemon. Higher cost on the hot path of QueryNodesSimple; out of proportion for a diagnostics need. Reject unless other consumers also need parent info.

  2. Compute roots client-side by paging through QueryNodesSimple and calling GetChildren(node_id) per result.
    N+1 round-trips for a developer-tool feature. Reject.

  3. 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 the GetRoots shape generalizes better. Mild preference for GetRoots.

Acceptance Criteria

  • GetRoots (or equivalent) RPC added to NodeService proto with appropriate request/response types
  • Daemon handler implemented in packages/daemon/src/services/node_service.rs, wired to SurrealStore::get_children(None)
  • nodespace diagnostics restores the Root nodes: line and root_node_count JSON field
  • In-line comment in collect() explaining the structural impossibility is removed
  • Integration test diagnostics_collect_reports_counts_and_recency asserts root count delta
  • cargo build succeeds
  • cargo test -p nodespace-cli passes (existing + updated assertions)
  • cargo clippy --all-targets -- -D warnings -D clippy::unused-async clean

Dependencies

Related

Activity

  1. malibio commented on May 18, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 128 passed, 3916 tests. Starting implementation.

  2. self-assigned this
    on May 18, 2026
  3. added a commit that references this issue on May 18, 2026
    b175296
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions