Repository navigation
Add NodeService::is_persisted and non-cascading delete_leaf_node - #3860
Conversation
mstomar125
left a comment
There was a problem hiding this comment.
APPROVE WITH NITS
Independent review (initial). Checked out in a throwaway worktree; ran the 6 new tests and the 10 existing test_delete_node* tests: 16/16 pass.
(a) Additive: confirmed. The diff is +340/-2. The only touched existing lines are the pub use list in db/mod.rs, which gains LeafDeleteOutcome. No existing signature or behaviour changes. LeafDeleteOutcome derives no Serialize/ts-rs, and nothing is added to nodespace-types, the registry, MCP, CLI or gRPC. No generated TypeScript changes. The sync repo pins core at rev 432bd7c and does not reference either new API yet, so nothing there is affected.
(b) Atomicity: sound.
- Every writer goes through the single
writermutex (connections.rs).delete_leaf_atomicholds that guard across the children and version recheck, theDELETEand the commit (nodes.rs~1831-1884). So an in-processcreate_parent_edgeor move onto the leaf cannot interleave. The deferredBEGINis fine because the connection is exclusive, anddelete_subtree_atomicrelies on the same thing. A second delete of the same id returnsNotFound. - Edges:
DELETE FROM noderemoves relationship rows through FK CASCADE on bothin_nodeandout_node. That covers thehas_childedge to the parent, incoming mentions andmember_of. It is the same mechanism asdelete_nodeanddelete_subtree_atomic, so the set is identical. Sibling order is$.orderin edge properties (nodes.rs~615, 747), not pointers, so the neighbours need no repair. - The
COUNTusesin_node = leaf AND has_child. That is the correct direction (in_nodeis the parent).
(c) Parity with delete_node: matches.
- Embedding-root capture, requeue only when
root_id != node_id, andVersionConflictvia??all match. - Order is gate, then schema-deletable check, then OCC, which matches
delete_node. - The FTS and type-ancestry triggers fire on the
DELETE. - One
NodeDeletedevent is emitted after commit and only onDeleted. - Tombstones: core does not do them on this path.
(d) is_persisted. It reads SELECT 1 FROM node WHERE id=? on a reader, with no virtual-date fallback. A virtual date gives false. A stored date gives true. Archived or soft-state nodes still have a row, so they give true. That is the right "is a row" semantics, and the doc says so.
Findings
- Non-blocking,
crud.rs~2651 (delete_leaf_node). The access gate runs before the existence check.delete_nodereturnsexisted:falsefor an absent target before consulting the gate. A sync gate that denies unknown or unreadable ids would turn an idempotent absent-id delete intoSubtreeAccessDenied. This contradicts the doc line "an absent node isNotFound". Either check existence first or document it. Gate-then-NotFound is arguably safer against id probing. - Non-blocking, test gap,
nodes.rs~1838. I removed the in-transaction version recheck and all 5 tests still pass. The earlier pre-transaction check masks it. That recheck is the TOCTOU guard and has no test. A deterministic test is hard, since it needs a hook between the two reads, so this is acceptable. Alternatively drop the redundant pre-transaction OCC check and rely on the in-transaction one only. - Non-blocking,
nodes.rs~1818. There is a redundant pre-transactionget_node, plusassert_schema_deletablebefore the lock. This mirrorsdelete_subtree_atomic, but the recheck inside the transaction already returnsNotFound. Fine as is. - Non-blocking,
mod.rstests. Not covered:- the sync bypass path;
- the embedding requeue (the claim in the PR description);
- a leaf that has mentions or incoming edges;
- a schema node (
schema_has_declarations).
The one-event test also only asserts the ids of events that arrive within a 500ms window each.
- Non-blocking,
crud.rs~2682. Ifget_embedding_root_idfails on aHasChildrenorNotFoundoutcome, nothing is requeued. That is correct.
(e) Mutation check.
- Disabling the children check makes 2 tests fail:
refuses_a_node_with_childrenandsees_a_child_attached_after.... Good. - Disabling the in-transaction version recheck makes none fail. See finding 2.
(f) Docs and comments are accurate apart from finding 1.
No blocking issues.
is_persisted(id) reports whether a node is a stored row, without the virtual-date fallback get_node applies to unstored YYYY-MM-DD ids. delete_leaf_node(id, expected_version) deletes exactly one node and its own edges, checking version and has_child children inside the write transaction; a node with children yields LeafDeleteOutcome::HasChildren and nothing is deleted. Same access gate, OCC error and NodeDeleted event as delete_node. SqliteStore::delete_leaf_atomic is the store-level primitive. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… edge, bypass, schema and requeue tests Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
25b237b to
9097dbd
Compare
Closes #3859
What
Two additive APIs that nodespace-sync#596 needs (no existing signature, behaviour or wire type changes; no TS-generated types touched).
NodeService::is_persisted(&self, id: &str) -> Result<bool, NodeServiceError>: true only when a row is stored.get_nodereturns a computed version-1 placeholder for any unstored YYYY-MM-DD id, so a persisted date node was indistinguishable from a virtual one at snapshot 0; this reads the node table directly.NodeService::delete_leaf_node(&self, node_id: &str, expected_version: i64) -> Result<db::LeafDeleteOutcome, NodeServiceError>(store primitiveSqliteStore::delete_leaf_atomic): deletes exactly one node and its own edges. The has_child children check runs inside the write transaction, so a child created after the caller collected its subtree yieldsLeafDeleteOutcome::HasChildren { child_count }and nothing is deleted (the caller re-collects and retries). Same OCC (VersionConflict), access gate (ADR-041, one-node check, bypass-aware) and singleNodeDeletedevent asdelete_node.LeafDeleteOutcome=Deleted | NotFound | HasChildren { child_count: u64 }.Tests
Six new
node_servicetests (leaf delete + one event + sibling kept, refusal with children, child attached after version read, version conflict / missing node, access gate refusal, virtual vs persisted date). Each mutation-checked (removing the behaviour fails the test). Existingtest_delete_node*still pass. clippy -D warnings and fmt clean; pre-push gate passed.🤖 Generated with Claude Code