Skip to content

Builtin relationships cannot declare edge fields, so collection RBAC is still free text #2429

Closed

Description

@malibio

Gap

#2387 added enum edge fields so a relationship can declare a closed value set, and was framed as the schema-side prerequisite for RBAC on collection↔person. It delivers that for schema-declared relationships — but the RBAC edge itself is a built-in relationship, which cannot carry declared edgeFields at all. So the RBAC work is not actually unblocked yet.

Two independent gates reject a builtin as a declaration:

  • reject_reserved_relationship_names (packages/core/src/schema/mod.rs) refuses any declaration named after a builtin
  • set_schema_relationships (packages/core/src/services/node_service/schema.rs) re-checks the same predicate on the write path

BUILTIN_RELATIONSHIP_NAMES is ["member_of", "has_child", "mentions", "has_role"]. The example JSON in #2387 — {"name": "member_of", "targetType": "collection", "edge_fields": [{"name": "role", "type": "enum", ...}]} — is therefore rejected before it reaches the new validation.

This is not a defect in #2387: with no declaration there is no edge_fields to validate against, so skipping builtins on the write path is correct. The gap is that the motivating use case sits on the one kind of relationship the new machinery cannot describe.

Where roles live today

Roles already ride a builtin edge, unvalidated. Per ADR-037, the seeded owner edge is created as:

create_relationship(&local_person_id, "has_role", &settings_id,
                    json!({"role": "owner", "status": "active"}))

So role on has_role is exactly the free-text access-control field #2387 was written about — "Owner", "owner" and "onwer" are still three distinct roles there, with no picker and no validated default.

Options

  1. Model collection RBAC as a new custom relationship (e.g. has_access, declared on person targeting collection) rather than extending member_of. EdgeField cannot declare enum values, so RBAC roles on a relationship would be free text #2387 is then a complete prerequisite and nothing further is needed on the schema side. Cheapest, and keeps membership (member_of, structural/ordered) separate from authorization — arguably the better model regardless. The cost is a second edge alongside member_of for the same pair.

  2. Give builtin relationships a way to declare edge fields. A fixed, code-owned edge-field table keyed by builtin name (not user-declarable, since the names stay reserved), consulted by the same validate_edge_data_against_fields on the write path. Covers has_role.role and has_role.status too, so the existing owner edge gets validated. Larger, and needs a decision on where that table lives and whether the UI reads it through the same edgeFields channel.

  3. Leave builtin edge data unvalidated and accept free-text roles on has_role. Cheapest now; keeps the exact hazard EdgeField cannot declare enum values, so RBAC roles on a relationship would be free text #2387 identified, on the one field where a wrong value is security-relevant.

Option 1 looks right if authorization is genuinely separable from membership; option 2 is the better answer if roles must stay on has_role, and has the side benefit of validating the edge that already exists. Worth deciding on that basis before the collection RBAC UI is built, since the choice determines whether the role picker has a schema to read from.

Acceptance criteria

  • Decide between the options above and record why
  • A collection↔person access level is expressible with a declared, validated value set
  • The existing has_role owner edge's role/status are either validated or explicitly documented as unvalidated, with the reason
  • The relationships UI can render a picker for the chosen shape
  • Schema-authoring guidance reflects whichever shape is chosen (the ENUM_EDGE_FIELDS rule currently tells agents that builtins cannot carry edge fields — that stays accurate under option 1, and needs updating under option 2)

Context

Found during code review of #2427 (the #2387 implementation), which flagged that the PR's stated motivation was not delivered by the change. The ENUM_EDGE_FIELDS agent guidance in that PR was reworded to state the builtin limit explicitly, and schema_declaring_an_edge_field_on_a_builtin_relationship_is_rejected asserts it, so the current behavior is documented and pinned rather than silently surprising — but the design question remains open.

