Repository navigation
C3c: Atomic child-transfer-on-split — single MoveChildrenToParent RPC (all-or-nothing) - #1276
Conversation
Code Review SummaryC3c is a well-scoped, architecturally correct change that eliminates N per-child RPCs in favor of a single all-or-nothing Findings[Improvement]
|
| Criterion | Status |
|---|---|
New MoveChildrenToParent RPC + core op + SqliteStore transaction |
✅ |
createNode mid-list-split issues exactly one RPC |
✅ (implemented; test assertion uses > not === 1) |
Optimistic structureTree update preserved |
✅ |
Order/version reconciled via response + RelationshipUpdated |
✅ (order via event, version via response) |
On failure: one rollback + 'child-transfer-failure' notification |
✅ |
No skipConflictDetection per-child loop remaining |
✅ |
| Atomicity test | ✅ (passes but doesn't cover TOCTOU window) |
| OCC mapping (daemon): stale version → Aborted | ✅ |
| Order preservation test | ✅ (present; doesn't assert actual order values) |
| ADR amendment | ❌ missing |
Overall: this is a net positive — the fundamental architecture (single RPC, one transaction, event-driven order reconciliation, preserved #656 notification) is correct and cleanly implemented. The two Improvement items (fractional order chaining, cycle check + TOCTOU window) are the highest priority to address before merge. The ADR update and test strengthening are close seconds.
Review findings addressed✅ Fixed (3 items): 1. Fractional order chaining bug — 2. TOCTOU + missing cycle check —
3. Frontend "exactly once" assertion — ⏭️ Skipped (2 items):
All 3867 frontend + 17 browser + 881 Rust tests pass after fixes. |
Re-Review Summary (commit 333872e)Three of four original findings were addressed. The fixes are directionally correct — the fractional order computation is now right, the cycle guard is in place, and the test assertion is tight. However, two issues remain: one is a latent semantic bug in the version-gate SQL that becomes a blocker if the RPC is ever called on a parentless node, and one is that the in-transaction OCC fix is untested at the store layer. Neither changes the correctness of the current frontend call site, so the overall change is still a net positive. Review of Prior Findings✅ Fix 1: Fractional order chaining — CorrectThe iterative ✅ Fix 2a: Cycle guard — Correct
✅ Fix 3: Frontend exact-once assertion — Correct
|
| Criterion | Status |
|---|---|
New MoveChildrenToParent RPC + core op + SqliteStore transaction |
✅ |
createNode mid-list-split issues exactly one RPC |
✅ (assertion now === callsBefore + 1) |
Optimistic structureTree update preserved |
✅ |
Order/version reconciled via response + RelationshipUpdated |
✅ |
On failure: one rollback + 'child-transfer-failure' notification |
✅ |
No skipConflictDetection per-child loop remaining |
✅ |
| Atomicity test | ✅ (covers service-level OCC; store-level in-txn path uncovered) |
| OCC mapping (daemon): stale version → Aborted | ✅ |
| Order preservation test | ✅ |
| ADR amendment | ⏭️ deferred |
Verdict
Requesting changes — the changes() semantic bug (ambiguity between version-mismatch and no-parent-edge) is a latent correctness issue on the public RPC surface. The fix is small: either add a pre-DELETE version read inside the transaction, or split the SQL to distinguish the two 0-result causes. The observability gap on version_conflict("batch-child", 0, 0) is a secondary improvement. Everything else looks correct and the change remains a net positive on the primary acceptance criteria.
Round 3 review findings addressed✅ Fixed (3 items): 1. Root-node false positive — Added 2. Actionable conflict node ID — The 3. Store-layer atomicity tests — Two new
Total: 3867 frontend + 17 browser + 883 Rust tests pass (883 = +2 new store tests). |
…closes #1275) Replaces the N per-child MoveNode RPCs with a single all-or-nothing MoveChildrenToParent RPC that re-parents an ordered set of children in one database transaction. OCC failures now roll back the entire batch rather than leaving partial state. Changes span all five layers: - proto: new MoveChildrenToParent RPC + ChildMove/request/response messages - core: SqliteStore::move_children_to_parent (single txn, delete+insert per edge) + NodeService::move_children_to_parent (up-front OCC pre-validation on all children, delegates atomic edge swap, bumps versions, emits RelationshipUpdated) - daemon: gRPC handler using existing service_error_to_status pipeline - tauri: move_children_to_parent command registered in lib.rs - frontend: BackendAdapter interface + TauriAdapter + HttpAdapter + MockAdapter; createNode child-transfer branch issues exactly one moveChildrenToParent call instead of N moveNode calls; on failure the #656 child-transfer-failure notification is preserved verbatim Tests: 4 new Rust unit tests (success, all-or-nothing, non-container guard, order preservation); 1 new daemon OCC mapping test; frontend test updated to spy on moveChildrenToParent and assert single-RPC + rollback + #656 notification. All 3867 frontend + 881 Rust tests pass. Co-Authored-By: Claude <[email protected]>
…ard, tighten test
Three review findings addressed:
1. Fractional order chaining bug (sqlite_store.rs): was computing orders with
arbitrary prev=i*1000.0 instead of the previously assigned order. Now
accumulates iteratively with orders.last().copied() as prev, producing
correct sequential fractional values (e.g. [1.0, 2.0, 3.0]).
2. TOCTOU + missing cycle check (node_service/mod.rs):
- Store method now accepts (child_id, expected_version) pairs and validates
version inside the transaction using a version-gated DELETE + SELECT
changes() — any mid-flight concurrent bump is caught inside the txn.
- Added is_descendant() cycle guard in the service pre-validation loop,
matching move_node's guards exactly as specified by the issue.
3. Frontend "exactly once" assertion (reactive-node-service.test.ts):
Changed toBeGreaterThan(callsBefore) → toBe(callsBefore + 1) to enforce
the acceptance criterion that exactly one RPC is issued, not merely ≥1.
Skipped: HttpAdapter dev-proxy route (no server-side handlers exist for any
route — consistent with project pattern); ADR-026/031 amendment (separate
nodespace-docs doc/ branch, cross-linked via PR description).
Co-Authored-By: Claude <[email protected]>
…micity tests
Three re-review findings addressed:
1. Root-node false positive (node_service/mod.rs): added is_root_node() guard in
the pre-validation loop so root nodes get HierarchyViolation instead of a
spurious VersionConflict from the in-transaction changes()=0 path. Root nodes
have no has_child edge so the version-gated DELETE would always return 0 rows.
2. Actionable conflict node ID (node_service/mod.rs): the VERSION_CONFLICT error
re-mapping now parses the node ID out of the store's error string
("VERSION_CONFLICT: node '<id>' ...") using strip_prefix + split, so the
resulting NodeServiceError::VersionConflict carries the actual offending node
ID instead of "batch-child".
3. Store-layer atomicity tests (sqlite_store.rs): two new #[tokio::test] tests:
- test_move_children_to_parent_store_rejects_stale_version: calls the store
directly (bypassing service pre-validation) with a stale version token;
asserts VERSION_CONFLICT error + child1 still under original parent (rollback).
- test_move_children_to_parent_store_success_and_order: asserts correct strictly-
increasing orders and all children move to new_parent on success.
All 3867 frontend + 17 browser + 883 Rust tests pass (883 = +2 new store tests).
Co-Authored-By: Claude <[email protected]>
The vi.mock addition during rebase conflict resolution caused the OCC integration tests to fail — vi.fn().mockResolvedValue(undefined) on updateNode in the factory intercepted the vi.spyOn rejection setup, breaking the test's ability to simulate VERSION_CONFLICT responses. Main's version of this file already had moveChildrenToParent in its mock (added by #1278's dead-code cleanup). Restoring that version fixes 3 failing OCC integration tests. Co-Authored-By: Claude <[email protected]>
6b12876 to
c2e54e4
Compare
… (all-or-nothing) (#1276) * C3c: Atomic child-transfer-on-split — single MoveChildrenToParent RPC (closes #1275) Replaces the N per-child MoveNode RPCs with a single all-or-nothing MoveChildrenToParent RPC that re-parents an ordered set of children in one database transaction. OCC failures now roll back the entire batch rather than leaving partial state. Changes span all five layers: - proto: new MoveChildrenToParent RPC + ChildMove/request/response messages - core: SqliteStore::move_children_to_parent (single txn, delete+insert per edge) + NodeService::move_children_to_parent (up-front OCC pre-validation on all children, delegates atomic edge swap, bumps versions, emits RelationshipUpdated) - daemon: gRPC handler using existing service_error_to_status pipeline - tauri: move_children_to_parent command registered in lib.rs - frontend: BackendAdapter interface + TauriAdapter + HttpAdapter + MockAdapter; createNode child-transfer branch issues exactly one moveChildrenToParent call instead of N moveNode calls; on failure the #656 child-transfer-failure notification is preserved verbatim Tests: 4 new Rust unit tests (success, all-or-nothing, non-container guard, order preservation); 1 new daemon OCC mapping test; frontend test updated to spy on moveChildrenToParent and assert single-RPC + rollback + #656 notification. All 3867 frontend + 881 Rust tests pass. Co-Authored-By: Claude <[email protected]> * Address review: fix order chaining, add in-transaction OCC + cycle guard, tighten test Three review findings addressed: 1. Fractional order chaining bug (sqlite_store.rs): was computing orders with arbitrary prev=i*1000.0 instead of the previously assigned order. Now accumulates iteratively with orders.last().copied() as prev, producing correct sequential fractional values (e.g. [1.0, 2.0, 3.0]). 2. TOCTOU + missing cycle check (node_service/mod.rs): - Store method now accepts (child_id, expected_version) pairs and validates version inside the transaction using a version-gated DELETE + SELECT changes() — any mid-flight concurrent bump is caught inside the txn. - Added is_descendant() cycle guard in the service pre-validation loop, matching move_node's guards exactly as specified by the issue. 3. Frontend "exactly once" assertion (reactive-node-service.test.ts): Changed toBeGreaterThan(callsBefore) → toBe(callsBefore + 1) to enforce the acceptance criterion that exactly one RPC is issued, not merely ≥1. Skipped: HttpAdapter dev-proxy route (no server-side handlers exist for any route — consistent with project pattern); ADR-026/031 amendment (separate nodespace-docs doc/ branch, cross-linked via PR description). Co-Authored-By: Claude <[email protected]> * Address review: root-node guard, actionable error ID, store-layer atomicity tests Three re-review findings addressed: 1. Root-node false positive (node_service/mod.rs): added is_root_node() guard in the pre-validation loop so root nodes get HierarchyViolation instead of a spurious VersionConflict from the in-transaction changes()=0 path. Root nodes have no has_child edge so the version-gated DELETE would always return 0 rows. 2. Actionable conflict node ID (node_service/mod.rs): the VERSION_CONFLICT error re-mapping now parses the node ID out of the store's error string ("VERSION_CONFLICT: node '<id>' ...") using strip_prefix + split, so the resulting NodeServiceError::VersionConflict carries the actual offending node ID instead of "batch-child". 3. Store-layer atomicity tests (sqlite_store.rs): two new #[tokio::test] tests: - test_move_children_to_parent_store_rejects_stale_version: calls the store directly (bypassing service pre-validation) with a stale version token; asserts VERSION_CONFLICT error + child1 still under original parent (rollback). - test_move_children_to_parent_store_success_and_order: asserts correct strictly- increasing orders and all children move to new_parent on success. All 3867 frontend + 17 browser + 883 Rust tests pass (883 = +2 new store tests). Co-Authored-By: Claude <[email protected]> * Fix: remove spurious vi.mock from conflict-notification test The vi.mock addition during rebase conflict resolution caused the OCC integration tests to fail — vi.fn().mockResolvedValue(undefined) on updateNode in the factory intercepted the vi.spyOn rejection setup, breaking the test's ability to simulate VERSION_CONFLICT responses. Main's version of this file already had moveChildrenToParent in its mock (added by #1278's dead-code cleanup). Restoring that version fixes 3 failing OCC integration tests. Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
Closes #1275