Skip to content

feat: Preserve created_at on same-parent reorders (Issue #795) - #796

Merged
malibio merged 2 commits into
mainfrom
feature/issue-795-sync-ready-relationship-timestamps
Jan 7, 2026
Merged

malibio merged 2 commits into
mainfrom
feature/issue-795-sync-ready-relationship-timestamps

Conversation

@malibio

@malibio malibio commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Same-parent reorder: Uses UPDATE to preserve created_at and increment version
  • Cross-parent move: Uses DELETE + CREATE (new relationship, new timestamps)

This differentiation is critical for cloud sync and conflict resolution.

Changes Made

Modified move_node in surreal_store.rs to detect same-parent reorders and use UPDATE instead of DELETE + CREATE.

Test plan

  • test_same_parent_reorder_preserves_created_at - verifies timestamp preservation
  • test_same_parent_reorder_increments_version - verifies version increment
  • test_cross_parent_move_creates_new_relationship - verifies new timestamps/version
  • test_multiple_same_parent_reorders_accumulate_version - verifies version accumulation

Acceptance Criteria

  • move_node detects if parent is changing vs. just reordering
  • Same-parent reorder uses UPDATE (preserves created_at, increments version)
  • Cross-parent move uses DELETE + CREATE (current behavior)
  • modified_at updated on both operations
  • Tests verify timestamp preservation on same-parent reorder
  • Tests verify version increments on reorder (for OCC)

Test Results

Baseline:

  • Frontend: 3431 tests passed (101 test files)
  • Rust nodespace-app: 23 tests passed
  • Rust nodespace-core: 673 passed (1 pre-existing failure)

After changes:

  • All new tests pass ✅
  • All existing move_node tests pass ✅
  • Frontend tests unchanged ✅

Closes #795

🤖 Generated with Claude Code

## Summary
Differentiate between same-parent reorder and cross-parent move operations
in the `move_node` function to support cloud sync and conflict resolution.

## Changes
- **Same-parent reorder**: Now uses UPDATE to preserve `created_at`,
  update `modified_at`, and increment `version` for OCC
- **Cross-parent move**: Continues to use DELETE + CREATE (new relationship
  gets new `created_at` and `version` reset to 1)
- Added detection logic to compare current parent with target parent

## Benefits
- **Sync-ready**: Preserved timestamps enable accurate conflict resolution
- **OCC support**: Version increment enables optimistic concurrency control
- **Distinguishable operations**: Sync systems can differentiate reorders
  from cross-parent moves

## Tests Added
- `test_same_parent_reorder_preserves_created_at`
- `test_same_parent_reorder_increments_version`
- `test_cross_parent_move_creates_new_relationship`
- `test_multiple_same_parent_reorders_accumulate_version`

Closes #795

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review: PR #796 - Sync-ready Relationship Timestamps

Summary

This PR implements a critical optimization for cloud sync and conflict resolution by differentiating between same-parent reorders (UPDATE pattern) and cross-parent moves (DELETE + CREATE pattern). The implementation is clean, well-documented, and includes comprehensive test coverage.

Recommendation: APPROVE


Requirements Validation

Acceptance Criteria Status
move_node detects if parent is changing vs. just reordering ✅ Implemented
Same-parent reorder uses UPDATE (preserves created_at, increments version) ✅ Implemented
Cross-parent move uses DELETE + CREATE (current behavior) ✅ Preserved
modified_at updated on both operations ✅ Verified
Tests verify timestamp preservation on same-parent reorder ✅ 2 tests
Tests verify version increments on reorder (for OCC) ✅ 2 tests

All 6 acceptance criteria from Issue #795 are satisfied.


Analysis by Review Category

1. Architectural Design & Integrity

Verdict: Excellent

The implementation correctly distinguishes the semantic difference between operations:

  • Same-parent reorder: A relationship attribute change (order), not a relationship change
  • Cross-parent move: A new relationship to a different parent

The solution is elegant - minimal code change (~50 lines of logic) with clear separation:

let is_same_parent_reorder = match (&new_parent_id, &current_parent_id) {
    (Some(new_pid), Some(cur_pid)) => new_pid == cur_pid,
    (None, None) => true,  // Both root - same "parent"
    _ => false,            // Different parents
};

This pattern correctly handles all three cases: child-to-child reorder, root-to-root reorder, and any cross-parent move.

2. Functionality & Correctness

Verdict: Correct

The UPDATE query correctly:

  • Preserves created_at (not modified)
  • Updates modified_at to current time
  • Increments version for OCC
UPDATE relationship
SET properties.order = $order,
    modified_at = time::now(),
    version = version + 1
WHERE in = $parent_id AND out = $node_id AND relationship_type = 'has_child';

Edge case consideration: The root-level case (None, None) correctly returns true for is_same_parent_reorder, but since new_parent_id.is_some() is false in this case, it falls through to the "Make root node" branch which just deletes any existing parent relationship. This is correct behavior - root nodes don't have has_child relationships pointing to them, so there's nothing to UPDATE. No bug here.

3. Security

Verdict: No concerns

No security-sensitive changes. The implementation uses parameterized queries (preventing injection) and doesn't introduce any new attack surfaces.

4. Maintainability & Readability

Verdict: Good

5. Testing Strategy & Robustness

Verdict: Comprehensive

Four well-designed tests covering all critical scenarios:

Test Validates
test_same_parent_reorder_preserves_created_at Core requirement - timestamp preservation
test_same_parent_reorder_increments_version OCC version increment
test_cross_parent_move_creates_new_relationship Regression test for cross-parent behavior
test_multiple_same_parent_reorders_accumulate_version Version accumulates correctly over time

The tests use proper timing delays (tokio::time::sleep(10ms)) to ensure timestamp differences are detectable.

6. Performance & Scalability

Verdict: Improved

The implementation actually improves performance for the common case:

  • Before: DELETE + INSERT (2 operations) for all moves
  • After: Single UPDATE for same-parent reorders (1 operation)

This reduces write amplification and transaction overhead for reordering operations.


Minor Observations

Nit: Uncommitted formatting changes

There are minor formatting changes (line wrapping) in the working directory that aren't committed:

-        store
-            .move_node(&child2.id, Some(&parent.id), None)
-            .await?;
+        store.move_node(&child2.id, Some(&parent.id), None).await?;

These should either be committed or reverted for consistency. Recommend running cargo fmt and committing if desired.


Conclusion

This is a well-implemented feature that correctly addresses the sync-readiness requirements. The code is clean, the tests are comprehensive, and the change improves both correctness and performance. The semantic distinction between reorder and move operations will be valuable for conflict resolution in the cloud sync layer.

Final Verdict: APPROVE


Review by Principal Engineer AI Reviewer

@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.

Principal Engineer Review Complete - Recommendation: APPROVE. See detailed review comment above.

Address reviewer nit about uncommitted formatting changes.
Standardize formatting per rustfmt rules.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator Author

Review Feedback Addressed

Changes Made

✅ Applied cargo fmt formatting - Addressed the nit about uncommitted formatting changes

Summary

Category Count
🔴 Critical addressed 0 (none found)
🟡 Important addressed 0 (none found)
🟢 Suggestions addressed 1
⏭️ Skipped 0

Commits Added

  • 2c3789bc - style: Apply cargo fmt formatting

All quality checks passed. PR ready for merge.

🤖 Generated with Claude Code

@malibio
malibio merged commit 826e310 into main Jan 7, 2026
@malibio
malibio deleted the feature/issue-795-sync-ready-relationship-timestamps branch January 7, 2026 12:28
malibio added a commit that referenced this pull request Feb 4, 2026
* feat: Preserve created_at on same-parent reorders (Issue #795)

## Summary
Differentiate between same-parent reorder and cross-parent move operations
in the `move_node` function to support cloud sync and conflict resolution.

## Changes
- **Same-parent reorder**: Now uses UPDATE to preserve `created_at`,
  update `modified_at`, and increment `version` for OCC
- **Cross-parent move**: Continues to use DELETE + CREATE (new relationship
  gets new `created_at` and `version` reset to 1)
- Added detection logic to compare current parent with target parent

## Benefits
- **Sync-ready**: Preserved timestamps enable accurate conflict resolution
- **OCC support**: Version increment enables optimistic concurrency control
- **Distinguishable operations**: Sync systems can differentiate reorders
  from cross-parent moves

## Tests Added
- `test_same_parent_reorder_preserves_created_at`
- `test_same_parent_reorder_increments_version`
- `test_cross_parent_move_creates_new_relationship`
- `test_multiple_same_parent_reorders_accumulate_version`

Closes #795

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* style: Apply cargo fmt formatting

Address reviewer nit about uncommitted formatting changes.
Standardize formatting per rustfmt rules.

🤖 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
* feat: Preserve created_at on same-parent reorders (Issue #795)

## Summary
Differentiate between same-parent reorder and cross-parent move operations
in the `move_node` function to support cloud sync and conflict resolution.

## Changes
- **Same-parent reorder**: Now uses UPDATE to preserve `created_at`,
  update `modified_at`, and increment `version` for OCC
- **Cross-parent move**: Continues to use DELETE + CREATE (new relationship
  gets new `created_at` and `version` reset to 1)
- Added detection logic to compare current parent with target parent

## Benefits
- **Sync-ready**: Preserved timestamps enable accurate conflict resolution
- **OCC support**: Version increment enables optimistic concurrency control
- **Distinguishable operations**: Sync systems can differentiate reorders
  from cross-parent moves

## Tests Added
- `test_same_parent_reorder_preserves_created_at`
- `test_same_parent_reorder_increments_version`
- `test_cross_parent_move_creates_new_relationship`
- `test_multiple_same_parent_reorders_accumulate_version`

Closes #795

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* style: Apply cargo fmt formatting

Address reviewer nit about uncommitted formatting changes.
Standardize formatting per rustfmt rules.

🤖 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
* feat: Preserve created_at on same-parent reorders (Issue #795)

## Summary
Differentiate between same-parent reorder and cross-parent move operations
in the `move_node` function to support cloud sync and conflict resolution.

## Changes
- **Same-parent reorder**: Now uses UPDATE to preserve `created_at`,
  update `modified_at`, and increment `version` for OCC
- **Cross-parent move**: Continues to use DELETE + CREATE (new relationship
  gets new `created_at` and `version` reset to 1)
- Added detection logic to compare current parent with target parent

## Benefits
- **Sync-ready**: Preserved timestamps enable accurate conflict resolution
- **OCC support**: Version increment enables optimistic concurrency control
- **Distinguishable operations**: Sync systems can differentiate reorders
  from cross-parent moves

## Tests Added
- `test_same_parent_reorder_preserves_created_at`
- `test_same_parent_reorder_increments_version`
- `test_cross_parent_move_creates_new_relationship`
- `test_multiple_same_parent_reorders_accumulate_version`

Closes #795

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* style: Apply cargo fmt formatting

Address reviewer nit about uncommitted formatting changes.
Standardize formatting per rustfmt rules.

🤖 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.

Sync-ready relationship timestamps: preserve created_at on same-parent reorder

1 participant