Activity

  1. malibio commented on Sep 8, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 233 test files passed (4900 tests), 89.24s. No pre-existing failures.

  2. self-assigned this
    on Sep 8, 2026
  3. malibio commented on Sep 8, 2026

    @malibio
    CollaboratorAuthor

    Decision: option 2 (a code-owned edge-field table for builtin relationships)

    The issue's own analysis favours option 1 (a new has_access relationship on person targeting collection). Reading the code and ADR-037, option 1 is not available: it would contradict an accepted architecture decision and require rewriting the Pro RLS predicate. Recording the evidence, since option 2 is the larger change.

    Why option 1 is not open

    ADR-037 (../nodespace-docs/decisions/037-collection-access-model.md) is accepted and already implemented on the local side. It does not merely happen to put collection permission on member_of — it decides that, and it explicitly rejects moving it elsewhere:

    Permission as a dedicated collection_members table column. Rejected in ADR-036 in favor of edge-property + VIEW; this ADR keeps permission on the member_of edge.

    Three concrete dependencies follow from that, all present in the code today:

    1. The core collection schema already documents the field as living there. packages/core/src/models/core_schemas.rs (restrictedToMembers): "member_of edge permission (admin/modify/readOnly) is a free-form edge property the RLS reads directly — no schema field needed." That comment is the gap this issue describes, verbatim, at the site where it bites.

    2. The RLS predicate walks member_of, not a second edge. ADR-037's access evaluation section: the upward walk unions member_of and has_child, and at a restrictedToMembers boundary requires "a person member_of edge to that collection; their level comes from the edge." Introducing has_access means the recursive predicate must walk a third edge type, and the Last-Admin Invariant trigger (a BEFORE DELETE OR UPDATE on member_of relationship edges) must move to it too. That is a Pro-schema change, not a local-schema change, and this repo cannot make it.

    3. member_of is not declarable, so the "second edge" is not free. ADR-059 records that descendants inherit an ancestor's access but never its membership. Splitting authorization onto a parallel edge means every restricted collection carries two edges per person that must be kept consistent — the membership edge deciding whether the walk finds you, and an access edge deciding your level. ADR-037 chose one edge for exactly this reason.

    There is a second, independent argument. Option 1 addresses only the collection axis; it leaves has_role untouched. ADR-037 defines two authority axes — collection-edge permission (admin/modify/readOnly) and tenant role on has_role (owner/admin/editor/viewer) — and both are free text today. The seeded owner edge in NodeService::seed_database_settings_if_needed writes {"role": "owner", "status": "active"} with nothing validating either key. Option 1 leaves that untouched; the third acceptance criterion would then have to be discharged as "explicitly documented as unvalidated", on the field where a wrong value is most security-relevant. Option 2 covers both axes with one mechanism.

    What option 2 costs, and why it is bounded

    Less than the issue estimates, because both halves already exist:

    • validate_edge_data_against_fields (packages/core/src/services/node_service/relationship.rs) is already the single choke point for edge-enum validation on both the create and update paths. It takes &[EdgeField] — it does not care where the fields came from. The builtin branch of create_relationship simply never looks any up.
    • The UI already renders a picker from whatever edgeFields a group carries: edgeInputKind in packages/desktop-app/src/lib/services/edge-field-input.ts returns enum for a field with coreValues. The reason no picker appears for member_of/has_role is that get_node_relationships (packages/core/src/ops/rel_ops.rs) skips builtins entirely, so no group is emitted.

    So the change is: a code-owned table keyed by builtin name, consulted by the write path and surfaced through the same edgeFields channel the UI already reads. The names stay reserved — the table is not user-declarable, and both existing rejection gates (reject_reserved_relationship_names, set_schema_relationships) stay exactly as they are. That preserves the invariant those gates protect (declarations and primitives share one relationship_type column) while removing the reason the gap existed.

    The ENUM_EDGE_FIELDS agent guidance is updated accordingly: builtins still cannot be declared, but they now carry a fixed, code-owned set an agent should not try to change.

    Scope note

    This ships the local-side validation and the picker. It does not touch the Pro RLS function or the Last-Admin trigger — those live outside this repo and are unchanged by this work, which is precisely the point: option 2 leaves the storage shape ADR-037 specified exactly where it is.

  4. malibio commented on Sep 8, 2026

    @malibio
    CollaboratorAuthor

    Closing unimplemented: the premise does not hold for this repo

    Investigated end to end. The gap this issue describes is real, but it is real in nodespace-sync, not here. Closing rather than implementing, with the reasoning recorded so nobody re-derives it.

    Core is single-user and has no permission concept

    One user, all nodes accessible. Nothing in core ever reads a permission to decide anything. That is not a missing feature — it is the design.

    So a permission on a member_of edge is not a data shape core validates; it is a concept core does not have. RBAC representation and enforcement both belong to the Pro daemon and its Postgres RLS policies (user_can_access_node, user_can_write_node, my_collection_ids, create_invite, set_member, remove_member, the last-admin check). The chain #2387 → #2427 → #2429 assumed permissions live in core. They do not.

    The strongest remaining argument for putting the vocabulary here was typo divergence — that "Admin"/"admin"/"amdin" would become three permissions in the local store. It does not survive the above: nothing local reads the value, and the component that owns the policy is also the one that writes and reads it.

    The vocabulary that looks like core's is Pro-gated

    packages/desktop-app/src/lib/components/collaboration/collaboration-view.svelte:24 declares const PERMISSIONS: Permission[] = ['readOnly', 'modify', 'admin'], which reads as core already owning the set. It does not: packages/desktop-app/src/lib/plugins/pro-plugin.ts mounts collaboration-tab only under the relogin and connected variants — community edition gets teaser and never reaches it. That array is Pro-surface code that happens to live in this repo.

    Nor is there anywhere to put a Pro-only enum: packages/core/Cargo.toml declares exactly one feature, nlp. A community build would carry the vocabulary unconditionally.

    No builtin has a core-owned vocabulary

    Option 2 (a code-owned edge-field table keyed by builtin name, consulted by the same validate_edge_data_against_fields as declared relationships, surfaced through the same edgeFields channel) was implemented and then discarded. The design is sound; it has no consumer here.

    With the collection permission excluded as Pro policy, the table ships empty:

    • has_child and member_of both carry a numeric order — a fractional position computed by the store, not a closed vocabulary. Edge validation is enum-membership-only by deliberate design.
    • mentions carries nothing.
    • has_role carries the tenant axis, which nodespace-sync documents as an explicitly OPEN set (owner/tenant-admin/member) and decodes tolerantly. Closing it in core would make the local store reject a role the authority on roles had issued. It should stay unvalidated — which is the alternative the third acceptance criterion already offers.

    An empty table means an always-None function, two never-matching call sites, a rel_ops loop that emits nothing, and an uncallable helper. Tests cannot rescue it either: the table is a compile-time match on a &str, so exercising it would mean adding a registration seam whose only purpose is to give dead production code a caller. That is a hollow abstraction, and the greenfield rules exist to prevent exactly it.

    The mechanism should land with its first real consumer, in the repo that owns the policy — not before.

    Acceptance criteria, per criterion

    1. Decide between the options and record why — done, here. Neither option 1 nor option 2 as framed; the premise is wrong for this repo.
    2. A collection↔person access level expressible with a declared, validated value set — not core's. Core has no access levels to express.
    3. has_role role/status validated or explicitly documented as unvalidated, with the reason — satisfied by this comment, taking the documented-as-unvalidated branch: the tenant axis is an open set owned by sync.
    4. The relationships UI can render a picker for the chosen shape — not core's, and already true where it applies: the picker renders from whatever edgeFields a group carries (edgeInputKind in packages/desktop-app/src/lib/services/edge-field-input.ts returns enum for a field with coreValues). It needs a vocabulary, not new UI.
    5. Schema-authoring guidance reflects the chosen shape — no change needed. The current ENUM_EDGE_FIELDS wording ("the built-in structural names are reserved and rejected as declarations, so you cannot attach an edge field to them") stays accurate, because no mechanism is shipping.

    Open cross-repo question, for whoever picks this up in nodespace-sync

    my_collection_ids() reads a collection_members view keyed on user_id, while ADR-037 describes the permission as riding the member_of edge (relationships.properties->>'permission'). Whether those are one datum or two representations that must be kept in step is unresolved, and cannot be settled from this repo. It matters before anyone builds on either.

    Kept from this investigation

    One genuine, unrelated bug surfaced while testing and is filed separately: SqliteStore::add_to_collection silently discards every edge attribute except order. That one is unambiguously core's and is live today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions