Repository navigation
Keep merge_nodes inside the tree invariants (closes #2938) - #3094
Conversation
Pragmatic Code Review — PR #3094 (closes #2938)Review Type: Initial Review Requirements Check
Correctness walk-through (no defects found)I traced every shape (S = survivor, L = loser):
Code Review Findings🟡 Important1. The root-only-membership rule now has a third hand-written copy if has_parent_after {
if survivor.node_type == "collection" { anyhow::bail!(super::collection_not_root(...)); }
if survivor.node_type != "person" {
let memberships = Self::member_of_targets_in_tx(tx, &[survivor_id, loser_id]).await?;
if !memberships.is_empty() { anyhow::bail!("member_of_not_root: ...") }
🟢 Suggestions2. Root survivor with a loser deep in its own subtree is refused, but could be merged by dropping 3. Cycle checks walk whole subtrees downward, where a walk up the ancestors is enough 4. The two remaining refusal branches have no tests 5. Policy refusals surface as Nits
Standards check
Recommendation: APPROVEThe fix is correct in every shape I traced, the refusal policy matches |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Review addressed (467bfd3)
|
Pragmatic Code Review: PR #3094 (re-review of 467bfd3)Review Type: Re-Review Previous Review Summary: The previous review made 5 recommendations and 3 nits. 4 recommendations and all 3 nits are addressed. 1 recommendation is not addressed, and the reason is acceptable. There is 1 new finding, a nit.
Correctness walk-through of the new logic
I traced every shape against the edge loop and found no defect:
Tests. 33 of 33 pass locally under
Code Review FindingsNits
No other new issues. Recommendation: APPROVE |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Re-review addressed (17c4fa6)
Comment-only change, so no re-review is needed. |
merge_nodes_in_tx re-pointed every edge with a plain endpoint UPDATE, so a merge could give the survivor two has_child parents, leave it holding member_of while it has a parent (ADR-059 §2), or close a has_child cycle. - The loser's parent edge re-points only onto a root survivor; otherwise it is dropped and counted, and the survivor keeps its position. - The merge is refused before any write when the result would break ADR-059 §2 (member_of_not_root / collection_not_root) or form a cycle (merge_would_cycle), matching move_node's refusal. - merge_nodes passes the loser's former parent to refresh_for_rootness_in_tx, so the tree that lost the loser is re-queued after commit. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…fusing an in-subtree parent - member_may_have_parent is now the one source of the ADR-059 §2 person exemption, used by check_root_only_member and merge_nodes_in_tx. - A root survivor no longer refuses a loser whose parent sits in the survivor's own subtree: the loser's parent edge is dropped, as it is when the survivor already has a parent. merge_would_cycle now covers only a survivor inside the loser's subtree. - The cycle check walks up the parent chain (O(depth)) instead of down a whole subtree. - New tests: in-subtree parent edge dropped, collection survivor refused, filed person survivor may take a parent. Each is mutation-checked. - Error message names the survivor; doc line re-wrapped. Skipped: a typed error for merge refusals. move_node reports the same refusals as query_failed, so a typed error belongs in a follow-up that covers both. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
17c4fa6 to
22303e5
Compare
Summary
merge_nodes_in_txre-pointed every edge with a plain endpoint UPDATE, bypassing the tree invariants every otherhas_childwrite enforces.Policy (open question 1: refuse, matching
move_node):edges_dropped; the survivor keeps its position (case 2).member_of_not_root(cases 4 and 5;personexempt) orcollection_not_root.merge_would_cyclewhen one node sits deeper than a direct child in the other's subtree. This is a third bypass the issue didn't list. A direct parent/child pair still merges (the edge between them becomes a self-edge).merge_nodesreads the loser's parent before the merge and passes it asformer_parenttorefresh_for_rootness_in_tx, so the tree that lost the loser is re-queued after commit.Open question 2 (Conflicts-view messaging) is UI and is not part of this PR.
Tests
tests/merge_nodes_test.rs: case 2, case 1, survivor directly under the loser, cases 4 and 5, and both cycle shapes.former_embedding_root_tests: case 2 re-queues both roots; a rolled-back merge (unknown conflict id, failing after the deferral) queues nothing.bun run rust:test:lib: 1800 passed.quality:fixclean.🤖 Generated with Claude Code