Repository navigation
Closed
Labels
Description
Problem
Currently, when the frontend creates a node with a parent, it must manufacture the edge/relationship data locally using addInMemoryRelationship(). This is a workaround because the backend's create_node API only returns the node ID, not the relationship data.
From packages/desktop-app/src/lib/utils/node-hierarchy.ts:
// TODO: This is a workaround. The proper fix (per hierarchy-reactivity-architecture-review.md)
// is for the backend to return complete relationship data from node creation, allowing the
// frontend to apply a proper optimistic update instead of manufacturing relationship records.Current Workaround
// Frontend guesses the order value
const order = existingChildren.length > 0 ? existingChildren.length + 1.0 : 1.0;
reactiveStructureTree.addInMemoryRelationship(parentId, childId, order);This is problematic because:
- Frontend manufactures database records (violates single source of truth)
- Order calculation may not match backend's fractional ordering
- Edge ID is manufactured (
${parentId}-${childId}) instead of using database ID
Proposed Solution
Backend Changes
-
packages/core/src/operations/mod.rs:
- Create
CreateNodeResultstruct:pub struct CreateNodeResult { pub node_id: String, pub edge: Option<HierarchyRelationship>, // Present if parent_id was provided }
- Modify
create_node()to returnResult<CreateNodeResult, NodeOperationError>
- Create
-
packages/desktop-app/src-tauri/src/commands/nodes.rs:
- Update
create_nodecommand to returnCreateNodeResult - Add serialization for new type
- Update
Frontend Changes
-
packages/desktop-app/src/lib/services/tauri-commands.ts:
- Update
createNode()return type
- Update
-
packages/desktop-app/src/lib/services/shared-node-store.ts:
- Use returned edge data instead of manufacturing it
-
packages/desktop-app/src/lib/utils/node-hierarchy.ts:
- Remove
registerChildWithParent()workaround (or simplify to use real data)
- Remove
Benefits
- Single source of truth for relationship data
- Correct edge IDs from database
- Correct fractional order from backend
- Eliminates frontend responsibility for database record generation
Reference
See docs/architecture/development/hierarchy-reactivity-architecture-review.md for architecture context.
Activity
malibio commentedon Nov 22, 2025
Note from PR #604 Review
During the code review of PR #604, the reviewer noted that the Rust verification query was removed in
surreal_store.rswith this comment:Suggestion: Once this issue (#603) is implemented and the backend returns complete relationship data from createNode, consider adding:
This would help detect any edge cases where CREATE might fail silently. The verification query removal was necessary to avoid timing issues, but observability could be improved as part of this work.
Address code review recommendations from PR #604
Post-migration fixes: terminology cleanup, edge abstraction, placehol…
malibio commentedon Nov 22, 2025
Note: HierarchyRelationship Type
When implementing this issue, the backend should return relationship data using the
HierarchyRelationshiptype structure (fromevent-types.ts):Current assessment: No changes needed to the type itself.
This issue actually validates the abstraction - the returned relationship data will match the existing type, and frontend code can use
getParentId()/getChildId()helpers if needed.Reference:
HierarchyRelationshipwas introduced in PR #604 to abstract SurrealDB's edge format from frontend code.malibio commentedon Nov 22, 2025
Closing as resolved. LIVE SELECT now handles relationship updates automatically via edge:created events. The registerChildWithParent() workaround in node-hierarchy.ts is never called (dead code). The manual relationship manufacturing is no longer needed.
Remove dead workaround code from node-hierarchy.ts
Remove dead workaround code from node-hierarchy.ts (#617)
Remove dead workaround code from node-hierarchy.ts (#617)
Refactor tree loading to use efficient adjacency list strategy (#632)
Post-migration fixes: terminology cleanup, edge abstraction, placehol…
Remove dead workaround code from node-hierarchy.ts (#617)
Refactor tree loading to use efficient adjacency list strategy (#632)
Post-migration fixes: terminology cleanup, edge abstraction, placehol…
Remove dead workaround code from node-hierarchy.ts (#617)
Refactor tree loading to use efficient adjacency list strategy (#632)
Post-migration fixes: terminology cleanup, edge abstraction, placehol…
Remove dead workaround code from node-hierarchy.ts (#617)
Refactor tree loading to use efficient adjacency list strategy (#632)