Repository navigation
Remove sleep-based eventual-consistency retry loops from NodeService (SQLite is synchronous/ACID) - #1239
Conversation
closes #1237) Under SQLite (synchronous/ACID), a write is visible on the very next read on the same connection — there is no replication lag. The retry/sleep machinery left over from the SurrealDB era added 50ms–2s of latency and masked whether orderings were actually correct. - Site 1 (create_node_with_parent ~L2095): replace 5×50ms sibling-validity retry with a single one-shot check; fallback to End behaviour is identical. - Site 2 (create_parent_edge ~L4604): delete dead "Sibling not found" 10×100ms retry loop — SqliteStore::move_node never emits that error string; the loop always exited on attempt 1. - Site 3 (create_parent_edge ~L4644): delete the 20×50ms position-verification / nested 10×50ms re-verify polling loop entirely; trust the single move_node result. - Tests: remove wait_for_children_tree_order helper and all test-side sleep calls; assert directly after awaited writes. - New tests: test_insert_after_ordering_is_deterministic_without_retries (proves SQLite ordering is correct on first read for a 5-node After/Beginning sequence) and test_stale_sibling_falls_back_to_end (proves stale-sibling fallback works on first attempt). Co-Authored-By: Claude <[email protected]>
Code Review SummaryThis PR cleanly removes three SurrealDB-era eventual-consistency retry/polling loops from `NodeService` and eliminates the corresponding test-side sleep infrastructure. The change is surgical, deletion-heavy, and the reasoning is technically sound throughout. All acceptance criteria from issue #1237 are met. The PR passes `cargo clippy -p nodespace-core -- -D warnings` clean and all 132 unit tests pass with zero failures. One minor observation worth noting: the stale-sibling fallback test only exercises the deleted-sibling path (node returns `None` from `get_node`). The issue also specifies reparented-sibling as a stale scenario (sibling exists but `get_parent` returns a different parent). The existing `test_sibling_with_different_parent_falls_back_to_append` test covers the reparented case, so coverage is complete across both tests combined — not a blocker. FindingsNo Critical IssuesAll three sites were handled correctly: Site 1 (`create_node_with_parent` ~L2095): The 5×50ms retry loop is removed. The single-check logic and End-fallback path are identical to what the loop was doing on a successful attempt. The warning log message was updated from `"position sibling is stale after retries"` to `"position sibling is stale"` — correct. Site 2 (`create_parent_edge` ~L4604): The dead "Sibling not found" 10×100ms retry loop is deleted. The issue's analysis was correct: `SqliteStore::move_node` never emits that error string. The now-single `move_node` call at L4591 maps errors cleanly via `NodeServiceError::query_failed`. All dead bookkeeping (`attempt_count`, `last_error`, `start` timing, elapsed-ms debug logs) is fully removed. Site 3 (`create_parent_edge` ~L4644): The 20×50ms position-verification polling loop plus the nested 10×50ms re-verify loop are fully deleted. The worst-case ~2s of polling is gone. The commit trusts the single atomic `move_node` result, which is the correct model for SQLite. Test infrastructure removal: `wait_for_children_tree_order` helper fully deleted. All `sleep(Duration::from_millis(N))` calls in the test module are removed. `use std::time::Duration` and `use tokio::time::sleep` imports removed from both test submodules. Assertions preserved and passing without any waiting. Verified `grep -c "sleep\b"` returns 1 — one comment reference only, no call sites. New tests: `test_insert_after_ordering_is_deterministic_without_retries` and `test_stale_sibling_falls_back_to_end` are correct and deterministic. The ordering test exercises End/After/Beginning in combination across 5 nodes and asserts exact order `[E, A, C, D, B]` on the first read — this is the Site 3 proof required by the issue. Both tests pass. Suggested ImprovementsNone that would block merge. NitpicksNit: `packages/core/src/services/node_service.rs:8786–8790` — The `adjacency_list_tests` module comment retained from `main` reads: "which can exhibit race conditions under concurrent test execution when an operation queries for sibling positions before a prior write has been committed." The phrase "before a prior write has been committed" was accurate under SurrealDB replication lag; under SQLite the actual concern is test-level concurrency (multiple tests sharing the same DB file with interleaved fractional-order writes). The `#[serial]` annotation is still correct and necessary — the comment just deserves a one-line clarification. Low priority; pre-existing text outside this PR's scope. Nit: `packages/core/src/services/node_service.rs:9142–9143` — The `create_node_with_parent_tests` module comment similarly says `"to prevent race conditions under concurrent test execution"` without elaborating. Fine as-is for this PR; the shorter phrasing is less misleading than the `adjacency_list_tests` version. Requirements Checklist (Issue #1237)
This is a net-positive change. Approving. |
closes #1237) (#1239) Under SQLite (synchronous/ACID), a write is visible on the very next read on the same connection — there is no replication lag. The retry/sleep machinery left over from the SurrealDB era added 50ms–2s of latency and masked whether orderings were actually correct. - Site 1 (create_node_with_parent ~L2095): replace 5×50ms sibling-validity retry with a single one-shot check; fallback to End behaviour is identical. - Site 2 (create_parent_edge ~L4604): delete dead "Sibling not found" 10×100ms retry loop — SqliteStore::move_node never emits that error string; the loop always exited on attempt 1. - Site 3 (create_parent_edge ~L4644): delete the 20×50ms position-verification / nested 10×50ms re-verify polling loop entirely; trust the single move_node result. - Tests: remove wait_for_children_tree_order helper and all test-side sleep calls; assert directly after awaited writes. - New tests: test_insert_after_ordering_is_deterministic_without_retries (proves SQLite ordering is correct on first read for a 5-node After/Beginning sequence) and test_stale_sibling_falls_back_to_end (proves stale-sibling fallback works on first attempt). Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
Closes #1237