Repository navigation
Ratify & harden node deletion strategy: atomic subtree CASCADE over has_child edges (+ confirmation + ADR) - #1280
Conversation
Backend (packages/core, packages/daemon, packages/proto):
- Replace per-child recursive delete loop with SqliteStore::delete_subtree_atomic:
single transaction, WITH RECURSIVE descendant collection, OCC check on target
only, DELETE FROM node WHERE id IN (...), FK CASCADE cleans edges/embeddings,
emits one NodeDeleted notification per deleted node after commit
- delete_node_cascade_atomic removed (was never atomic — dead stub)
- NodeService::delete_node now returns DeleteResult { existed, deleted_count }
- Proto DeleteNodeResponse gains deleted_count: uint64
- Daemon and Tauri command propagate deleted_count through
- 4 new Rust tests: cascade correctness, atomicity on version conflict, OCC guards
target-only, idempotent missing-node
Frontend (packages/desktop-app):
- DeleteResult interface updated to { existed, deletedCount }
- delete-confirmation.svelte.ts: promise-based confirmation service using $state
- delete-confirmation-modal.svelte: "Delete N descendants?" modal, mounted globally
in +layout.svelte
- ReactiveNodeService::deleteNode now async: fetches descendant count, shows
confirmation for N > 0, aborts on cancel
- Tests updated: deleteNode calls awaited, DeleteResult mock shape updated
Co-Authored-By: Claude <[email protected]>
Code Review SummaryPR #1280 is a well-scoped, architecturally sound change that delivers on the core promise: replace non-atomic recursive deletion with a single-transaction subtree CASCADE, gate it behind a frontend confirmation dialog, and document the decision in an ADR. The Rust backend work is particularly solid — the dual OCC check (pre-check + re-check inside the transaction) is the correct pattern, the test suite covers all four acceptance-criteria scenarios, and the proto field addition is backward-compatible. This is a net improvement and approaches merge-ready, with two issues to address before landing. Findings[Improvement] Modal keyboard shortcuts broken: inner
|
| Criterion | Status |
|---|---|
| Single-transaction subtree delete | PASS — delete_subtree_atomic with one tx.execute |
| Mid-operation failure leaves subtree intact | PASS — test_delete_node_version_conflict_leaves_subtree_intact |
| OCC guards only target | PASS — test_delete_node_occ_guards_only_target_not_descendants |
One NodeDeleted event per deleted node |
PASS — post-commit notify loop in sqlite_store.rs |
| Frontend shows "Delete N descendants?" when N > 0 | PARTIAL — dialog wording is correct; keyboard dismiss is broken (see above) |
delete_node_cascade_atomic dead stub removed |
PASS — renamed and genuinely implemented |
| ADR merged in nodespace-docs | PASS — ADR-036 committed to nodespace-docs main |
| Cancel = no-op (untested) | MISSING — no test for cancel path |
Decision: Request Changes — the keyboard handler inversion in the modal is a behavioural bug (not just a nit), and the cancel-path test gap leaves an acceptance criterion untested. Both are small fixes. Once those two items land the PR is good to merge.
malibio
left a comment
There was a problem hiding this comment.
Review status: CHANGES REQUESTED. Two items to address before merge: (1) the modal keyboard handler is inverted — the inner modal div's onkeydown stops propagation before Escape/Enter can reach the overlay's handleKeydown; move handleKeydown to the inner modal div. (2) add a test for the cancel path (mock getDescendants to return a non-empty array, resolve confirmNodeDeletion as false, assert events.nodeDeleted is not called). Full findings in the detailed comment above.
…ests, guard concurrent confirmations - Move onkeydown handler from overlay to inner modal div (was blocked by stopPropagation) - Guard confirmNodeDeletion against concurrent calls (second call returns false immediately) - Add mock for delete-confirmation.svelte in reactive-node-service tests - Add 3 new tests: shows confirmation with N descendants, cancel aborts deletion (no mutation), leaf nodes skip confirmation (descendantCount=0) Co-Authored-By: Claude <[email protected]>
…as_child edges (+ confirmation + ADR) (#1280) * Atomic subtree CASCADE delete with frontend confirmation (#220) Backend (packages/core, packages/daemon, packages/proto): - Replace per-child recursive delete loop with SqliteStore::delete_subtree_atomic: single transaction, WITH RECURSIVE descendant collection, OCC check on target only, DELETE FROM node WHERE id IN (...), FK CASCADE cleans edges/embeddings, emits one NodeDeleted notification per deleted node after commit - delete_node_cascade_atomic removed (was never atomic — dead stub) - NodeService::delete_node now returns DeleteResult { existed, deleted_count } - Proto DeleteNodeResponse gains deleted_count: uint64 - Daemon and Tauri command propagate deleted_count through - 4 new Rust tests: cascade correctness, atomicity on version conflict, OCC guards target-only, idempotent missing-node Frontend (packages/desktop-app): - DeleteResult interface updated to { existed, deletedCount } - delete-confirmation.svelte.ts: promise-based confirmation service using $state - delete-confirmation-modal.svelte: "Delete N descendants?" modal, mounted globally in +layout.svelte - ReactiveNodeService::deleteNode now async: fetches descendant count, shows confirmation for N > 0, aborts on cancel - Tests updated: deleteNode calls awaited, DeleteResult mock shape updated Co-Authored-By: Claude <[email protected]> * Address review: fix modal keyboard handling, add cancel/descendants tests, guard concurrent confirmations - Move onkeydown handler from overlay to inner modal div (was blocked by stopPropagation) - Guard confirmNodeDeletion against concurrent calls (second call returns false immediately) - Add mock for delete-confirmation.svelte in reactive-node-service tests - Add 3 new tests: shows confirmation with N descendants, cancel aborts deletion (no mutation), leaf nodes skip confirmation (descendantCount=0) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
Closes #220