Repository navigation
Fix Shift+Tab outdent failing with 'Sibling not found' error after rapid node creation - #663
Conversation
…tion When outdenting a node, the backend uses the oldParentId (passed as insertAfterNodeId) to position the outdented node. The backend queries for children of newParentId and expects to find oldParentId among them. Previously, we only waited for the node being moved to be persisted, but not for oldParentId. This caused a race condition when rapidly creating nested nodes and immediately outdenting - the oldParentId's edge might not be persisted yet. Fix: Wait for BOTH nodeId AND oldParentId to be persisted before calling moveNodeCommand. Closes #662 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The previous fix waited for node saves but didn't account for debounced operations. When rapidly creating nested nodes via Tab, node creation uses debounced persistence (500ms) to coalesce rapid updates. If the user outdents before the debounce timer fires, moveNode fails with "Sibling not found" because the parent-child edge hasn't been created. Solution: - Add flushAndWaitForNodes() method to SimplePersistenceCoordinator that clears debounce timers and executes operations immediately - Expose this via flushAndWaitForNodeSaves() on SharedNodeStore - Use flushAndWaitForNodeSaves() in outdentNode() to ensure nodes are fully persisted before calling backend moveNode() This ensures both the node records AND their has_child edges exist in the database before dependent operations reference them. Fixes #662 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The previous fix only flushed specific nodes (nodeId, oldParentId, newParentId), but this wasn't sufficient when other nodes in the hierarchy also had pending saves that affected parent-child edges. Changes: - Added flushAll() method to SimplePersistenceCoordinator to flush entire queue - Added flushAllPendingSaves() public method on SharedNodeStore - Changed outdentNode to use flushAllPendingSaves() instead of selective flushing This ensures ALL pending node saves complete before moveNode, guaranteeing that all parent-child edges exist in the database. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Root cause: Two separate issues caused "Sibling not found" errors during rapid Enter+Tab+Shift+Tab operations: 1. Fire-and-forget moves: indentNode executed moveNodeCommand async without tracking, so outdentNode could start before edges existed in database. 2. Stale parentId: outdentNode read parent.parentId from Node object which could be stale. ReactiveStructureTree is updated synchronously but the Node object's parentId was not reflecting the latest hierarchy. Fix: - Add pendingMoveOperations tracking for indent/outdent move commands - waitForPendingMoveOperations() ensures moves complete in order - Use structureTree.getParent() as authoritative source for parent hierarchy - Disable DomainEventForwarder (causes feedback loops, tracked in #665) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code Review SummaryReview Type: Initial Review Requirements Check (Issue #662)
Code Review FindingsCritical IssuesNone identified. Suggested Improvements[Improvement] Missing test coverage for race condition scenarioFile: N/A (missing test) Suggestion: Consider adding an integration test that simulates the race condition scenario described in the issue:
[Improvement] Module-level mutable state for
|
| Suite | Status |
|---|---|
| Frontend (Vitest) | 1445/1450 passed (5 failures pre-existing on main) |
| Backend (Rust) | 542 passed, 0 failed |
| Quality checks | ✅ Passed |
Recommendation
APPROVE
The implementation correctly addresses the race condition described in issue #662. The fix is well-designed, using proper async coordination patterns. The code is readable, well-documented, and follows project conventions.
The suggested improvements are non-blocking and can be addressed in follow-up work if desired.
🤖 Generated with Claude Code
malibio
left a comment
There was a problem hiding this comment.
Approving this PR. The implementation correctly addresses the race condition described in issue #662 using proper async coordination patterns. The code is well-designed, readable, and follows project conventions.
Key fixes:
- Added pending move operation tracking to prevent race conditions during rapid indent/outdent
- Uses structureTree.getParent() as authoritative source for hierarchy during rapid edits
- Flushes all pending saves before moveNode operations
Suggested improvements (non-blocking):
- Consider adding integration test for race condition scenario
- Consider tracking outdent operations like indent for consistency
- Minor comment updates to reflect actual behavior
The domain event forwarder disabling is appropriate and properly documented with issue #665 reference.
Test results verified: 1445/1450 frontend tests pass (5 pre-existing failures on main), 542 Rust tests pass.
Recommendation: APPROVE
…tests - Track outdentNode move operations via trackMoveOperation() for consistency with indentNode, preventing potential rapid-outdent race conditions - Remove unused flushAndWaitForNodeSaves() method from SharedNodeStore - Update flushAllPendingSaves() docstring to remove stale reference - Add comprehensive test suite for indent/outdent race condition prevention (9 tests covering the Issue #662 scenario) Addresses reviewer recommendations from PR #663 review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Review Feedback Addressed ✅Changes Made
Skipped Recommendations (with reasoning)
Test Results
New Tests AddedThe new test file
🤖 Generated with Claude Code |
…pid node creation (#663) * Fix Shift+Tab outdent 'Sibling not found' error after rapid node creation When outdenting a node, the backend uses the oldParentId (passed as insertAfterNodeId) to position the outdented node. The backend queries for children of newParentId and expects to find oldParentId among them. Previously, we only waited for the node being moved to be persisted, but not for oldParentId. This caused a race condition when rapidly creating nested nodes and immediately outdenting - the oldParentId's edge might not be persisted yet. Fix: Wait for BOTH nodeId AND oldParentId to be persisted before calling moveNodeCommand. Closes #662 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix outdent race condition by flushing debounced saves before moveNode The previous fix waited for node saves but didn't account for debounced operations. When rapidly creating nested nodes via Tab, node creation uses debounced persistence (500ms) to coalesce rapid updates. If the user outdents before the debounce timer fires, moveNode fails with "Sibling not found" because the parent-child edge hasn't been created. Solution: - Add flushAndWaitForNodes() method to SimplePersistenceCoordinator that clears debounce timers and executes operations immediately - Expose this via flushAndWaitForNodeSaves() on SharedNodeStore - Use flushAndWaitForNodeSaves() in outdentNode() to ensure nodes are fully persisted before calling backend moveNode() This ensures both the node records AND their has_child edges exist in the database before dependent operations reference them. Fixes #662 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix outdent race condition by flushing ALL pending saves before moveNode The previous fix only flushed specific nodes (nodeId, oldParentId, newParentId), but this wasn't sufficient when other nodes in the hierarchy also had pending saves that affected parent-child edges. Changes: - Added flushAll() method to SimplePersistenceCoordinator to flush entire queue - Added flushAllPendingSaves() public method on SharedNodeStore - Changed outdentNode to use flushAllPendingSaves() instead of selective flushing This ensures ALL pending node saves complete before moveNode, guaranteeing that all parent-child edges exist in the database. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix outdent race condition with pending move tracking and stale parentId Root cause: Two separate issues caused "Sibling not found" errors during rapid Enter+Tab+Shift+Tab operations: 1. Fire-and-forget moves: indentNode executed moveNodeCommand async without tracking, so outdentNode could start before edges existed in database. 2. Stale parentId: outdentNode read parent.parentId from Node object which could be stale. ReactiveStructureTree is updated synchronously but the Node object's parentId was not reflecting the latest hierarchy. Fix: - Add pendingMoveOperations tracking for indent/outdent move commands - waitForPendingMoveOperations() ensures moves complete in order - Use structureTree.getParent() as authoritative source for parent hierarchy - Disable DomainEventForwarder (causes feedback loops, tracked in #665) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: track outdent operations, cleanup unused method, add tests - Track outdentNode move operations via trackMoveOperation() for consistency with indentNode, preventing potential rapid-outdent race conditions - Remove unused flushAndWaitForNodeSaves() method from SharedNodeStore - Update flushAllPendingSaves() docstring to remove stale reference - Add comprehensive test suite for indent/outdent race condition prevention (9 tests covering the Issue #662 scenario) Addresses reviewer recommendations from PR #663 review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
…pid node creation (#663) * Fix Shift+Tab outdent 'Sibling not found' error after rapid node creation When outdenting a node, the backend uses the oldParentId (passed as insertAfterNodeId) to position the outdented node. The backend queries for children of newParentId and expects to find oldParentId among them. Previously, we only waited for the node being moved to be persisted, but not for oldParentId. This caused a race condition when rapidly creating nested nodes and immediately outdenting - the oldParentId's edge might not be persisted yet. Fix: Wait for BOTH nodeId AND oldParentId to be persisted before calling moveNodeCommand. Closes #662 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix outdent race condition by flushing debounced saves before moveNode The previous fix waited for node saves but didn't account for debounced operations. When rapidly creating nested nodes via Tab, node creation uses debounced persistence (500ms) to coalesce rapid updates. If the user outdents before the debounce timer fires, moveNode fails with "Sibling not found" because the parent-child edge hasn't been created. Solution: - Add flushAndWaitForNodes() method to SimplePersistenceCoordinator that clears debounce timers and executes operations immediately - Expose this via flushAndWaitForNodeSaves() on SharedNodeStore - Use flushAndWaitForNodeSaves() in outdentNode() to ensure nodes are fully persisted before calling backend moveNode() This ensures both the node records AND their has_child edges exist in the database before dependent operations reference them. Fixes #662 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix outdent race condition by flushing ALL pending saves before moveNode The previous fix only flushed specific nodes (nodeId, oldParentId, newParentId), but this wasn't sufficient when other nodes in the hierarchy also had pending saves that affected parent-child edges. Changes: - Added flushAll() method to SimplePersistenceCoordinator to flush entire queue - Added flushAllPendingSaves() public method on SharedNodeStore - Changed outdentNode to use flushAllPendingSaves() instead of selective flushing This ensures ALL pending node saves complete before moveNode, guaranteeing that all parent-child edges exist in the database. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix outdent race condition with pending move tracking and stale parentId Root cause: Two separate issues caused "Sibling not found" errors during rapid Enter+Tab+Shift+Tab operations: 1. Fire-and-forget moves: indentNode executed moveNodeCommand async without tracking, so outdentNode could start before edges existed in database. 2. Stale parentId: outdentNode read parent.parentId from Node object which could be stale. ReactiveStructureTree is updated synchronously but the Node object's parentId was not reflecting the latest hierarchy. Fix: - Add pendingMoveOperations tracking for indent/outdent move commands - waitForPendingMoveOperations() ensures moves complete in order - Use structureTree.getParent() as authoritative source for parent hierarchy - Disable DomainEventForwarder (causes feedback loops, tracked in #665) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: track outdent operations, cleanup unused method, add tests - Track outdentNode move operations via trackMoveOperation() for consistency with indentNode, preventing potential rapid-outdent race conditions - Remove unused flushAndWaitForNodeSaves() method from SharedNodeStore - Update flushAllPendingSaves() docstring to remove stale reference - Add comprehensive test suite for indent/outdent race condition prevention (9 tests covering the Issue #662 scenario) Addresses reviewer recommendations from PR #663 review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
…pid node creation (#663) * Fix Shift+Tab outdent 'Sibling not found' error after rapid node creation When outdenting a node, the backend uses the oldParentId (passed as insertAfterNodeId) to position the outdented node. The backend queries for children of newParentId and expects to find oldParentId among them. Previously, we only waited for the node being moved to be persisted, but not for oldParentId. This caused a race condition when rapidly creating nested nodes and immediately outdenting - the oldParentId's edge might not be persisted yet. Fix: Wait for BOTH nodeId AND oldParentId to be persisted before calling moveNodeCommand. Closes #662 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix outdent race condition by flushing debounced saves before moveNode The previous fix waited for node saves but didn't account for debounced operations. When rapidly creating nested nodes via Tab, node creation uses debounced persistence (500ms) to coalesce rapid updates. If the user outdents before the debounce timer fires, moveNode fails with "Sibling not found" because the parent-child edge hasn't been created. Solution: - Add flushAndWaitForNodes() method to SimplePersistenceCoordinator that clears debounce timers and executes operations immediately - Expose this via flushAndWaitForNodeSaves() on SharedNodeStore - Use flushAndWaitForNodeSaves() in outdentNode() to ensure nodes are fully persisted before calling backend moveNode() This ensures both the node records AND their has_child edges exist in the database before dependent operations reference them. Fixes #662 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix outdent race condition by flushing ALL pending saves before moveNode The previous fix only flushed specific nodes (nodeId, oldParentId, newParentId), but this wasn't sufficient when other nodes in the hierarchy also had pending saves that affected parent-child edges. Changes: - Added flushAll() method to SimplePersistenceCoordinator to flush entire queue - Added flushAllPendingSaves() public method on SharedNodeStore - Changed outdentNode to use flushAllPendingSaves() instead of selective flushing This ensures ALL pending node saves complete before moveNode, guaranteeing that all parent-child edges exist in the database. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix outdent race condition with pending move tracking and stale parentId Root cause: Two separate issues caused "Sibling not found" errors during rapid Enter+Tab+Shift+Tab operations: 1. Fire-and-forget moves: indentNode executed moveNodeCommand async without tracking, so outdentNode could start before edges existed in database. 2. Stale parentId: outdentNode read parent.parentId from Node object which could be stale. ReactiveStructureTree is updated synchronously but the Node object's parentId was not reflecting the latest hierarchy. Fix: - Add pendingMoveOperations tracking for indent/outdent move commands - waitForPendingMoveOperations() ensures moves complete in order - Use structureTree.getParent() as authoritative source for parent hierarchy - Disable DomainEventForwarder (causes feedback loops, tracked in #665) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: track outdent operations, cleanup unused method, add tests - Track outdentNode move operations via trackMoveOperation() for consistency with indentNode, preventing potential rapid-outdent race conditions - Remove unused flushAndWaitForNodeSaves() method from SharedNodeStore - Update flushAllPendingSaves() docstring to remove stale reference - Add comprehensive test suite for indent/outdent race condition prevention (9 tests covering the Issue #662 scenario) Addresses reviewer recommendations from PR #663 review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Closes #662