Repository navigation
Description
Background
NodeService::create_parent_edge, NodeService::reorder_child, and the underlying move_node (now SqliteStore::move_node after the libsql migration) all currently express insertion position as insert_after_node_id: Option<&str>:
Some(id)→ "insert after this sibling"None→ "insert at beginning of the parent's children"
This shape silently overloads None for callers with opposite intents:
| Caller | Intent for None |
|---|---|
Outliner Enter-at-position-0 (shouldCreateNodeAbove branch) |
"insert at beginning" |
Sync pull-side apply_remote (cloud has_child echo with no order field) |
"append at end" |
reorder_node(_, _, None) move-to-first |
"insert at beginning" |
| Future caller wanting "no hint, just place it somewhere reasonable" | ambiguous |
Today the sync caller has to compute last_child_id explicitly to express "append" (see NodeSpaceAI/nodespace-sync#79) — an extra get_children round-trip per echoed edge — because there is no signal it can pass that the backend would interpret as "end."
⚠️ Updated 2026-05-29 after thenodespaceddaemon + SQLite migration. The original issue framed the MCP HTTP handlers as the primary call site. That is no longer accurate — see "Current architecture" below. The ambiguity has since propagated into the gRPC proto wire format (empty string = beginning), which is now the most important surface to fix.
Current architecture (post-nodespaced)
MCP is no longer served over HTTP. The live request path is:
Claude Desktop / Claude Code
→ packages/mcp (TypeScript, stdio transport)
→ `nodespace` CLI (stateless gRPC client)
→ nodespaced daemon (tonic, Unix socket) ── NodeServiceImpl
→ NodeService (packages/core)
→ SqliteStore
Consequences for this issue:
- The Rust HTTP MCP server (
packages/core/src/mcp/) is dev-only now — constructed solely bypackages/dev-tools/src/bin/dev-mcp.rs. Neither the Tauri shell nornodespacedstart it. Itshandle_insert_child_at_index/handle_move_child_to_indexhandlers are still worth migrating for consistency, but they are off the production hot path. - The gRPC layer is now the primary consumer and it has re-encoded the same
Noneoverload as an empty-string sentinel in the proto (empty = beginning, viaempty_to_nonein the daemon). Fixing this properly means the proto field should carry intent, not an overloaded string. - The TypeScript
packages/mcpserver does not yet expose reorder/insert-at-index tools, so there is nothing to migrate there today.
Proposal
Introduce an InsertPosition enum that captures intent at the Rust API surface:
pub enum InsertPosition<'a> {
/// Insert at the beginning of the parent's children list.
Beginning,
/// Insert at the end of the parent's children list.
End,
/// Insert directly after the named sibling. If the sibling is not
/// found in the parent's children, fall back to `End` (today's
/// `move_node` semantic).
After(&'a str),
}create_parent_edge and reorder_child take this enum directly:
pub async fn create_parent_edge(
&self,
child_id: &str,
parent_id: &str,
position: InsertPosition<'_>,
) -> Result<(), NodeServiceError>;SqliteStore::move_node keeps its underlying Option<&str> for compatibility with the lower layer, but the calculation in move_node exposes both "first_order - 1" and "last_order + 1" branches via the enum at the service layer.
Proto / wire change
The string insert_after_node_id fields in CreateNodeRequest, MoveNodeRequest, and ReorderNodeRequest (packages/proto/proto/node_service.proto) must stop overloading the empty string. Replace with an explicit position that maps to the enum — e.g. a oneof or an enum field carrying BEGINNING | END | AFTER(id). The daemon's empty_to_none translation is deleted in favor of decoding the explicit variant.
Migration / call sites (verified 2026-05-29)
All of these pass position to the ordering APIs and must be migrated:
Proto + daemon gRPC (primary, production):
-
packages/proto/proto/node_service.proto—CreateNodeRequest.insert_after_node_id,MoveNodeRequest.insert_after_node_id,ReorderNodeRequest.insert_after_node_idre-expressed to carry intent -
packages/daemon/src/services/node_service.rs—create_node,move_node,reorder_nodeRPCs (currently useempty_to_none) -
packages/daemon/src/services/import_service.rs—create_node_with_parentcall
Core service + storage:
-
InsertPositionenum lives inpackages/core/src/services/ -
create_parent_edge,reorder_child,reorder_nodeaccept the enum -
create_node_with_parent,move_node_uncheckedmigrated
Tauri frontend bindings:
-
packages/desktop-app/src-tauri/src/commands/nodes.rs+lib.rs— command params - TS callers in
packages/desktop-app/src/lib/services/(reactive-node-service, shared-node-store, optimistic-operation-manager, pending-operations, tauri-commands, backend-adapter, tauri-sync-listener, collection-service)
Dev-only Rust MCP (migrate for consistency):
-
packages/core/src/mcp/handlers/nodes.rs—handle_insert_child_at_index(drop the create-then-reorder-to-beginning hack),handle_move_child_to_index(drop the index→sibling translation)
Cross-repo companion:
- Nodespace-sync PR migrating
apply_remotefrom the explicitlast_child_idworkaround (#79) toInsertPosition::End
Cleanup unlocked by this
handle_insert_child_at_indexcurrently inserts at index 0 on a non-empty list by creating at the end then callingreorder_node(.., None)to move it up — collapses to oneInsertPosition::Beginningcall.handle_move_child_to_indexruns a retry/verify loop to disambiguate beginning-vs-end — removable once intent is explicit.- The daemon's
empty_to_nonesentinel decoding for position fields goes away. - Several stale "SurrealDB eventual consistency" /
sleep()-based retry comments in the MCP handlers predate the SQLite migration and should be deleted as part of this.
Why this matters
This is the "right" shape the recent nodespace-sync#77 work groped towards via overloads and translations:
#1214's original revision hadcreate_parent_edgetranslateNone → last_childat the service layer. That broke the outliner's Enter-at-position-0 UX (new line landed at bottom instead of above the current line). The fix lived at the wrong layer becauseNonecouldn't carry intent.- The stripped revision of
#1214keeps idempotency only; the receive-side append-at-end semantic moved tonodespace-sync#79where it can be expressed unambiguously. - An
InsertPosition::Endwould let sync express the same intent without the extraget_childrenround-trip per echo.
Out of scope
- Bulk-move APIs (
move_nodes, batch reorder) — keepInsertPositionper-call. - Cross-parent semantics — unchanged; the parent-id argument already covers that.
Acceptance criteria
-
InsertPositionenum exists inpackages/core/src/services/ -
create_parent_edge,reorder_child,reorder_nodeaccept the enum - Proto position fields re-expressed to carry intent; daemon
empty_to_nonefor position removed - All call sites in the migration list above are updated (proto, daemon gRPC, core, Tauri commands, TS services, dev MCP handlers)
- Nodespace-sync companion PR migrating
apply_remotetoInsertPosition::End - Per-variant tests added; existing tests continue to pass
- Stale SurrealDB/eventual-consistency comments + create-then-reorder hack + move retry loop removed from the MCP handlers
- No
clippy::needless_matchor similar warnings from the new enum
References
- Root cause for the API confusion:
nodespace-sync#77(the receive-side ordering bug that surfaced both intents passing throughNone) - The pragmatic resolution that shipped:
#1214(idempotency only) +nodespace-sync#79(sync passes explicitlast_child_id) - Daemon migration that moved MCP off HTTP and re-encoded the overload in proto:
nodespaced+ SQLite migration (#1222,#1224) - The cleaner long-term shape: this issue
Activity
[-]API: introduce InsertPosition enum for create_parent_edge / move_node / reorder_child[/-][+]API: introduce InsertPosition enum across proto/gRPC + service (replace overloaded insert_after_node_id)[/+]Add CLI coverage for query, export, batch, mention, schema ops (closes …
Introduce InsertPosition enum across proto/gRPC + service layer (closes
API: introduce InsertPosition enum across proto/gRPC + service (repla…
Add CLI coverage for query, export, batch, mention, schema ops (closes …
CLI coverage gap: surface remaining knowledge-graph operations so ski…
API: introduce InsertPosition enum across proto/gRPC + service (repla…
CLI coverage gap: surface remaining knowledge-graph operations so ski…