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
Serialize the ops-layer has_child order write (add-existing-child + bulk import) under reorder_lock #1750
#1746 brought the self-contained store order-writers under reorder_lock (move_node, create_child_node_atomic, move_children_to_parent). Two has_child order-write paths still bypass it because they span the store/ops boundary, so a concurrent write under the same parent can read a stale max order and collide/duplicate an order key with a locked create/move:
Add existing node as a child — NodeService reads get_next_child_order (services/node_service/relationship.rs:651) then writes create_generic_relationship (db/sqlite_store/relationships.rs:825) as two separate store calls. Nothing holds reorder_lock across the read→write.
bulk_create_has_child (db/sqlite_store/relationships.rs:571) inserts pre-computed orders — the max-order read that produced them happens upstream, unlocked.
reorder_lock is a private field of SqliteStore, so the ops layer can't hold it across two store calls. Closing this needs a layered change, not a one-line lock — out of scope for #1746's contained fixes.
Fix direction
Add an atomic store method (e.g. add_existing_child / link_child_next_order) that computes the next has_child order and inserts the edge under reorder_lock, and route the ops-layer "add existing child" path and the bulk-import order computation through it.
Re-entrancy check required (per #1561/#1746): the new method must not call move_node / create_child_node_atomic / move_children_to_parent while holding the lock. create_generic_relationship does not take reorder_lock, so performing its insert under the lock is safe.
Context
Surfaced by the adversarial review of #1746. This is the remaining sibling-order write race after #1746; the fractional-order family also includes #1561.
Picking this up (mstomar125) — bringing the ops-layer has_child order write (add-existing-child and bulk import) under the same reorder_lock discipline that already covers the store-internal writers, so the read of get_next_child_order and the write can't interleave with a concurrent reorder. Confirmed #1751 covered only the store-internal methods (move_node/create_child_node_atomic/move_children_to_parent); the ops-layer add-existing-child path still reads-then-writes outside the lock.
Resolved in #1771 (merged). The ops-layer add-existing-child order write is now atomic under reorder_lock via a new append_child_edge store method (read max order → compute next key → insert as one unit), matching the discipline #1751 brought to the store-internal writers. A mutation-checked concurrency test (16 concurrent appends racing a reorder) confirms no colliding order keys; the bulk-import paths use precomputed orders and were unaffected. Build + audit gates green.
Activity
Fix move_children_to_parent order collision and serialize order writes (
mstomar125 commentedon Jul 28, 2026
Picking this up (mstomar125) — bringing the ops-layer has_child order write (add-existing-child and bulk import) under the same reorder_lock discipline that already covers the store-internal writers, so the read of get_next_child_order and the write can't interleave with a concurrent reorder. Confirmed #1751 covered only the store-internal methods (move_node/create_child_node_atomic/move_children_to_parent); the ops-layer add-existing-child path still reads-then-writes outside the lock.
mstomar125 commentedon Jul 28, 2026
Resolved in #1771 (merged). The ops-layer add-existing-child order write is now atomic under reorder_lock via a new
append_child_edgestore method (read max order → compute next key → insert as one unit), matching the discipline #1751 brought to the store-internal writers. A mutation-checked concurrency test (16 concurrent appends racing a reorder) confirms no colliding order keys; the bulk-import paths use precomputed orders and were unaffected. Build + audit gates green.