Repository navigation
Fix Sibling Chain Integrity in combineNodes() Operation - #234
Conversation
## Changes ### Core Refactoring - **Extract shared `promoteChildren()` helper** with depth-aware parent selection - **Simplify `deleteNode()`** to be internal helper (no child handling) - **Unified logic in `combineNodes()`** handles all deletion scenarios ### Key Improvements 1. **Depth-Aware Child Promotion**: Children promoted to nearest ancestor at same depth 2. **Consistent Behavior**: Both empty and non-empty node deletion use same path 3. **Sibling Chain Integrity**: `removeFromSiblingChain()` repairs chain before deletion 4. **Single Source of Truth**: All child promotion logic in `promoteChildren()` ### Files Changed - `reactive-node-service.svelte.ts`: Refactored deletion and child promotion - `base-node-viewer.svelte`: Updated to always use `combineNodes()` ## Testing - All cases verified: empty nodes, nodes with content, nodes with children - Sibling chain repair logic consolidated - UI now consistently uses `combineNodes()` for all deletion scenarios 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This commit fixes a critical race condition in the combineNodes() function where node deletion could occur before sibling chain repairs completed, causing database locking errors and FOREIGN KEY constraint violations. Changes: - Made combineNodes() async to properly await sibling chain repairs - Identify affected nodes BEFORE calling removeFromSiblingChain() - Wait for all sibling chain updates to persist before deleting node - Updated all call sites to properly await combineNodes() - Updated event handlers in base-node-viewer.svelte to be async Technical Details: The issue was that removeFromSiblingChain() queues an async database operation via PersistenceCoordinator, but the original code immediately proceeded to delete the node without waiting. The fix: 1. Identifies nodes that will be affected (next sibling, children) 2. Calls removeFromSiblingChain() to queue the updates 3. Waits for those specific nodes to persist 4. Then safely deletes the node This ensures proper ordering: sibling chain repair → wait → deletion Files Modified: - reactive-node-service.svelte.ts: Made combineNodes() async - base-node-viewer.svelte: Made event handlers async - sibling-chain-integrity.test.ts: Updated test calls to await Related: - Issue #230: Fix Sibling Chain Integrity - PR #243: PersistenceCoordinator implementation - Rebased onto main to leverage new PersistenceCoordinator architecture 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
8da9c21 to
1c1761a
Compare
…entation This commit implements the suggested improvements from the code review: 1. **Timeout Fallback Validation in combineNodes()**: Added defensive check to validate that all expected nodes were persisted before deletion. If timeout occurs, logs detailed error but continues operation to avoid leaving UI in inconsistent state. 2. **Enhanced deleteNode() Documentation**: Clarified API contract with explicit warnings about child handling. Documents when direct deleteNode() usage is appropriate vs combineNodes(). Addresses reviewer concern about "internal helper" terminology for public API. 3. **Documented Batch Update Decision**: Added comment explaining why individual child updates are preferred over batch API. PersistenceCoordinator already handles batching at lower level, typical nodes have <10 children, and added complexity wouldn't justify minimal performance gain. Technical Details: - combineNodes() now captures return value from waitForNodeSaves() - Validates persistedNodes.size matches expected nodesToWaitFor.length - Logs failed node IDs for debugging if timeout occurs - deleteNode() JSDoc now includes use cases and explicit API guidance Related: Issue #230, PR #234 code review feedback 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code Review Improvements ImplementedAddressed all suggested improvements from the pragmatic code review: ✅ Improvement #1: Timeout Fallback ValidationLocation: Added defensive validation to ensure all expected nodes were persisted before deletion:
✅ Improvement #2: Enhanced deleteNode() DocumentationLocation: Clarified API contract with comprehensive documentation:
✅ Improvement #3: Batch Update Decision DocumentedLocation: Added comment explaining optimization decision:
Engineering Principles Applied
All quality checks pass ✅ |
|
Triggering GitHub sync... |
Reopening for MergeThis PR was closed as a duplicate, but it actually contains the implementation of the fix for Issue #230. The commits in this PR are:
These changes are not yet in main and need to be merged to complete Issue #230. What this PR does:
Proceeding with merge now. |
* Fix sibling chain integrity with unified child promotion logic (#230) ## Changes ### Core Refactoring - **Extract shared `promoteChildren()` helper** with depth-aware parent selection - **Simplify `deleteNode()`** to be internal helper (no child handling) - **Unified logic in `combineNodes()`** handles all deletion scenarios ### Key Improvements 1. **Depth-Aware Child Promotion**: Children promoted to nearest ancestor at same depth 2. **Consistent Behavior**: Both empty and non-empty node deletion use same path 3. **Sibling Chain Integrity**: `removeFromSiblingChain()` repairs chain before deletion 4. **Single Source of Truth**: All child promotion logic in `promoteChildren()` ### Files Changed - `reactive-node-service.svelte.ts`: Refactored deletion and child promotion - `base-node-viewer.svelte`: Updated to always use `combineNodes()` ## Testing - All cases verified: empty nodes, nodes with content, nodes with children - Sibling chain repair logic consolidated - UI now consistently uses `combineNodes()` for all deletion scenarios 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix sibling chain integrity in combineNodes operation This commit fixes a critical race condition in the combineNodes() function where node deletion could occur before sibling chain repairs completed, causing database locking errors and FOREIGN KEY constraint violations. Changes: - Made combineNodes() async to properly await sibling chain repairs - Identify affected nodes BEFORE calling removeFromSiblingChain() - Wait for all sibling chain updates to persist before deleting node - Updated all call sites to properly await combineNodes() - Updated event handlers in base-node-viewer.svelte to be async Technical Details: The issue was that removeFromSiblingChain() queues an async database operation via PersistenceCoordinator, but the original code immediately proceeded to delete the node without waiting. The fix: 1. Identifies nodes that will be affected (next sibling, children) 2. Calls removeFromSiblingChain() to queue the updates 3. Waits for those specific nodes to persist 4. Then safely deletes the node This ensures proper ordering: sibling chain repair → wait → deletion Files Modified: - reactive-node-service.svelte.ts: Made combineNodes() async - base-node-viewer.svelte: Made event handlers async - sibling-chain-integrity.test.ts: Updated test calls to await Related: - Issue #230: Fix Sibling Chain Integrity - PR #243: PersistenceCoordinator implementation - Rebased onto main to leverage new PersistenceCoordinator architecture 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback: improve defensive programming and documentation This commit implements the suggested improvements from the code review: 1. **Timeout Fallback Validation in combineNodes()**: Added defensive check to validate that all expected nodes were persisted before deletion. If timeout occurs, logs detailed error but continues operation to avoid leaving UI in inconsistent state. 2. **Enhanced deleteNode() Documentation**: Clarified API contract with explicit warnings about child handling. Documents when direct deleteNode() usage is appropriate vs combineNodes(). Addresses reviewer concern about "internal helper" terminology for public API. 3. **Documented Batch Update Decision**: Added comment explaining why individual child updates are preferred over batch API. PersistenceCoordinator already handles batching at lower level, typical nodes have <10 children, and added complexity wouldn't justify minimal performance gain. Technical Details: - combineNodes() now captures return value from waitForNodeSaves() - Validates persistedNodes.size matches expected nodesToWaitFor.length - Logs failed node IDs for debugging if timeout occurs - deleteNode() JSDoc now includes use cases and explicit API guidance Related: Issue #230, PR #234 code review feedback 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* Fix sibling chain integrity with unified child promotion logic (#230) ## Changes ### Core Refactoring - **Extract shared `promoteChildren()` helper** with depth-aware parent selection - **Simplify `deleteNode()`** to be internal helper (no child handling) - **Unified logic in `combineNodes()`** handles all deletion scenarios ### Key Improvements 1. **Depth-Aware Child Promotion**: Children promoted to nearest ancestor at same depth 2. **Consistent Behavior**: Both empty and non-empty node deletion use same path 3. **Sibling Chain Integrity**: `removeFromSiblingChain()` repairs chain before deletion 4. **Single Source of Truth**: All child promotion logic in `promoteChildren()` ### Files Changed - `reactive-node-service.svelte.ts`: Refactored deletion and child promotion - `base-node-viewer.svelte`: Updated to always use `combineNodes()` ## Testing - All cases verified: empty nodes, nodes with content, nodes with children - Sibling chain repair logic consolidated - UI now consistently uses `combineNodes()` for all deletion scenarios 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix sibling chain integrity in combineNodes operation This commit fixes a critical race condition in the combineNodes() function where node deletion could occur before sibling chain repairs completed, causing database locking errors and FOREIGN KEY constraint violations. Changes: - Made combineNodes() async to properly await sibling chain repairs - Identify affected nodes BEFORE calling removeFromSiblingChain() - Wait for all sibling chain updates to persist before deleting node - Updated all call sites to properly await combineNodes() - Updated event handlers in base-node-viewer.svelte to be async Technical Details: The issue was that removeFromSiblingChain() queues an async database operation via PersistenceCoordinator, but the original code immediately proceeded to delete the node without waiting. The fix: 1. Identifies nodes that will be affected (next sibling, children) 2. Calls removeFromSiblingChain() to queue the updates 3. Waits for those specific nodes to persist 4. Then safely deletes the node This ensures proper ordering: sibling chain repair → wait → deletion Files Modified: - reactive-node-service.svelte.ts: Made combineNodes() async - base-node-viewer.svelte: Made event handlers async - sibling-chain-integrity.test.ts: Updated test calls to await Related: - Issue #230: Fix Sibling Chain Integrity - PR #243: PersistenceCoordinator implementation - Rebased onto main to leverage new PersistenceCoordinator architecture 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback: improve defensive programming and documentation This commit implements the suggested improvements from the code review: 1. **Timeout Fallback Validation in combineNodes()**: Added defensive check to validate that all expected nodes were persisted before deletion. If timeout occurs, logs detailed error but continues operation to avoid leaving UI in inconsistent state. 2. **Enhanced deleteNode() Documentation**: Clarified API contract with explicit warnings about child handling. Documents when direct deleteNode() usage is appropriate vs combineNodes(). Addresses reviewer concern about "internal helper" terminology for public API. 3. **Documented Batch Update Decision**: Added comment explaining why individual child updates are preferred over batch API. PersistenceCoordinator already handles batching at lower level, typical nodes have <10 children, and added complexity wouldn't justify minimal performance gain. Technical Details: - combineNodes() now captures return value from waitForNodeSaves() - Validates persistedNodes.size matches expected nodesToWaitFor.length - Logs failed node IDs for debugging if timeout occurs - deleteNode() JSDoc now includes use cases and explicit API guidance Related: Issue #230, PR #234 code review feedback 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* Fix sibling chain integrity with unified child promotion logic (#230) ## Changes ### Core Refactoring - **Extract shared `promoteChildren()` helper** with depth-aware parent selection - **Simplify `deleteNode()`** to be internal helper (no child handling) - **Unified logic in `combineNodes()`** handles all deletion scenarios ### Key Improvements 1. **Depth-Aware Child Promotion**: Children promoted to nearest ancestor at same depth 2. **Consistent Behavior**: Both empty and non-empty node deletion use same path 3. **Sibling Chain Integrity**: `removeFromSiblingChain()` repairs chain before deletion 4. **Single Source of Truth**: All child promotion logic in `promoteChildren()` ### Files Changed - `reactive-node-service.svelte.ts`: Refactored deletion and child promotion - `base-node-viewer.svelte`: Updated to always use `combineNodes()` ## Testing - All cases verified: empty nodes, nodes with content, nodes with children - Sibling chain repair logic consolidated - UI now consistently uses `combineNodes()` for all deletion scenarios 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix sibling chain integrity in combineNodes operation This commit fixes a critical race condition in the combineNodes() function where node deletion could occur before sibling chain repairs completed, causing database locking errors and FOREIGN KEY constraint violations. Changes: - Made combineNodes() async to properly await sibling chain repairs - Identify affected nodes BEFORE calling removeFromSiblingChain() - Wait for all sibling chain updates to persist before deleting node - Updated all call sites to properly await combineNodes() - Updated event handlers in base-node-viewer.svelte to be async Technical Details: The issue was that removeFromSiblingChain() queues an async database operation via PersistenceCoordinator, but the original code immediately proceeded to delete the node without waiting. The fix: 1. Identifies nodes that will be affected (next sibling, children) 2. Calls removeFromSiblingChain() to queue the updates 3. Waits for those specific nodes to persist 4. Then safely deletes the node This ensures proper ordering: sibling chain repair → wait → deletion Files Modified: - reactive-node-service.svelte.ts: Made combineNodes() async - base-node-viewer.svelte: Made event handlers async - sibling-chain-integrity.test.ts: Updated test calls to await Related: - Issue #230: Fix Sibling Chain Integrity - PR #243: PersistenceCoordinator implementation - Rebased onto main to leverage new PersistenceCoordinator architecture 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback: improve defensive programming and documentation This commit implements the suggested improvements from the code review: 1. **Timeout Fallback Validation in combineNodes()**: Added defensive check to validate that all expected nodes were persisted before deletion. If timeout occurs, logs detailed error but continues operation to avoid leaving UI in inconsistent state. 2. **Enhanced deleteNode() Documentation**: Clarified API contract with explicit warnings about child handling. Documents when direct deleteNode() usage is appropriate vs combineNodes(). Addresses reviewer concern about "internal helper" terminology for public API. 3. **Documented Batch Update Decision**: Added comment explaining why individual child updates are preferred over batch API. PersistenceCoordinator already handles batching at lower level, typical nodes have <10 children, and added complexity wouldn't justify minimal performance gain. Technical Details: - combineNodes() now captures return value from waitForNodeSaves() - Validates persistedNodes.size matches expected nodesToWaitFor.length - Logs failed node IDs for debugging if timeout occurs - deleteNode() JSDoc now includes use cases and explicit API guidance Related: Issue #230, PR #234 code review feedback 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Duplicate of #230. Closing to avoid confusion.
Work continues in: