Skip to content

Fix Sibling Chain Integrity (7 test failures) #230

Closed

Description

@malibio

Bug: Sibling Chain Integrity Failures

Related to: Issue #208 (Comprehensive Test Coverage)
Test File: src/tests/integration/sibling-chain-integrity.test.ts
Failures: 7/7 tests failing (100% failure rate)

Problem

The comprehensive tests have exposed critical bugs in sibling chain (beforeSiblingId linked list) maintenance:

  • Chain breaks during node deletion
  • Chain corruption during indent/outdent
  • Circular references possible
  • Chain not repaired during node combining
  • Complex operation sequences break integrity

Failing Tests

  1. should repair chain when node is deleted
  2. should maintain chain integrity during indent operation
  3. should maintain chain integrity during outdent operation
  4. should maintain chain when combining nodes
  5. should validate chain has no circular references
  6. should maintain chain integrity with complex operations sequence
  7. (One more - see test output)

Impact

HIGH SEVERITY: Sibling chain is fundamental to node ordering. All bugs in this area cause visual order corruption and data loss.

Acceptance Criteria

  • All 7 tests pass
  • Chain repairs correctly after deletions
  • No circular references possible
  • Indent/outdent maintain integrity
  • Complex sequences work correctly

Testing

Run: bun run test src/tests/integration/sibling-chain-integrity.test.ts

Activity

  1. self-assigned this
    on Oct 11, 2025
  2. malibio commented on Oct 12, 2025

    @malibio
    CollaboratorAuthor

    Progress Update: Session 1 - Core Refactoring Complete

    Work Completed ✅

    Major Refactoring:

    1. Extracted shared promoteChildren() helper with depth-aware parent selection logic
    2. Simplified deleteNode() to be internal helper (no child handling, just chain repair + storage removal)
    3. Unified all deletion logic in combineNodes() - now handles both empty and non-empty nodes
    4. Updated UI layer (base-node-viewer.svelte) to always use combineNodes() instead of calling deleteNode() directly

    Key Files Modified:

    • packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts (93 insertions, 107 deletions)
    • packages/desktop-app/src/lib/design/components/base-node-viewer.svelte

    Architecture Improvements:

    • ✅ Depth-aware child promotion (children go to nearest ancestor at same depth)
    • ✅ Single source of truth for child promotion logic
    • ✅ Consistent removeFromSiblingChain() usage before all deletions
    • ✅ All node deletion flows through combineNodes()

    Git Status:

    Current Status 🔄

    Test Infrastructure Now Working:

    Test Results:

    Test Files: 1 failed (1)
    Tests: 6 failed | 1 passed (7)
    

    Actual Errors Being Surfaced:

    1. FOREIGN KEY constraint failed - Nodes referencing non-existent beforeSiblingId values
    2. NodeNotFound - Operations trying to update already-deleted nodes
    3. database is locked - Concurrent access issues (may be separate from sibling chain bugs)

    What Needs Investigation 🔍

    The refactoring is logically correct but tests still fail because:

    1. FOREIGN KEY failures suggest orphaned pointers still exist - Need to trace where chains break:

      • Are children being promoted with correct beforeSiblingId values?
      • Is removeFromSiblingChain() being called at the right time?
      • Are there race conditions between in-memory updates and database writes?
    2. NodeNotFound errors suggest:

    3. Database locking suggests:

      • Too many concurrent writes
      • Need better write queueing
      • May be unrelated to sibling chain logic

    Debug Strategy for Next Session 📋

    Recommended approach:

    1. Run single test in isolation to reduce noise:

      bunx vitest run src/tests/integration/sibling-chain-integrity.test.ts -t "should repair chain when node is deleted"
    2. Add detailed logging to trace chain updates:

      • Log all removeFromSiblingChain() calls with before/after state
      • Log all promoteChildren() operations
      • Log all beforeSiblingId updates
    3. Check interaction with PersistenceCoordinator (added in Implement PersistenceCoordinator for Dependency-Based Persistence #242):

      • My changes assume synchronous in-memory updates
      • New dependency-based persistence might change execution order
      • May need to ensure chain updates happen atomically
    4. Verify database schema has proper foreign key constraints:

      • Check if beforeSiblingId has FK constraint to nodes table
      • Understand what triggers the constraint violations

    Handoff Notes for Next Agent 📝

    Context:

    • Issue Fix Sibling Chain Integrity (7 test failures) #230 is about fixing 7 failing sibling chain integrity tests
    • I completed a major refactoring to unify child promotion logic
    • Tests now run but expose real bugs (FOREIGN KEY violations)
    • Code is logically sound but something in execution is breaking chains

    Current Branch State:

    Dev Environment:

    • Dev server must be running: cd packages/desktop-app/src-tauri && cargo run --bin dev-server --features dev-server
    • Run tests: cd packages/desktop-app && bunx vitest run src/tests/integration/sibling-chain-integrity.test.ts
    • Check logs: tail -f /tmp/dev-server-latest.log

    Key Functions to Review:

    • promoteChildren() - Line ~1010 in reactive-node-service.svelte.ts
    • deleteNode() - Line ~1084 (now simplified)
    • combineNodes() - Line ~707 (calls promoteChildren)
    • removeFromSiblingChain() - Line ~752

    Next Steps:

    1. Add logging to trace sibling chain updates
    2. Run one test at a time to isolate failures
    3. Check if PersistenceCoordinator is deferring writes unexpectedly
    4. Verify FK constraints in database schema
    5. Fix any remaining chain repair logic bugs

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions