Repository navigation
Description
Spun off from architectural-audit tracking issue #1228, finding C3 (container rules sub-piece). Ordering math → #1259 (C3a).
Background — the rule exists in Rust but isn't enforced on move
can_have_children() is a first-class method on the Rust behavior trait (packages/core/src/behaviors/mod.rs:208), implemented per node type (text/date/collection true; query/task-leaf false, etc.). But NodeService::move_node never calls it — verified at packages/core/src/services/node_service/mod.rs:1575-1641, which validates version, date-node immobility, parent existence, and circular reference, but not whether the new parent is a container.
The only enforcement today is in the frontend: indentNode gates on pluginRegistry.canHaveChildren(prevSibling.nodeType) (reactive-node-service.svelte.ts:853). pluginRegistry.canHaveChildren (plugin-registry.ts:318-323) reads a per-plugin canHaveChildren flag (core-plugins.ts, schema-plugin-loader.ts:141). So the rule is duplicated and unenforced authoritatively: a move via the RPC directly (agent, MCP, cross-window) can place a child under a non-container, and the frontend copy can drift from the Rust behaviors.
Target architecture
Daemon is authoritative; frontend keeps a synchronous derived copy for UX gating — sourced from the same schema, not hand-maintained.
- Daemon enforces.
NodeService::move_node(andcreate_node/upsert_node_with_parentwhere a parent is set) rejects placing a child under a parent whose behavior returnscan_have_children() == false, with a typed error (reuseInvalidParent/ a newNotAContainervariant). Any caller (frontend, agent, MCP) is rejected uniformly. - Frontend gates the UI synchronously without a round-trip. Indent must disable instantly per keystroke — a round-trip per Tab is unacceptable. The frontend keeps a derived, cached container predicate, but sourced from schema the frontend already loads, not a separately hand-maintained flag list. The
can_have_childrenvalue becomes part of schema/behavior metadata the frontend already fetches (or is exposed on existing schema read RPCs), andpluginRegistry.canHaveChildrenderives from that single source. The frontend gate is an optimistic UX hint; the daemon rejection is the truth. On the rare rejection, roll back the optimistic indent (the indent path already has rollback at lines 966-977).
Avoiding the round-trip: no per-keystroke RPC. The container predicate is resolved from already-loaded schema metadata. The only network interaction is the normal moveNode RPC the indent already makes, which now authoritatively rejects an invalid placement.
Exact changes
Daemon/core:
- In
NodeService::move_node(mod.rs, after the parent-exists check ~1606), look up the new parent's behavior and reject when!can_have_children(). Same guard in the create/upsert-with-parent paths. - Add/confirm a typed error (
NodeServiceError::NotAContaineror reuseInvalidParent) mapped to a clear gRPCStatusviaservice_error_to_status(exhaustive mapping landed in B6/B6: Exhaustive NodeServiceError→gRPC error mapping + parity tests #1257 — add the new variant there). - Ensure
can_have_childrenis reachable from schema/behavior metadata exposed to the frontend (extend the schema read response or behavior metadata surface) so the frontend derives the predicate without hardcoding flags.
Frontend:
-
pluginRegistry.canHaveChildren(plugin-registry.ts:318) derives from the schema-sourced metadata rather than per-plugin hand-setcanHaveChildren: trueflags. Remove the duplicated hardcoded flags incore-plugins.ts/schema-plugin-loader.ts. - Keep the synchronous gate at
indentNode(reactive-node-service.svelte.ts:853) as a UX optimization; ensure the existing rollback (966-977) handles a daemonNotAContainerrejection gracefully and surfaces it (don't silently swallow).
Proto: only if can_have_children must be added to a schema read response message. Prefer surfacing it on the existing schema/behavior metadata path; add a field only if no existing field carries it.
Acceptance criteria
- A
MoveNode(and create-with-parent) RPC placing a child under a non-container node is rejected by the daemon with a typed, descriptive error — verified independent of the frontend. - The frontend's
canHaveChildrenpredicate is derived from the same source the daemon uses, with no separately hand-maintained flag list. - Indent UI still disables synchronously (no per-keystroke round-trip).
- A daemon container rejection rolls back the optimistic indent and surfaces (not silently swallowed).
Testing
- End-to-end enforcement test (required, addresses "can't validate end-to-end"):
cargo testassertingmove_noderejects a child under a non-container (e.g. a leafquerynode) and accepts under a container — driven purely through the daemon. - Vitest: indent gate disabled for non-container previous siblings; optimistic indent rolls back on a simulated daemon
NotAContainerrejection. - Parity test: the frontend predicate and Rust
can_have_children()agree for every built-in node type (lock the single-source contract). -
bun run checkclean;createLogger; no lint-suppression.
Risks
- Schema-sourcing scope creep. If
can_have_childrenisn't already on the schema read path, exposing it touches the schema RPC surface. Keep minimal — one metadata field, no behavioral change to schema reads. - Live outliner. A newly-strict daemon could reject indents the frontend previously allowed (drift between the two copies). Audit the built-in types up front so enforcement matches current UX exactly; greenfield means fix divergence by correcting the frontend, not loosening the daemon.
Coordination
- Parallel-safe with C3a (C3a: Delete frontend outdent ordering math — trust the daemon's authoritative order via relationship events #1259) (disjoint: C3a = ordering, C3b = container predicate), B8 (B8: Close TOCTOU in bulk_update / bulk_create_hierarchy (read escapes the transaction) #1258), B4 follow-up: fold remaining 11 CollectionService::new daemon sites into core (collection_ops) #1243.
- Builds on C2/C2: Make structureTree single source of truth — unify dual sync paths + invariant check #1250 + C1a/C1a: Consolidate the node-CRUD transport layer — fold tauri-commands node half into backendAdapter #1255 + B6/B6: Exhaustive NodeServiceError→gRPC error mapping + parity tests #1257 (error mapping). Contributes to unblocking C1b.
Standard NodeSpace startup / PR sequence
EnterWorktree({name: "issue-<N>-c3b-container-rules"}), bun install, baseline, gh:*, test:all, quality:fix + commit, gh:pr, /pragmatic-code-review before merge. bun run test not bun test.
Spun off from #1228 (architectural audit), finding C3 (C3b — container rules).
Activity
malibio commentedon May 30, 2026
Frontend baseline: 132 files, 3873 tests passed
C3b: Enforce container rule in daemon; add parity test for frontend g…
C3b: Enforce container rule (canHaveChildren) in the daemon; source t…
C3b: Enforce container rule (canHaveChildren) in the daemon; source t…