Repository navigation
Let the CLI move a node - #3580
Conversation
Pragmatic Code Review: PR #3580 "Let the CLI move a node"Review Type: Initial review (no prior reviews or comments on the PR). Reviewed commit Method: Read the diff plus the surrounding code it depends on: the SummaryThe mapping onto the two RPCs is right for the documented happy paths, the command is small and follows the shape of Three flag combinations write something other than what the caller asked for and exit 0, and cli.md states a rule for Requirements Check
On Findings🟡 Important1. The help text and cli.md say the sibling "must be a child of the parent the node ends up under". Nothing checks that:
So Recommendation: refuse it. The best place is core ( 2. clap accepts an empty value, the CLI sends Recommendation: reject an empty 3. A root has no sibling order ( Recommendation: add 4. The reorder From Recommendation: reorder after a non-last sibling: from 🟢 Suggestions5. A conflict on a move with no Without 6. JSON output is not asserted. AC1 asks for JSON output like the other node commands. The tests assert the resulting tree only. One assertion that the printed node carries the bumped version, on the reorder path in particular since it reads the node back separately, would cover the 7. The root-reorder refusal that cli.md documents has no CLI test. "A position without 8. The refusal message is duplicated at two sites. The same four-line format string is now edited in two places. A small helper ( Nitpicks
Checked and found sound
Recommendation: REQUEST CHANGESFindings 1 to 4 are each a few lines. With them fixed this is ready to merge; 5 to 8 and the nits are at the author's discretion. |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Review addressed (
|
Pragmatic Code Review: PR #3580 "Let the CLI move a node"Review Type: Re-Review. Scope: Method: Read the commit, the prior review and the author's response, then traced every caller of core's Previous Review Summary
Per finding:
Requirements Check
What I traced for
|
| Caller | Position sent | Affected? |
|---|---|---|
indentNode (:1047) |
none (end) | No |
outdentNode (:1212) |
after the old parent, under the old parent's parent | No in the normal case: it waits for pending moves and flushes all pending saves first, so the old parent's edge is in the database. A move to the root skips the check. |
promoteChildren (:1340) |
after an ancestor-or-self of the merged-into node, under that node's parent | Yes, see below |
Could not determine: callers outside this repository (nodespace-sync builds on core and could call move_node or move_node_unchecked directly); whether the race below is reachable at human typing speed; and whether the delete that follows a merge cascades to children still attached in the database (core documents delete as a cascade, but I did not read the daemon's default delete path to the end).
Code Review Findings
🟡 Important
1. promoteChildren can now have its move refused where it previously succeeded, and it only logs the failure.
📁 packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts:1335-1345; 📁 packages/core/src/services/node_service/hierarchy.rs:509-512
The author's response says the desktop app's "indent/outdent moves already name a child of the target parent". That is true of those two, but promoteChildren (Backspace-merge of a node that has children, via combineNodes) is a third caller and it differs in the way that matters:
- It takes the anchor and the new parent from the in-memory structure tree (
getParentsForNode), not from the database. - It calls
persistMoveimmediately. UnlikeindentNodeandoutdentNode, it does not wait for pending moves or flush pending saves.outdentNode's own comment (:1185-1190) explains that this wait exists to avoid sibling-not-found errors. - Node writes are debounced by 500 ms (
shared-node-store.svelte.ts:158), and an indent's move is asynchronous.
So if the anchor was created or indented moments before the merge, the database does not yet have it as a child of the target parent. Before this commit the store placed the promoted child last, which is the correct position here: the anchor is an ancestor-or-self of the node visually above the deleted one, so it is the last child of its parent. After this commit the move is a hierarchy violation. The .catch at :1340 logs it and nothing else: the structure tree has already been updated optimistically, and combineNodes goes on to delete the merged node (:637) while the child is still under it in the database.
Example: A has a child P that was typed in under 500 ms ago; F follows A and has a child G. Merging F into P sends "move G under A, after P" while P's create is still pending.
Recommendation: make promoteChildren satisfy the new rule the same way outdentNode does: run its moves inside a tracked move operation that waits for pending moves and flushes pending saves before persistMove. Add a frontend test for a merge whose anchor has a pending create. If that is too much for this PR, apply the check only where the caller is known to read from the database, and file the frontend change before tightening the shared path.
Principle: tightening a precondition on a shared path requires checking every caller against it; a previously benign fallback must not become a silent failure followed by a destructive step.
🟢 Suggestions
2. The unversioned exemption has no caller to justify it.
📁 packages/core/src/services/node_service/hierarchy.rs:506-512
The comment says "the unversioned path applies placements already made", but move_node_unchecked is called only from tests and benches in this repository. Keying input validation on whether a version was supplied also ties two unrelated things together: move_existing_node's doc says the two variants "differ only in OCC". Either apply the check on both paths, or name the caller the exemption is for.
Principle: YAGNI; one rule per concept.
3. Stale doc comment on resolve_reorder_position.
📁 packages/core/src/services/node_service/hierarchy.rs:1089-1092
It still says "any After sibling must exist". The rule is now that the sibling must be another child of the node's parent.
4. A missing sibling is reported as "is not a child of".
📁 packages/core/src/services/node_service/hierarchy.rs:1137-1142
reorder_node used to say "Sibling node X does not exist" for a typo. The new message is accurate but less direct for the commonest mistake. Optional: keep the existence wording when node_exists is false. Related: the rule is tested only through the CLI; a core unit test beside the other move tests would pin it where it lives.
Checked and found sound
- The check runs after the version check and
validate_moveon the move path and after the version check on the reorder path, so a stale version still reports a conflict first. - It reads through a pooled reader before the transaction, which matches the documented fail-fast design. The store's in-transaction fallback still handles a sibling moved away concurrently.
second_parent_refusedproduces the same text as before at both sites.- clap changes:
conflicts_withmoved fromparenttorootand still covers the pair; the tests assert each combination. - cli.md: hand-written section and generated surface agree with the code.
- No node-type, schema, lifecycle or Pro-boundary concerns in this commit.
Recommendation: REQUEST CHANGES
Every prior finding is resolved or reasonably declined, and the CLI itself is ready. The one blocker is finding 1: the core check is correct for the CLI but was verified against two of the desktop app's three callers. Either bring promoteChildren in line or scope the check, then this can merge. Findings 2 to 4 are at the author's discretion.
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Re-review addressed (
|
Pragmatic Code Review: PR #3580 "Let the CLI move a node"Review Type: Re-Review (third pass). Scope: Method: Read the commit, both prior reviews and the author's responses, the CLI command and its tests, core's reorder path, the store's Previous Review Summary
Per finding:
Who reaches the reorder check. Requirements Check
The new code:
|
| Flags | RPC | --after checked by |
Result |
|---|---|---|---|
| none | none | n/a | refused before any RPC |
--parent P |
MoveNode | n/a | placed last |
--parent P --first |
MoveNode | n/a | placed first |
--parent P --after S |
MoveNode | CLI (require_child_of) |
refused unless S is a child of P and S is not the node |
--root |
MoveNode | n/a | root; clap refuses --first, --after, --parent with it |
--first |
ReorderNode | n/a | first under current parent; refused for a root |
--after S |
ReorderNode | core (require_sibling_under) |
refused unless S is another child of the node's parent |
--first --after S |
n/a | n/a | clap refuses |
--version is orthogonal to all of these. The check runs only where it is needed: (Some(parent), Some(sibling)) cannot be true with --root, and the reorder path leaves it to core.
Checked and found sound:
- The check runs before the write, so "Nothing was written." in the message is true.
- It uses the destination parent, not the node's current one. The test's first case (a child of the parent the node is leaving) would pass a check written against the wrong parent, so it pins this.
GetChildrenreads everyhas_childrow for the parent with no lifecycle filter and no limit, so an archived child or a child past some page boundary is not wrongly refused. The CLI client is built with the raised decode limit (packages/proto/src/lib.rs:53).- A parent that does not exist returns no children, so the command is refused with "is not a child of" instead of reaching
MoveNode. The wording is slightly off for that case, but nothing is written and the next thing the caller checks is the right one. - Failure output:
mainreturns theanyhowerror, so each refusal isError: ...on stderr with a non-zero exit, with or without--json. Only a version conflict also prints structured JSON on stdout under--json; that matchesnode update. - The read-then-write window is stated honestly in the code comment and the author's response; the store's "last" fallback still covers a sibling moved away in between.
- cli.md and the help text: "
--afternames a child of the parent the node ends up under; any other node is refused and nothing is written" is now true on both RPCs. The generated surface matches theMoveArgsdoc comments. - Removing
require_child_offails the test: the three move cases innode_move_after_a_node_that_is_not_a_sibling_writes_nothingwould succeed and tripexpect_err. A check that refused everything failsnode_move_reparents_a_node_at_the_requested_position, which moves after a real sibling.
Code Review Findings
🟢 Suggestions
1. The CLI's "after itself" branch is not pinned by a test.
📁 packages/cli/src/commands/node.rs:542-544; 📁 packages/cli/tests/it/cli_integration.rs:2083
The test's self case is --parent <new_parent> --after <node> with the node still under the old parent. Delete the sibling == node branch and that case is still refused, by the membership check, and the assertion accepts either message. The branch only matters when the node is already under the named parent (--parent <current parent> --after <self>): then the node is in GetChildren and, without the branch, MoveNode would place it last.
Recommendation: add that case to the loop ((Some(&old_parent), &node)), and assert the "after itself" message for it.
Principle: a test should fail when the branch it covers is removed.
2. The restored "Sibling node X does not exist" branch has no test, and the shared assertion is loose.
📁 packages/core/src/services/node_service/hierarchy.rs:1128-1132; 📁 packages/cli/tests/it/cli_integration.rs:2101-2104
The author's response says the CLI test "runs both reorder refusals through core"; those two are a child of another parent and the node itself. A reorder after a node that does not exist is not among the five cases, and no other test in core, the daemon or the app asserts that message. Separately, contains("is not a child of") || contains("after itself") lets any case produce either message.
Recommendation: add (None, &"no-such-node".to_string()) and give each case its expected fragment (a third tuple element) instead of the ||.
Principle: same as above; one expected outcome per case.
Nitpicks
- Nit: 📁
packages/cli/src/commands/node.rs:465-490: with a stale--versionand a wrong--afteron a move, the sibling error is reported and the conflict is not; on a reorder core reports the conflict first. Nothing is written either way. Also, without--versionthe membership read sits between the version read and the write; runningrequire_child_ofbefore the version read would keep that window as small as it was. - Nit: 📁
packages/core/src/services/node_service/hierarchy.rs:1083: the edited doc-comment line is over 100 columns; rustfmt does not wrap comments, so it needs a manual wrap.
Could not determine
- Whether the tests pass: I did not run them. The author reports
bun run test:changedpassing. - Callers outside this repository. A build on top of core that calls
ReorderNodewith anAfternaming a non-sibling would now be refused; core's move path, which such a build is more likely to use, is unchanged. require_child_oftransfers every child of the parent, content included, to test membership. I did not measure it; for a very large parent it is a heavier read than the move itself. Not worth a proto change here.
Recommendation: APPROVE
The blocker from the second review is resolved in the way that carries the least risk: core's move path is exactly main's, and the CLI checks its own input before writing. The two suggestions are a few test lines each and are at the author's discretion.
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review 2): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Third review addressed (
|
9af43e4 to
9118bf0
Compare
Closes #3569
What changed
nodespace node move <id>:--parent <id>or--rootchanges the parent (MoveNode);--firstor--after <sibling-id>alone changes the position under the current parent (ReorderNode).--version <n>works as onnode update; without it the command moves the node at its current version. Output is the node's JSON, like the other node commands.has_childedge is now refused with the exact command to run (nodespace node move <node> --parent <new-parent>), at both sites in core.references/cli.md, the regenerated CLI surface, and SKILL.md's hierarchy and version paragraphs name the command.Notes for review
--before. The RPCs take beginning / end / after, and resolving "before X" in the CLI would be a separate read that can go stale before the write.--firstand--afterreach every position; cli.md says how to place a node before a sibling.ReorderNodereturns nothing.update_refusedbecamewrite_refused(status, rpc, json)so a move's version conflict is reported the same way as an update's.Tests
CLI integration tests cover: move to the end, the beginning and after a sibling; move to root; reorder first and after a sibling; a move with no destination or position; a stale
--versionon both RPCs writing nothing; flag exclusivity; and the refusal, whose printed command is parsed and run to confirm it moves the node.bun run test:changedpasses (rust, skill, scripts tiers). Its first run failed three timeouts inscripts/gate-sccache.test.ts, which this change doesn't touch; the file passed alone and the full re-run passed.🤖 Generated with Claude Code