Repository navigation
Bound GetChildrenTree's subtree payload with an actionable error - #2493
Conversation
#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
Code Review SummaryThis PR closes out the last remaining gap from issue #2108: I verified the full acceptance criteria list from #2108 against the current state of the codebase (prior PRs #2294/#2319 plus this diff), not just this diff in isolation — see below. Acceptance Criteria Verification (issue #2108)
All eight acceptance criteria are now satisfied across #2294, #2319, and this PR. No gaps remain. FindingsCritical IssuesNone. Suggested Improvements
Nitpicks
VerdictApprove (posting as a comment-only review since this is a self-authored PR and |
malibio
left a comment
There was a problem hiding this comment.
Initial review posted above. Net positive — closes the final gap in #2108 with a pattern-consistent (mirrors SubtreeAccessDenied/FAILED_PRECONDITION), well-tested fix. Two non-blocking Suggested Improvements noted (partial short-circuit comment clarity; 20k-node limit is a heuristic, not a hard byte guarantee). No Critical Issues. Approve (posting as comment since PR author cannot self-approve).
…AX_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
Address Review SummaryBoth Suggested Improvements from the pragmatic-code-review addressed (comment-only, no logic change):
No items skipped. Both were low-risk, worthwhile clarifications. Verification: Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: Both changes are doc-comment-only clarifications with zero logic/behavior change — no new functionality, no architectural change, no risk of introducing a new issue. The prior review already found no Critical or Important issues and recommended Approve. 🤖 Generated with Claude Code |
Summary
Closes #2108. The diagnostics count/unknown-vs-zero, count-only RPCs, bounded ordered recent-node query, and the configured 64MiB gRPC message-size ceiling were already fixed by #2294/#2319. This PR addresses the one remaining defect from the issue:
get_children_treehas no node-count bound, only a depth bound (MAX_TREE_DEPTH), so a wide-but-shallow subtree can still produce a payload the gRPC transport rejects with an opaqueOutOfRangeat decode time — on the app's hot path for opening a document.The frontend eagerly loads a document's full tree in one call with no lazy-expand fallback, so truncating the response would silently drop content. Per the issue's stated preference, this states and enforces a maximum document size instead of raising the limit or truncating:
MAX_TREE_NODES(20,000) next to the existingMAX_TREE_DEPTHguard, checked inget_children_treebefore the tree is built.NodeServiceError::TreeTooLarge→OpsError::TreeTooLarge→ aRESOURCE_EXHAUSTEDgRPC status carryingnode_id/count/maxin metadata (mirrors the existingSubtreeAccessDenied→FAILED_PRECONDITIONpattern), so a caller gets a specific, actionable failure instead of a raw transport decode error.Test plan
cargo test --workspace— all passingbun run test— 233 files / 4913 tests passingbun run quality:fix— clean (eslint, svelte-check, tsc, rustfmt, clippy)RUN_LONG_TESTS=1, ~80s, matches existing large-subtree test convention): subtree just over the limit is refused withTreeTooLarge; subtree at exactly the limit is servedTreeTooLargemaps toRESOURCE_EXHAUSTEDwithx-tree-node-count/x-tree-node-maxmetadata🤖 Generated with Claude Code
https://claude.ai/code/session_01KavcAieXx31wYVQfjz1wk6