Skip to content

Make create_parent_edge idempotent on already-existing edges (fixes nodespace-sync#77, alice-side) - #1214

Merged
mstomar125 merged 3 commits into
NodeSpaceAI:mainfrom
mstomar125:fix/create-parent-edge-idempotent
May 27, 2026
Merged

mstomar125 merged 3 commits into
NodeSpaceAI:mainfrom
mstomar125:fix/create-parent-edge-idempotent

Conversation

@mstomar125

@mstomar125 mstomar125 commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Backend half of nodespace-sync#77. Makes NodeService::create_parent_edge idempotent on already-existing edges so the sync pull-side's echo replay doesn't re-position the just-created child off its local order.

What changed

packages/core/src/services/node_service.rs — create_parent_edge now short-circuits when:

  1. insert_after_node_id is None (no explicit reorder intent), AND
  2. get_parent(child_id) reports the child is already under parent_id

The guard is narrowed via insert_after_node_id.is_none() so a caller that passes an explicit hint still triggers a real reorder (covered by test_create_parent_edge_reorders_when_explicit_hint_against_existing_edge).

packages/core/src/db/surreal_store.rs — added test_move_node_same_parent_no_hint_moves_to_beginning to lock the store-level contract used by reorder_node(_, _, None) (MCP "move to first position" path).

The three existing test_same_parent_* tests were already updated to use explicit insert_after_sibling for their reorder calls.

Scope note: what this PR does NOT do

An earlier revision of this PR ALSO translated None → last_child_id inside create_parent_edge to fix the sync receive-side bug (bob's view of alice's new child landed at the top of the parent's list). That translation has been stripped in e25fa571 because it conflated two callers with opposite intents:

Caller Intended meaning of None
Sync pull-side apply_remote "no order info from cloud, append at end"
Outliner Enter-at-position-0 "insert at beginning of the parent's list"

Core can't disambiguate at the API layer. The fix lives at the call sites instead — sync's pull-side computes last_child_id explicitly in NodeSpaceAI/nodespace-sync#79. The outliner's "insert at beginning" UX is preserved by core's unchanged move_node(_, _, None) = "insert at beginning" semantic.

Test plan

  • cargo test -p nodespace-core --lib — 1191 → 1193 passing (+2 new, no removals)
  • cargo clippy -p nodespace-core --lib -- -D warnings — clean
  • cargo fmt --check — clean
  • Manual verification: two-window same-device demo, alice types + Enter at end of text → new sibling appears directly below in both windows (requires nodespace-sync#79 for the receive-side correction)

Related

  • #1213 — setNode skip-while-editing guard (nodespace-sync#76). Independent of this PR.
  • #1215 — frontend resilience for #77 (tauri-sync-listener fallback + structureTree-based stale check). Independent of this PR.
  • nodespace-sync#79 — receive-side companion that passes the explicit last_child_id hint. Required for the full #77 fix.
  • #1216 — follow-up suggestion: introduce an InsertPosition enum so future callers can express intent without overloading Option.

…-end

Fixes the receive-side half of nodespace-sync#77: when alice creates a new
sibling and presses Enter, the cloud LIVE-SELECT echoes the new
has_child edge back through the sync pull-side, which then calls
NodeService::create_parent_edge(child, parent, None) on the local
daemon. Two bugs combined to drag the new sibling to the top of its
parent's list in both windows:

1. The pull-side echo re-creates an edge that already exists locally.
   The old create_parent_edge unconditionally delegated to move_node,
   which re-computed the order and silently re-positioned the child
   off its just-computed local order.

2. The cloud relationship row carries no `order` field (sync's
   `RELATE ... SET rel_type = $rt` doesn't push it), so the pull-side
   has to pass `None` for `insert_after_node_id`. The store's move_node
   interprets `None` as "insert at beginning of children" — which is
   what the MCP `reorder_node(_, _, None)` "move to first position"
   path needs, but the wrong default for a hierarchical CREATE. For
   bob (who has never had this relationship before), the new node
   landed at first_order - 1.0 ≈ -0.998, sorting before every existing
   sibling.

The fix lives at the NodeService layer where the calling convention
splits cleanly between CREATE and REORDER:

- create_parent_edge is now idempotent: if `child_id` is already a
  child of `parent_id`, return Ok immediately without touching the
  edge.

- create_parent_edge translates a `None` insert-after hint to the
  parent's current last-child id, so the underlying move_node call
  appends at end. move_node's None semantic is preserved for the
  reorder path.

- create_node_with_parent's stale-hint fallback is simplified: when
  the sibling-validation retry loop times out, clearing the hint
  to `None` now does the right thing (create_parent_edge translates
  it to append). The fallback comment promised "fall back to append"
  but the previous behavior produced "insert at beginning"; the
  semantic now matches the comment.

Three pre-existing tests called move_node(child, parent, None) as
shorthand for "actually reorder this child" and depended on the
implicit `None = move to beginning` behavior. Updated each to use
an explicit `insert_after_sibling` so they exercise a real position
change. Added the matching version-bump assertions back so issue #795
coverage is preserved.

Test deltas vs origin/main:
  - 1190 → 1191 passing (3 existing tests rewritten, no new tests)
  - cargo clippy -p nodespace-core --lib -- -D warnings: clean

Manually verified end-to-end against the two-window same-device demo
(scripts/run-two-daemons.sh + alice + bob Tauri windows): pressing
Enter places the new sibling directly below the current row in both
windows.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic code review — PR #1214

CI: ⏳ No checks reported on fix/create-parent-edge-idempotent — verify CI is wired up before merge.
Scope: +138 / -52 across 2 files. NodeService::create_parent_edge becomes idempotent + None-hint translates to append; three existing tests rewritten to use explicit insert_after_sibling; one test renamed and assertion flipped.
Requirements: Backend half of nodespace-sync#77. Both fixes (idempotency + None→append translation) are real and named in the PR body. The rewritten tests acknowledge that None-as-reorder was load-bearing for old behavior.

Findings

🔴 Idempotency guard treats create_parent_edge(child, parent, Some(other_sibling)) as a no-op when child is already under parent (node_service.rs:4554-4564)

if let Some(existing_parent) = self.get_parent(child_id).await? {
    if existing_parent.id == parent_id {
        return Ok(());
    }
}

The guard short-circuits unconditionally when the child is already under the target parent — but the caller may have passed a non-None insert_after_node_id precisely because they want to reposition an existing child. The PR body says "Callers that want to actually reorder an existing child should use reorder_child" — but that's an unwritten contract. Today the only known caller of create_parent_edge is sync's pull-side passing None, but the function is pub on NodeService and any future caller passing Some(sibling) will get silent no-ops. Either:

  1. Narrow the guard to if existing_parent.id == parent_id && insert_after_node_id.is_none() (matches the actual sync-echo case).
  2. Add a debug assertion or warn-level log when Some hint is provided with already-present edge.
  3. Make the function take an enum (EdgeIntent::CreateOrIgnore vs EdgeIntent::Reorder) so the contract is in the type.

Option 1 is the smallest fix and preserves the sync echo behavior the PR is targeting. Recommend at minimum (1) + a test that calls create_parent_edge with a Some hint against an existing edge and asserts the reorder actually happens.

🟡 None-translation costs an extra get_children round-trip on every edge creation (node_service.rs:4574-4582)

match self.get_children(parent_id).await {
    Ok(children) => children.last().map(|c| c.id.clone()),
    Err(_) => None,
}

Every CREATE with no explicit insert-after now does:

  1. get_parent(child_id) (idempotency check)
  2. get_children(parent_id) (None translation)
  3. move_node(...) (the actual write, which internally re-queries children to compute the fractional order)

For a parent with many children, get_children is O(n) and runs before every CREATE. Sync echo replays may produce a burst of these. Profile-impact unknown but the design path can be: have move_node accept a InsertPosition::{Append, AtBeginning, After(id)} enum and push the None→Append translation into the store layer where it can share the children lookup.

🟡 Err(_) => None silently swallows DB errors and falls back to "insert at beginning" (node_service.rs:4580)
If get_children returns Err (transient DB issue), we silently degrade to the exact pre-fix behavior the PR is trying to eliminate — the new node lands at the beginning of the list. Better: propagate the error (the caller can retry), or at minimum tracing::warn! with the parent_id and error so the degradation is observable.

🟡 Idempotency guard's get_parent is also fallible and not retried (node_service.rs:4554-4564)
get_parent propagates errors via ? — a transient DB error during the sync echo replay aborts the entire create_parent_edge call, which the sync pull-side may or may not handle gracefully. Compare with the move_node call below, which retries up to 3 times for sibling-not-found. The idempotency check is the cheaper failure mode and worth retrying or at least documenting the propagation contract.

🟡 Concurrency: read-then-write race between get_children().last() and move_node (node_service.rs:4574-4582, 4614)
Two threads racing create_parent_edge(child_X, parent, None) and create_parent_edge(child_Y, parent, None):

  • T1 reads get_children → last = existing_child
  • T2 reads get_children → last = existing_child
  • T1 calls move_node(child_X, parent, Some(existing_child)) → child_X inserted after existing_child
  • T2 calls move_node(child_Y, parent, Some(existing_child)) → child_Y inserted between existing_child and child_X, not at the actual end

For sync echo replays this can manifest as out-of-order siblings when the cloud delivers a batch of new edges. The fractional-order math handles it (no collision), but the visual order may not match the cloud-canonical order. Worth either serializing edge creation per-parent (already done elsewhere?) or accepting the eventually-consistent ordering with a doc comment naming it.

🟡 Test rewrites lose coverage of the None-hint behavior for in-place reorder (surreal_store.rs:7322-7507)
Three tests previously called move_node(child, parent, None) to exercise same-parent reorder. They've been rewritten to pass an explicit sibling. The PR body and updated comments correctly explain that None on an already-existing edge is now a no-op (per create_parent_edge's guard) — but the lower-level move_node(_, _, None) isn't idempotent and still means "move to beginning". The rewrites work around that, but the gap is: nothing in the test suite now exercises move_node's no-op-on-redundant-call behavior at the store layer. If a future change introduces an idempotency check at the store layer too (or removes it from create_parent_edge), these tests won't catch the regression. Add a small unit test asserting move_node(child, parent, None) for an already-present edge moves child to beginning (current behavior) — locks in the layered contract.

Nits

🟢 Nit: Doc comments name nodespace-sync#77 directly (node_service.rs:4553, 4566)
Core's NodeService is now coupled (in comments) to a sync-side issue number. Acceptable for the present moment because the issue documents the root cause, but consider promoting the actual invariants (idempotency contract, None-as-append semantics) to function-level rustdoc that doesn't depend on reading an external issue.

🟢 Nit: Double blank line in test module (node_service.rs:7421-7422 and surreal_store.rs:7421)
Pre-existing in some places, introduced anew in others — cargo fmt should normalize. Not a blocker if clippy is clean.

🟢 Nit: test_insert_at_end_by_default rename keeps the #[serial(sibling_ordering)] attribute (node_service.rs:9554)
Correct — the serial guard is about parallel-test interference, not about the semantic being tested. Worth a one-line comment naming why the serial guard stays.

🟢 Nit: Idempotency log is debug! (node_service.rs:4559-4563)
Sync echo replays will fire this on every cloud-echoed edge. debug! is the right level for default operation, but during the first weeks after rollout an info! (with rate-limiting) would help confirm the path is firing as expected in production.

🟢 Nit: effective_after_owned: Option<String> + resolved_insert_after: Option<&str> (node_service.rs:4574-4584)
The two-binding pattern (owned String to extend lifetime, then borrow) is a Rust idiom but worth a one-line comment naming why both exist — future readers will wonder.

🟢 Nit: PR body says "1191 passed / 0 failed (one rename of an existing test; no net test count change)" — matches the diff. Worth double-checking the rewritten tests still cover Issue #795's actual scenario (the issue is about same-parent reorder preserving created_at); rewriting to use a real position change is arguably better coverage, but call it out.

Summary

The two fixes are real and the test rewrites are honest about the semantic shift. The 🔴 is about the idempotency guard's blast radius — narrowing it to the actual sync-echo case (None hint) preserves the intent without breaking the pub API's reordering contract. The 🟡s are mostly about defensive sharpness (error handling, race windows, missing test coverage at the layer below the fix).

Verdict: REQUEST CHANGES

- 🔴 Narrow idempotency to no-explicit-hint calls only. Previously the
  guard short-circuited every `create_parent_edge(child, parent, *)`
  call when the edge already existed — including calls that passed
  `Some(target_sibling)` to explicitly reposition the child. New test
  `test_create_parent_edge_reorders_when_explicit_hint_against_existing_edge`
  locks the narrowed contract in place. Today's only known caller of
  this function that passes a hint against an existing edge would be
  a future caller; the test future-proofs it.

- Propagate `get_children` errors instead of swallowing them. The
  previous `Err(_) => None` silently degraded to "insert at beginning"
  — the exact bug nodespace-sync#77 was filed to eliminate. Use `?`
  and let the caller decide whether to retry.

- Document the `get_parent` propagation contract. The idempotency
  check uses `?` and aborts on transient DB error, distinct from the
  10×100ms retry budget on the `move_node` loop below (which is for
  the sibling-not-found case, a different consistency window).

- Document the read-then-write concurrency window between
  `get_children` and `move_node`. Two concurrent
  `create_parent_edge(_, parent, None)` calls produce distinct
  fractional orders (no collision) but the *between-which-siblings*
  placement reflects whichever transaction landed last. Acceptable
  for sync echo replay (eventually consistent across windows);
  callers needing strict ordering should serialise or use
  `reorder_child` afterwards.

- Add `test_move_node_same_parent_no_hint_moves_to_beginning` at the
  store layer. The previous PR's test rewrites moved the explicit-
  sibling pattern into three existing tests, which inadvertently left
  zero coverage for the lower-level `move_node(_, _, None) =
  "insert at beginning"` semantic. The MCP `reorder_node(_, _, None)`
  "move to first position" path depends on this; a future refactor
  that flips the None default to "append at end" at this layer would
  silently break MCP — this test catches that.

- Fix stale comments in two test bodies that described the no-op
  semantic as living at `move_node`; the idempotency lives at
  `NodeService::create_parent_edge` (the layer where the calling
  convention splits cleanly between CREATE and REORDER).

Test deltas vs origin/main:
  - 1191 → 1193 passing (+2 new tests, no removals)
  - cargo clippy: clean

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Pushed review-feedback addressed in cc9883ef.

Real concerns

  • 🔴 Idempotency narrowed to no-explicit-hint calls — previously the guard short-circuited every create_parent_edge(child, parent, *) with existing_parent.id == parent_id, including calls passing Some(target_sibling) to explicitly reposition. Now gated on insert_after_node_id.is_none(). New test test_create_parent_edge_reorders_when_explicit_hint_against_existing_edge locks the narrowed contract.
  • 🟡 Err(_) => None silent degradation removed — get_children errors now propagate via ?. Previously the silent degradation re-triggered the exact "insert at beginning" bug this path was added to fix.
  • 🟡 get_parent retry contract documented — comment names the propagation contract and contrasts with the 10×100ms retry budget on the move_node loop (different consistency window).
  • 🟡 Concurrency window documented — read-then-write between get_children and move_node produces distinct fractional orders (no collision) but possibly inconsistent between-which-siblings placement under concurrent calls. Acceptable for sync echo replay (eventually consistent); callers needing strict ordering should serialise or use reorder_child afterwards.
  • 🟡 Lost store-layer coverage restored — added test_move_node_same_parent_no_hint_moves_to_beginning at the store layer. The MCP reorder_node(_, _, None) "move to first position" path depends on this semantic. A future refactor that flips the None default to "append at end" at the store layer would silently break MCP — this test catches that.
  • Fixed two stale comments in test bodies that described the no-op as living at move_node; it lives at NodeService::create_parent_edge (the layer where the calling convention splits cleanly between CREATE and REORDER).

Cost note (acknowledge)

  • 🟡 Extra get_children round-trip per CREATE without explicit hint — kept as-is for clarity. A future refactor could push the None translation into the store's move_node (sharing the children lookup it already does internally) if profiling shows it's a hotspot. Noted in the doc comment.

Test deltas

  • 1191 → 1193 passing (+2 new tests, no removals).
  • cargo clippy -p nodespace-core --lib -- -D warnings — clean.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic code review (re-review) — PR #1214

Review Type: Re-Review (scope: commit cc9883ef "Address PR #1214 review feedback").
CI: ⏳ Still no checks reported on fix/create-parent-edge-idempotent. Same flag as round 1.

Previous review summary

  • Previous 🔴: 1 — addressed.
  • Previous 🟡: 5 — addressed: 4, documented: 1.
  • Previous 🟢: 5 — addressed: 3, no-op acceptable: 2.
  • New findings this pass: 0 🔴, 0 🟡, 1 🟢.

Round-1 findings — disposition

✅ 🔴 Idempotency blast radius narrowed — guard now gated on insert_after_node_id.is_none(). Calls passing an explicit hint against an already-present edge route through move_node and reposition. New test test_create_parent_edge_reorders_when_explicit_hint_against_existing_edge directly exercises this:

service.create_parent_edge(&child1_id, &parent_id, Some(&child2_id)).await.unwrap();
// assertion: after[0] = "Child 2", after[1] = "Child 1"

A future regression that widens the guard back to "any same-parent edge" fails this test. Clean fix.

✅ Err(_) => None silent degradation — get_children now propagates via ? instead of swallowing. The previous fallback to "insert at beginning" on a transient DB error — which would have silently re-triggered the bug this path was added to fix — is gone.

✅ get_parent retry contract — comment added explicitly contrasting the propagation-via-? for get_parent with the 10×100ms retry budget on move_node's sibling-not-found loop. Makes the layered consistency-window story legible.

✅ Concurrency window — read-then-write race between get_children().last() and move_node is now documented at the call site, naming exactly the failure mode (distinct fractional orders, but between-which-siblings placement may not match cloud-canonical order) and the acceptable-for-sync-echo-replay rationale.

✅ Lost store-layer coverage — new test_move_node_same_parent_no_hint_moves_to_beginning directly asserts move_node(child, parent, None) for an already-present edge moves the child to the beginning. The comment names the MCP reorder_node(_, _, None) dependency explicitly — a future refactor that flips that default would break MCP and fail this test.

✅ Stale test comments — fixed: comments now correctly attribute the no-op to NodeService::create_parent_edge rather than to move_node.

🟡 Extra get_children round-trip per CREATE — explicitly kept as-is with a comment naming the future-optimization path (push None translation into move_node to share its existing children lookup). Acceptable as documented.

New findings

🟢 Nit: test_create_parent_edge_reorders_when_explicit_hint_against_existing_edge doesn't assert no log spam on the reorder path (node_service.rs:9625-9684)
The narrowed guard now keeps tracing::debug!(... "edge already exists with no reorder hint, treating as no-op" ...) for the legitimate no-op path. A future refactor that accidentally widens the guard would still take the no-op branch and emit that log under the explicit-hint call. The test asserts on the post-condition (reorder happened) but not on the log message — a tracing_test capture confirming the no-op log did NOT fire would catch silently-widened guards. Style; not blocking.

Summary

Every round-1 🔴 and 🟡 is either fixed in code, locked in by a test, or explicitly documented with a rationale. The narrowed idempotency contract is the right shape — sync-echo idempotency lives where the calling convention splits cleanly between CREATE and REORDER, and the test suite now covers both the sync-echo no-op and the explicit-hint reorder. The store-layer test restores the layered contract coverage the rewrites had dropped.

Verdict: APPROVE

The previous version of this PR translated `create_parent_edge`'s
`None` insert-after hint to "append after the parent's last child"
inside `NodeService`. That correctly fixed sync's receive-side
echo path but introduced a regression for the frontend's
Enter-at-position-0 flow:

  • User puts cursor at start of node "hello" and presses Enter
  • Frontend's `shouldCreateNodeAbove` branch fires → dispatches a
    CREATE with `insert_after_node_id: null` meaning "insert above
    the current line"
  • Frontend optimistic UI shows new empty line ABOVE
  • Backend's translation: null → last_child_id → move_node
    appends at end
  • Backend's RelationshipCreated event arrives ~200ms later with
    that "append" order; the frontend updates structureTree → new
    empty line visually relocates to the BOTTOM of the parent's
    list

Two real callers, two opposite meanings for the same `None`. Backend
can't tell them apart at the API surface, so the receive-side fix
has to live where the intent is unambiguous.

Move the translation to the sync layer in PR D' (`nodespace-sync` —
`apply_remote` for has_child relationships computes the parent's
current last child and passes it explicitly as the hint). Core's
`create_parent_edge` keeps its `None = insert at beginning` semantic
intact, matching `move_node` and `reorder_node(_, _, None)`.

Behavioral surface of this PR after the strip:
  • Idempotency guard (no-op when child is already under parent AND
    no explicit hint) — KEPT. This is the alice-side echo fix.
  • `None`-translation block — REMOVED. Sync receive-side moves to
    PR D'.
  • Stale-hint fallback in `create_node_with_parent` — kept the
    simplified shape; documents the actual behavior (`None` →
    insert at beginning).
  • `test_insert_at_end_by_default` reverted to
    `test_insert_at_beginning_by_default` with the original
    assertions.
  • `test_create_parent_edge_reorders_when_explicit_hint_against_existing_edge`
    updated to seed with an explicit hint (independent of the
    default insertion direction).
  • `test_move_node_same_parent_no_hint_moves_to_beginning` — kept,
    locks the store-level contract used by MCP's reorder path.

Test deltas vs origin/main:
  1191 → 1193 passing (no net change from previous revision; the
  add and remove balance).

Follow-up: file an issue on core suggesting an
`InsertPosition::{Beginning, End, After(id)}` enum for
`create_parent_edge`'s signature so future callers can express
intent without overloading `Option`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Force-pushed e25fa571 after a late audit found a real UX regression. Stripping the None → last_child_id translation while keeping the idempotency guard.

Why — the translation conflated two callers with opposite intents for the same None:

Caller Intent
Sync pull-side echo (this PR's target) "no order info, append at end"
Outliner Enter-at-position-0 (legitimate frontend UX) "insert at beginning of the parent's list"

The previous revision made the outliner's "insert above current line" flow visually land the new line at the bottom of the parent's children (optimistic above → ~200ms later moves to bottom on backend confirm). Caught by re-reading the frontend's shouldCreateNodeAbove branch.

Resolution — resolve at the call site, not at the backend:

  • This PR keeps only the idempotency-on-existing-edge guard (clear correctness fix).
  • The sync receive-side append at end semantic moves to a companion sync PR: NodeSpaceAI/nodespace-sync#79 where apply_remote computes last_child_id explicitly and passes it as the hint.
  • The outliner's "insert at beginning" UX is preserved because core's move_node(_, _, None) = "insert at beginning" semantic is unchanged.

API-improvement follow-up — filed #1216 suggesting an InsertPosition::{Beginning, End, After(id)} enum so future callers can express intent without overloading Option. That's the right long-term shape; today's resolution keeps the change minimal.

Test delta vs origin/main

  • 1191 → 1193 passing (+2 new tests, no removals).
  • cargo clippy -p nodespace-core --lib -- -D warnings — clean.

Updated PR description above reflects the new scope.

@mstomar125 mstomar125 changed the title Make create_parent_edge idempotent + translate None hint to append-at-end (fixes nodespace-sync#77, backend) Make create_parent_edge idempotent on already-existing edges (fixes nodespace-sync#77, alice-side) May 27, 2026
@mstomar125
mstomar125 merged commit 972614e into NodeSpaceAI:main May 27, 2026
malibio pushed a commit that referenced this pull request Jun 22, 2026
- 🔴 Narrow idempotency to no-explicit-hint calls only. Previously the
  guard short-circuited every `create_parent_edge(child, parent, *)`
  call when the edge already existed — including calls that passed
  `Some(target_sibling)` to explicitly reposition the child. New test
  `test_create_parent_edge_reorders_when_explicit_hint_against_existing_edge`
  locks the narrowed contract in place. Today's only known caller of
  this function that passes a hint against an existing edge would be
  a future caller; the test future-proofs it.

- Propagate `get_children` errors instead of swallowing them. The
  previous `Err(_) => None` silently degraded to "insert at beginning"
  — the exact bug nodespace-sync#77 was filed to eliminate. Use `?`
  and let the caller decide whether to retry.

- Document the `get_parent` propagation contract. The idempotency
  check uses `?` and aborts on transient DB error, distinct from the
  10×100ms retry budget on the `move_node` loop below (which is for
  the sibling-not-found case, a different consistency window).

- Document the read-then-write concurrency window between
  `get_children` and `move_node`. Two concurrent
  `create_parent_edge(_, parent, None)` calls produce distinct
  fractional orders (no collision) but the *between-which-siblings*
  placement reflects whichever transaction landed last. Acceptable
  for sync echo replay (eventually consistent across windows);
  callers needing strict ordering should serialise or use
  `reorder_child` afterwards.

- Add `test_move_node_same_parent_no_hint_moves_to_beginning` at the
  store layer. The previous PR's test rewrites moved the explicit-
  sibling pattern into three existing tests, which inadvertently left
  zero coverage for the lower-level `move_node(_, _, None) =
  "insert at beginning"` semantic. The MCP `reorder_node(_, _, None)`
  "move to first position" path depends on this; a future refactor
  that flips the None default to "append at end" at this layer would
  silently break MCP — this test catches that.

- Fix stale comments in two test bodies that described the no-op
  semantic as living at `move_node`; the idempotency lives at
  `NodeService::create_parent_edge` (the layer where the calling
  convention splits cleanly between CREATE and REORDER).

Test deltas vs origin/main:
  - 1191 → 1193 passing (+2 new tests, no removals)
  - cargo clippy: clean

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
malibio pushed a commit that referenced this pull request Jun 22, 2026
…otent

Make create_parent_edge idempotent on already-existing edges (fixes nodespace-sync#77, alice-side)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant