Skip to content

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

Closed

Description

@malibio

Problem

Currently, move_node uses DELETE + RELATE (create new) pattern for ALL moves, including same-parent reorders:

DELETE relationship WHERE out = $node_id AND relationship_type = 'has_child';
RELATE $parent_id->relationship->$node_id CONTENT {
    relationship_type: 'has_child',
    properties: { order: $order },
    created_at: time::now(),  -- loses original timestamp
    modified_at: time::now(),
    version: 1  -- resets version
};

This causes issues for cloud sync and conflict resolution:

  1. Lost created_at - Original relationship creation time is lost on every reorder
  2. Reset version - OCC version resets to 1, breaking conflict detection
  3. Indistinguishable operations - Can't tell "reorder within parent" from "move to new parent"

Solution

Differentiate between same-parent reorder and cross-parent move:

Same-parent reorder (UPDATE)

UPDATE relationship 
SET properties.order = $order, 
    modified_at = time::now(), 
    version = version + 1
WHERE in = $parent AND out = $child AND relationship_type = 'has_child';

Cross-parent move (DELETE + CREATE)

-- Current behavior is correct - new relationship = new created_at
DELETE relationship WHERE out = $node_id AND relationship_type = 'has_child';
RELATE $new_parent_id->relationship->$node_id CONTENT { ... };

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)

Context

Labels

enhancement, backend, sync

Activity

  1. malibio commented on Jan 7, 2026

    @malibio
    CollaboratorAuthor

    Test Baseline

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

    Starting work on this issue.

  2. self-assigned this
    on Jan 7, 2026
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