Skip to content

C3b: Enforce container rule (canHaveChildren) in the daemon; source the frontend UI gate from schema #1260

Closed

Description

@malibio

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.

  1. Daemon enforces. NodeService::move_node (and create_node/upsert_node_with_parent where a parent is set) rejects placing a child under a parent whose behavior returns can_have_children() == false, with a typed error (reuse InvalidParent / a new NotAContainer variant). Any caller (frontend, agent, MCP) is rejected uniformly.
  2. 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_children value becomes part of schema/behavior metadata the frontend already fetches (or is exposed on existing schema read RPCs), and pluginRegistry.canHaveChildren derives 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::NotAContainer or reuse InvalidParent) mapped to a clear gRPC Status via service_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_children is 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-set canHaveChildren: true flags. Remove the duplicated hardcoded flags in core-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 daemon NotAContainer rejection 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 canHaveChildren predicate 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 test asserting move_node rejects a child under a non-container (e.g. a leaf query node) 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 NotAContainer rejection.
  • Parity test: the frontend predicate and Rust can_have_children() agree for every built-in node type (lock the single-source contract).
  • bun run check clean; createLogger; no lint-suppression.

Risks

  • Schema-sourcing scope creep. If can_have_children isn'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

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

  1. malibio commented on May 30, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 132 files, 3873 tests passed

  2. self-assigned this
    on May 30, 2026
  3. added 2 commits that reference this issue on May 30, 2026
    f79b8af
    3f7fb24
  4. added a commit that references this issue on Jun 22, 2026
    a1c986a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions