Repository navigation
B7: Remove SurrealDB-era fractional-ordering jitter — make ordering deterministic under SQLite - #1256
Conversation
…eterministic (closes #1253) Under SQLite's serialized writes, two inserts cannot interleave mid-computation, so jitter was dead weight. All calculate_order call sites and the generate_jitter usage in add_to_collection are removed. Doctest examples now assert exact values; approx_eq helper and the uniqueness-via-jitter test are replaced with a deterministic + strictly-increasing-orders test. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Code Review SummaryThis change correctly removes the SurrealDB-era jitter from fractional ordering. The core logic is sound: Findings[Improvement]
|
malibio
left a comment
There was a problem hiding this comment.
Review posted as a comment above. Key findings: (1) add_to_collection has a genuine read-then-write TOCTOU window not wrapped in a transaction — this was specifically called out as needing analysis in the acceptance criteria; (2) PR description omits the required per-call-site concurrency analysis from AC #1. Both are straightforward to address. Core jitter removal logic is correct.
… window The review identified that add_to_collection had an unprotected read-then-write window: get_next_member_order (SELECT) and the INSERT ran as two independent statements. Under concurrent async callers both could read the same last_order and write duplicate order values for different members. Inlines the order SELECT inside the transaction, matching the pattern used by bulk_add_to_collections and create_child_node_atomic. Concurrency analysis per call site: - create_child_node_atomic: SELECT before tx open, but daemon serializes callers - move_node: siblings queried in Rust then UPDATE inside tx; serialized by daemon - add_to_collection: was unprotected — now wrapped in a single transaction - bulk_add_to_collections: already wrapped in transaction (correct) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Review feedback addressed✅ Addressed: 2 findings 1.
|
…eterministic under SQLite (#1256) * B7: Remove SurrealDB-era ordering jitter — make fractional ordering deterministic (closes #1253) Under SQLite's serialized writes, two inserts cannot interleave mid-computation, so jitter was dead weight. All calculate_order call sites and the generate_jitter usage in add_to_collection are removed. Doctest examples now assert exact values; approx_eq helper and the uniqueness-via-jitter test are replaced with a deterministic + strictly-increasing-orders test. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Address review: wrap add_to_collection in transaction to close TOCTOU window The review identified that add_to_collection had an unprotected read-then-write window: get_next_member_order (SELECT) and the INSERT ran as two independent statements. Under concurrent async callers both could read the same last_order and write duplicate order values for different members. Inlines the order SELECT inside the transaction, matching the pattern used by bulk_add_to_collections and create_child_node_atomic. Concurrency analysis per call site: - create_child_node_atomic: SELECT before tx open, but daemon serializes callers - move_node: siblings queried in Rust then UPDATE inside tx; serialized by daemon - add_to_collection: was unprotected — now wrapped in a single transaction - bulk_add_to_collections: already wrapped in transaction (correct) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Removes SurrealDB-era jitter from fractional ordering. Under SQLite's serialized writes, concurrent inserts cannot interleave mid-computation, so jitter was dead weight everywhere.
Changes
calculate_orderis now pure and deterministic — returns exact midpoint/endpoint valuesgenerate_jitter()deleted entirelyadd_to_collection: wrapped SELECT + INSERT in a transaction (closes the one genuine TOCTOU window found during analysis)approx_eqhelper and jitter-uniqueness test replaced with exact-value + strictly-increasing-orders testsConcurrency analysis per call site
create_child_node_atomic(~line 420)move_node(~lines 1290–1307)add_to_collection(~line 2579)bulk_add_to_collections(~line 2843)Conclusion: jitter was not providing collision protection on any path. The one path with a genuine concurrent-write window (
add_to_collection) is now protected by a transaction, which is the correct fix.Closes #1253