Repository navigation
Bound QueryNodesSimple/GetRoots and add count-only RPCs - #2319
Merged
Merged
Conversation
QueryNodesSimple's daemon handler hardcoded order_by: None on every request, so even though SqliteStore::query_nodes gained a real ORDER BY (#2211/#2212), the gRPC surface never used it — offset-based pagination through this RPC could return duplicate or skipped rows across pages. A client-requested limit also passed straight through with no ceiling, relying entirely on the gRPC message-size limit to fail an oversized response. - Add a NodeSortOrder proto enum and order_by field on QueryNodesSimpleRequest; the daemon now always applies a deterministic default (created ascending) when unspecified, via order_by_from_proto. - Clamp QueryNodesSimple's limit to a max page size (500) and give GetRoots the same default/max treatment, replacing its "0 = unlimited" sentinel. - Add count_nodes/count_roots (store, service, and CountNodes/CountRoots RPCs) so a caller that only needs a total doesn't have to fetch (and page through) the matching records. Refactor query_nodes's condition building into build_scalar_conditions, shared with count_nodes. - Switch `nodespace diagnostics` to the count-only RPCs for total_node_count/root_node_count and a small CreatedDesc-ordered page for recent_node_ids, instead of pulling up to 100,000 full records to call .len() on the result. Regression tests: store-level count_nodes/count_roots agreement with query_nodes/get_roots across every filter shape, and daemon-level gRPC tests proving repeated limit/offset pages tile a 47-node set exactly once (no dup/gaps) with stable repeat calls, an oversized limit against 505 seeded nodes clamps to exactly 500, and count_nodes/count_roots report exact totals via a real gRPC round trip. Co-Authored-By: Claude Sonnet 5 <[email protected]>
6 tasks done
malibio
added a commit
that referenced
this pull request
Sep 8, 2026
* Bound GetChildrenTree's subtree payload with an actionable error (closes #2108) The rest of #2108's issues were already fixed by #2294/#2319 (unknown-vs-zero diagnostics fallbacks, count-only RPCs, bounded ordered recent-node query, and the configured 64MiB gRPC message-size ceiling). The one remaining defect: on the app's hot path for opening a document, get_children_tree still built and serialized an entire subtree into one JSON payload with no node-count bound — only depth is guarded (MAX_TREE_DEPTH). A wide-but-shallow subtree (many siblings under one parent) can still produce a message the gRPC transport rejects with an opaque OutOfRange at decode time. The frontend eagerly loads a document's full tree in one call with no lazy-expand fallback (shared-node-store.svelte.ts's loadChildrenTree), so truncating the response would silently drop content rather than degrade gracefully. Per the issue's stated preference, state and enforce a maximum document size instead: - Add MAX_TREE_NODES (20,000) next to the existing MAX_TREE_DEPTH guard in node_service/mod.rs, checked in get_children_tree before the tree is built. - Add NodeServiceError::TreeTooLarge -> OpsError::TreeTooLarge -> a RESOURCE_EXHAUSTED gRPC status carrying node_id/count/max in metadata (mirrors the SubtreeAccessDenied FAILED_PRECONDITION pattern), so a caller gets a specific, actionable failure instead of a raw transport decode error. - Regression tests: core-level tests seeding a subtree just over/at the limit (gated behind RUN_LONG_TESTS, matching the existing large-subtree test convention — this seeds 20k+ nodes and takes ~80s), and a fast daemon-level unit test asserting the status code and metadata. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KavcAieXx31wYVQfjz1wk6 * Address review: clarify short-circuit scope and heuristic nature of MAX_TREE_NODES Comment-only changes from pragmatic-code-review on PR #2493 (both Suggested Improvements, non-blocking): - hierarchy.rs: clarify the MAX_TREE_NODES check only skips the remaining mention-lookup and tree-build/serialization, not the DB fetch that already ran in get_subtree_data — that fetch is one consolidated query and can't be split into count-then-fetch without a schema/query change. - mod.rs: note MAX_TREE_NODES is a heuristic node-count cap, not a guaranteed byte ceiling, since per-node content/properties size is still unbounded. Accepted deliberately given typical nodes are short text/task fragments, rather than adding a byte-accumulation pass to close the residual case. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KavcAieXx31wYVQfjz1wk6 --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2289.
QueryNodesSimple's daemon handler hardcodedorder_by: Noneon every request, so even thoughSqliteStore::query_nodesgained a realORDER BY(#2211/#2212, merged earlier), the gRPC surface never actually used it — offset-based pagination through this RPC could return duplicate or skipped rows across pages. A client-requestedlimitalso passed straight through to the store with no ceiling, so a large-enough request returned every matching row in one unary message and relied entirely on the gRPC message-size limit (raised in #2286) to badly fail anything larger still.This PR bounds
QueryNodesSimple/GetRootsinstead of relying on that ceiling, and adds a count-only path for callers (likenodespace diagnostics) that only need a total.NodeSortOrderproto enum andorder_byfield onQueryNodesSimpleRequest. The daemon now always applies a deterministic default order (created ascending) when unspecified — seeorder_by_from_protoinpackages/daemon/src/services/node_service.rs— so offset-based pagination through this RPC is finally stable, not just theoretically supported by the store layer.QueryNodesSimple'slimitto a max page size (500), mirroring the existingMAX_EXECUTE_QUERY_LIMITpattern onExecuteQuery. GiveGetRootsthe same default/max treatment, replacing its old "0 = unlimited" sentinel.count_nodes/count_roots— newSqliteStoremethods,NodeServicemethods, andCountNodes/CountRootsgRPC RPCs — so a caller that only needs a total doesn't have to fetch (and page through) the matching records.query_nodes's condition-building is refactored into a sharedbuild_scalar_conditionshelper socount_nodescan't drift fromquery_nodes's filter semantics.nodespace diagnosticsto the new count-only RPCs fortotal_node_count/root_node_count, and a smallCREATED_DESC-ordered page (limit=10) forrecent_node_ids, instead of pulling up to 100,000 full records purely to call.len()on the result and sort client-side.Explicitly out of scope
The issue also lists
GetChildren,GetChildrenTree,GetCollectionMembers(Recursive),SearchNodes,GetAllSchemas, andExportMarkdownas unbounded. Those don't currently modellimit/offsetviaNodeQuerythe wayQueryNodesSimple/GetRootsdo (some, likeGetChildren, are edge-order-based and already deterministic; others would need a separate pagination design). This PR keeps to the RPCs the issue describes in the most concrete detail and that build directly on theorder_by/limit/offsetprimitivesNodeQueryalready has. Happy to split the rest into a follow-up issue.Test plan
bun run test:all— no new failures (frontend 227 files/4810 tests, full Rust workspace incl. thenodespace-appTauri-seam suite, all green)bun run quality:fix—cargo fmt,cargo clippy --all-targets -- -D warnings -D clippy::unused-asyncclean,eslint/tsc/svelte-checkcleanpackages/core/src/db/sqlite_store/nodes.rs):count_nodes_agrees_with_query_nodes_len_across_filter_shapes,count_roots_agrees_with_get_roots_lenpackages/daemon/tests/grpc_round_trip.rs):query_nodes_simple_pages_tile_full_set_exactly_once_with_default_ordering— 47-node dataset, 3 pages oflimit=20, asserts the tiled pages reconstruct the full set with no duplicates/gaps and that repeating a page is stablequery_nodes_simple_clamps_an_oversized_limit_to_the_max_page_size— 505 seeded nodes,limit=100_000request clamps to exactly 500count_nodes_and_count_roots_report_totals_without_transferring_recordsdiagnostics_collect_reports_counts_and_recency,diagnostics_reports_unknown_counts_when_the_node_query_fails) and the QueryNodesSimple exceeds gRPC's 4MB message-size limit on large databases, and the failure is silently misreported (diagnostics shows 'Total nodes: 0') #2286 message-size-ceiling regression test (query_nodes_simple_handles_response_over_the_default_grpc_limit) still pass unmodified in behaviortest:all+cargo build --bin nodespaced+cargo test -p nodespace-app) — green🤖 Generated with Claude Code