Skip to content

Fix Shift+Tab outdent failing with 'Sibling not found' error after rapid node creation - #663

Merged
malibio merged 5 commits into
mainfrom
fix/issue-662-outdent-sibling-not-found
Nov 26, 2025
Merged

malibio merged 5 commits into
mainfrom
fix/issue-662-outdent-sibling-not-found

Conversation

@malibio

@malibio malibio commented Nov 26, 2025

Copy link
Copy Markdown
Collaborator

Closes #662

malibio and others added 4 commits November 26, 2025 10:21
…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]>
@malibio

malibio commented Nov 26, 2025

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Review Type: Initial Review
Branch: fix/issue-662-outdent-sibling-not-found
PR: #663 - Fix Shift+Tab outdent failing with 'Sibling not found' error after rapid node creation


Requirements Check (Issue #662)

Criterion Status Notes
Shift+Tab outdent succeeds after rapid node creation ✅ Implemented via waitForPendingMoveOperations() and flushAllPendingSaves()
No "Sibling not found" errors during normal outdent operations ✅ Race conditions addressed by tracking pending moves
Node moves only one level up (correct behavior) ✅ Using structureTree.getParent() as authoritative source
UI stays in sync with backend after outdent ✅ Optimistic UI with proper rollback on error
No new test failures ✅ Verified - 5 failures are pre-existing on main branch
Code passes bun run quality:fix ✅ Verified - no lint/format issues

Code Review Findings

Critical Issues

None identified.


Suggested Improvements

[Improvement] Missing test coverage for race condition scenario

File: N/A (missing test)
Rationale: The PR fixes a complex race condition involving rapid Enter+Tab+Shift+Tab sequences, but no integration test was added to verify this behavior. While the existing indent/outdent command tests verify the command layer, they don't test the async move operation tracking in reactive-node-service.svelte.ts.

Suggestion: Consider adding an integration test that simulates the race condition scenario described in the issue:

  1. Create a nested node
  2. Rapidly indent it
  3. Immediately outdent another node
  4. Verify no errors and correct final state

[Improvement] Module-level mutable state for pendingMoveOperations

File: /packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts (line 45)
Rationale: The pendingMoveOperations Map is declared at module scope, making it a global singleton. While this works correctly for the current architecture (single ReactiveNodeService per app instance), it could cause issues if multiple service instances are ever created (e.g., for testing or multi-window scenarios).

// Current (line 45):
const pendingMoveOperations: Map<string, Promise<void>> = new Map();

Suggestion: Consider whether this state should be encapsulated within the service factory or documented as an intentional architectural decision. Current behavior is acceptable given the service's singleton nature.


[Improvement] outdentNode doesn't track its move operation

File: /packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts (line 912)
Rationale: indentNode calls trackMoveOperation() to register its async move (line 800), but outdentNode does not. This asymmetry means that if a user rapidly outdents twice in a row, the second outdent might start before the first completes.

// indentNode (lines 797-800):
// Track this move so subsequent indent/outdent operations wait for it
trackMoveOperation(nodeId, moveOperation);

// outdentNode (line 912) - starts async block but doesn't track:
(async () => {
  try {
    await waitForPendingMoveOperations();
    ...

Suggestion: For completeness and defensive coding, consider tracking outdent operations as well to prevent potential rapid-outdent race conditions.


Nitpicks

Nit: Unused flushAndWaitForNodes method

File: /packages/desktop-app/src/lib/services/shared-node-store.ts (lines 212-246)
Note: The flushAndWaitForNodes() method in SimplePersistenceCoordinator and its public wrapper flushAndWaitForNodeSaves() in SharedNodeStore were added but the final implementation uses flushAll() / flushAllPendingSaves() instead. These more selective methods remain unused.

If they're being kept for future use, add a comment explaining the intent. Otherwise, consider removing to reduce surface area. Not blocking.


Nit: Comment references old approach

File: /packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts (line 911)
Note: The comment says "Fire-and-forget backend persistence (but wait for nodes to be persisted first!)" but the implementation now waits for ALL pending saves via flushAllPendingSaves(), not just specific nodes. Consider updating the comment to reflect the actual behavior.


Architecture Assessment

Positive Aspects:

  1. Proper separation of concerns - Pending move tracking is cleanly implemented as module-level coordination without polluting the service API
  2. Defensive waiting pattern - The waitForPendingMoveOperations() approach ensures moves complete in order
  3. Authoritative source fix - Using structureTree.getParent() instead of potentially stale Node.parentId is architecturally sound
  4. Clear documentation - Comments explain the race condition scenario and fix rationale

Domain Event Forwarder Disabling:
The PR disables DomainEventForwarder due to feedback loop issues. This is the correct interim solution, properly documented with issue #665 reference. This is acceptable given the greenfield nature of the project.


Test Results

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 malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Added pending move operation tracking to prevent race conditions during rapid indent/outdent
  2. Uses structureTree.getParent() as authoritative source for hierarchy during rapid edits
  3. 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]>
@malibio

malibio commented Nov 26, 2025

Copy link
Copy Markdown
Collaborator Author

Review Feedback Addressed ✅

Changes Made

Recommendation Status Details
🟡 Track outdent operations like indent ✅ Addressed Added trackMoveOperation() call in outdentNode() for consistency
🟢 Remove unused flushAndWaitForNodeSaves ✅ Addressed Removed method and updated docstring reference
🟡 Add test for race condition scenario ✅ Addressed Added 9 comprehensive tests in indent-outdent-race-condition.test.ts
🟢 Module-level state documentation ⏭️ Skipped Existing comment at line 43-45 already documents the pattern
🟢 Update comment about fire-and-forget ✅ Addressed Updated comment to match new tracking behavior

Skipped Recommendations (with reasoning)

  • Module-level pendingMoveOperations documentation: The existing code comment (lines 43-45 and 47-56) already clearly documents the purpose and singleton nature of this state. Additional documentation would be redundant.

Test Results

  • Frontend: 1454 passed, 5 failed (pre-existing failures on main)
  • Backend: 542 passed, 0 failed
  • Quality: ✅ All checks pass

New Tests Added

The new test file indent-outdent-race-condition.test.ts covers:

  1. Move operation tracking (add/remove/cleanup on failure)
  2. waitForPendingMoveOperations() behavior
  3. Race condition prevention scenarios
  4. Issue Fix Shift+Tab outdent failing with 'Sibling not found' error after rapid node creation #662 rapid Enter+Tab+Shift+Tab sequence

🤖 Generated with Claude Code

@malibio
malibio merged commit 8062dc0 into main Nov 26, 2025
@malibio
malibio deleted the fix/issue-662-outdent-sibling-not-found branch November 26, 2025 12:06
malibio added a commit that referenced this pull request Feb 4, 2026
…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]>
malibio added a commit that referenced this pull request Feb 5, 2026
…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]>
malibio added a commit that referenced this pull request Feb 26, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Shift+Tab outdent failing with 'Sibling not found' error after rapid node creation

1 participant