Skip to content

Batch A (P0): data-integrity fixes — transactional move_node (#1429) + window-close/reload store guards (#1435, #1436) - #1453

Merged
mstomar125 merged 2 commits into
NodeSpaceAI:mainfrom
mstomar125:fix/batch-a-data-integrity
Jun 24, 2026
Merged

mstomar125 merged 2 commits into
NodeSpaceAI:mainfrom
mstomar125:fix/batch-a-data-integrity

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

Phase 1 bug-sweep Batch A, core half — three P0 data-integrity fixes. Each mirrors a guard/pattern that already exists on a sibling path, so they're small and low-risk.

#1429 — make cross-parent move_node transactional

move_node ran DELETE old has_child edge + INSERT new edge as two un-enclosed db.execute calls. An INSERT failure after the committed DELETE left the node with no parent edge — a silently-orphaned root. move_children_to_parent / delete_subtree_atomic already wrap their multi-statement work in a transaction.
Fix: wrap delete-old + insert-new in one transaction() + commit(). Make-root / same-parent-reorder are single statements (already atomic).

#1435 — flushPending executing-op guard

flushPending (run by flushAllPending on window close) re-invoked pending.operation() for every entry, including ones already executing — a debounced save mid-RPC fires twice → OCC conflict / duplicate create at the worst moment. Sibling flushAndWaitForNodes guards this with !executingOperations.has(nodeId).
Fix: add the same guard; still await the in-flight promise.

#1436 — batchSetNodes skip-while-editing guard

batchSetNodes (used by doLoadChildrenTree with a database source) lacked setNode's isFocused || hasPending skip, so a concurrent tree reload overwrote a child being edited mid-keystroke (the sync#76 corruption class).
Fix: apply the same skip-while-editing guard + server-confirmed-version stash per node in the database-source loop.

Tests

  • Rust: test_move_node_cross_parent_leaves_exactly_one_edge (asserts exactly one edge, under the new parent). cargo fmt/clippy -D warnings clean.
  • Frontend: new flushPending double-execute test + 4 batchSetNodes guard cases. Full suite 3890/3890 pass.
  • test:free-users: 7/7 pass — community build behaviorally unchanged.

Free/community impact

None behaviorally — #1435/#1436 harden existing local-store guards (additive skips), #1429 makes a store mutation atomic. test:free-users green.

Note: bun run quality:fix surfaces 3 pre-existing eslint errors in two files this PR does not touch (person-schema-form.svelte, reactive-structure-tree.svelte.ts); the files I changed are eslint-clean. Flagging rather than expanding scope.

Closes #1429, closes #1435, closes #1436.

Mayank Tomar and others added 2 commits June 24, 2026 09:35
Moving a node to a different parent ran two separate `db.execute` calls
with no enclosing transaction: DELETE the old `has_child` edge, then
INSERT the new one. If the INSERT failed (constraint / IO / crash /
cancel) after the DELETE committed, the node was left with NO has_child
edge — a silently-orphaned root. Sibling mutations
(`move_children_to_parent`, `delete_subtree_atomic`) already wrap their
multi-statement work in a transaction; this path did not.

Wrap the delete-old + insert-new pair in one `transaction()` + `commit()`
so it is all-or-nothing. The make-root and same-parent-reorder paths are
single statements and already atomic. Add a test asserting a cross-parent
move leaves exactly one has_child edge under the new parent.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…loses #1435, closes #1436)

Two data-loss guards in shared-node-store, mirroring guards that already
exist on sibling paths:

#1435 — flushPending (run by flushAllPending on window close) called
`pending.operation()` for every entry unconditionally, even ones already
executing. Its sibling flushAndWaitForNodes guards exactly this with
`!executingOperations.has(nodeId)`. Without the guard, a debounced save
mid-RPC at window close fires a second time -> OCC conflict or duplicate
create at the most data-loss-sensitive moment. Add the same executing-op
guard; still await the in-flight promise.

#1436 — batchSetNodes (used by doLoadChildrenTree with a database source)
lacked setNode's `isFocused || hasPending` skip, so a concurrent tree
reload for a parent whose child is being edited overwrote the child's
optimistic content mid-keystroke (the sync#76 corruption class). Apply
the same skip-while-editing guard + server-confirmed-version stash per
node in the database-source loop.

Tests: flushPending double-execute guard; four batchSetNodes guard cases.

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

Copy link
Copy Markdown
Contributor Author

APPROVE — Tight, well-scoped P0 batch. All three fixes are grounded in real sibling patterns and each ships a targeted test. Verified against origin/fix/batch-a-data-integrity.

#1429 — transactional cross-parent move (sqlite_store.rs:1561-1583)

  • Correct. DELETE-old-edge + INSERT-new-edge are now wrapped in one transaction() / commit(), matching move_children_to_parent (L918) and delete_subtree_atomic conventions. libsql rolls back on tx drop, so a failed INSERT no longer leaves a parentless (orphaned-root) node — no explicit rollback() needed and none of the other tx sites use one either.
  • The other two branches are genuinely single-statement and already atomic: same-parent-reorder is one UPDATE (L1554), make-root is one DELETE (L1592).
  • Test test_move_node_cross_parent_leaves_exactly_one_edge asserts exactly one edge under the new parent and re-checks via get_parent_id. Covers the zero-edge and double-edge regressions directly.

#1435 — flushPending executing-op guard (shared-node-store.svelte.ts:288-300)

  • Correct, precisely mirrors flushAndWaitForNodes (L356). When the guard skips re-execution, pendingOperations.delete(nodeId) is still done by the in-flight op's own executeOperation finally (L172), and the same pending.promise is awaited regardless — no leak, no missed settle.
  • Test resolves a parked updateNode mock and asserts toHaveBeenCalledTimes(1) across flush — exercises the exact double-execute window.

#1436 — batchSetNodes skip-while-editing guard (shared-node-store.svelte.ts:1730-1759)

  • Faithfully mirrors setNode's guard (L1396-1442): same isFocused || hasPending predicate, same database-source + existingNode + non-ai-chat gating, same isPlausibleOwnEcho-gated serverConfirmedVersions stash to preserve OCC, same persistedNodeIds.add.
  • 4 tests cover focused skip, unfocused-but-pending skip, the no-guard regression, and per-node isolation within one batch.

Community/Pro mandate: all three are additive hardening of shared local-store / db paths with no Pro-gating semantics changed; test:free-users reported 7/7. No concern.

Non-blocking:

  • CI: statusCheckRollup empty — no automated gate on the branch; the 3890/3890 + free-users claims rest on local runs.
  • Description flags 3 pre-existing eslint errors in two untouched files — correctly out of scope.
  • [bug] Cross-parent move_node is non-transactional — a mid-op failure orphans the node #1429's test asserts post-conditions of a successful move; atomicity is structurally guaranteed by the tx, but a fault-injection test would make the rollback path explicit if cheap later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant