You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Other sibling-order write paths bypass reorder_lock (can still race); move_children_to_parent order collision #1746
The concurrent-reorder race fix (#1561) added SqliteStore::reorder_lock, which serializes move_node against move_node. Adversarial review surfaced that other sibling-order read-then-write paths do not take that lock, so a concurrent move_node + one of them (or one of them against itself) can still collide/corrupt has_child order under the same parent. These are pre-existing and outside #1561's stated two-reorders scenario, tracked here.
Paths that bypass reorder_lock
create_child_node_atomic append — reads max order (sqlite_store/nodes.rs:79-82), computes, inserts in a separate transaction.
has_child append via get_next_order_for_relationship (sqlite_store/relationships.rs:~211, 252-256).
move_children_to_parent (sqlite_store/nodes.rs:~1344) — also a single-threaded bug: assigns fresh 1.0, 2.0, 3.0 without reading existing children under the new parent, so it can collide with siblings already there even without concurrency.
Options
Extend reorder_lock to guard every sibling-order read→compute→write (uniform serialization of all order mutations). Must check each path for re-entrancy (nothing that holds the lock may call another lock-taking path).
Separately fix move_children_to_parent to read existing children and append after them (correctness bug, not just concurrency).
Context
Surfaced during review of #1561. Not a regression from that PR — the lock simply doesn't (and didn't claim to) cover these paths.
move_children_to_parent order collision (correctness). It assigned the moved children fresh 1.0, 2.0, 3.0… without reading the new parent's existing children, so moving into a non-empty parent collided their has_child order keys even single-threaded. It now reads the current max order under new_parent_id and appends the moved children after it (empty parent → unchanged).
create_child_node_atomic + move_children_to_parent under reorder_lock. Both now hold Concurrent sibling reorders can race on the fractional-order read-then-write window #1561's mutex across their sibling-order read → compute → write, so they can't interleave with a concurrent reorder on the shared connection. Re-entrancy verified clean (only these two plus move_node acquire the lock; none calls another; no caller holds it).
Verification
New deterministic test move_children_into_non_empty_parent_appends_without_collision (the old code produced 1.0, 1.0, 2.0, 2.0); existing move + concurrent_reorders_keep_all_children_with_distinct_order tests still pass. 968 core lib tests green, clippy clean, full pre-push gate green. Independent adversarial review: no deadlock / race / correctness bug / regression.
The ops-layer "add existing node as child" (get_next_child_order read → create_generic_relationship write, two separate store calls) and bulk_create_has_child (inserts pre-computed orders) still write has_child orders without the lock. reorder_lock is private to SqliteStore, so serializing those cross-boundary read→writes needs an atomic store method — tracked in #1750.
Activity
Fix move_children_to_parent order collision and serialize order writes (
mstomar125 commentedon Jul 27, 2026
Resolved in #1751 (merged to
mainas647a46c7).What shipped
move_children_to_parentorder collision (correctness). It assigned the moved children fresh1.0, 2.0, 3.0…without reading the new parent's existing children, so moving into a non-empty parent collided theirhas_childorder keys even single-threaded. It now reads the current max order undernew_parent_idand appends the moved children after it (empty parent → unchanged).create_child_node_atomic+move_children_to_parentunderreorder_lock. Both now hold Concurrent sibling reorders can race on the fractional-order read-then-write window #1561's mutex across their sibling-order read → compute → write, so they can't interleave with a concurrent reorder on the shared connection. Re-entrancy verified clean (only these two plusmove_nodeacquire the lock; none calls another; no caller holds it).Verification
New deterministic test
move_children_into_non_empty_parent_appends_without_collision(the old code produced1.0, 1.0, 2.0, 2.0); existing move +concurrent_reorders_keep_all_children_with_distinct_ordertests still pass. 968 core lib tests green, clippy clean, full pre-push gate green. Independent adversarial review: no deadlock / race / correctness bug / regression.Follow-up (filed #1750)
The ops-layer "add existing node as child" (
get_next_child_orderread →create_generic_relationshipwrite, two separate store calls) andbulk_create_has_child(inserts pre-computed orders) still writehas_childorders without the lock.reorder_lockis private toSqliteStore, so serializing those cross-boundary read→writes needs an atomic store method — tracked in #1750.