Skip to content

ADR-037: Collection access model — core data plane (restrictedToMembers, member_of permission, PersonNode seeding) #1372

Closed

Description

@malibio

Land the open-core data plane for ADR-037's organizational-by-default / opt-in-restriction access model, so a future nodespaced-pro RLS layer can enforce it. Per ADR-028 this issue covers only inert, local-first data and ops: a Core-protected boolean restrictedToMembers on the collection schema, a permission value (admin/modify/readOnly, default modify) on member_of edges, and the ops the UI needs to toggle restriction and manage person members with permission levels.

PersonNode the type is owned by #133 — this issue depends on it for the person-only membership check and does not re-specify it. No PersonNode instance is seeded locally (nothing reads it in the free/local journey); the first PersonNode is created at Pro sync-onboarding (create + name + bind), a pro/frontend flow.

Out of scope (private nodespace-sync / nodespace-cloud): RLS enforcement (user_can_access_node/user_can_write_node, nearest-boundary recursive CTE, break-inheritance, person-only filter), the atomic auto-admin bootstrap on restrict, the Last-Admin Invariant trigger, auth_identities/JWT bind, all cloud DDL (nodes.id TEXT, collection_members VIEW, REPLICA IDENTITY FULL), and PersonNode instantiation/naming. Core lands the data they read.

Greenfield (per CLAUDE.md): no migration code. The modify read-default covers legacy member_of edges; absent restrictedToMembers = false. Reset is acceptable.

Dependencies

  • Implement PersonNodeBehavior #133 (PersonNode type) — hard prerequisite for Task C2 (person-only membership) and the member-list ops. PersonNode schema + behavior live there, not here.

What core must land (the wire contract pro reads)

Two things on the wire, plus the person keyspace (#133) the edges point at:

  • properties.restrictedToMembers: bool on collection nodes
  • properties.permission: "admin" | "modify" | "readOnly" on person member_of edges

Task A — restrictedToMembers core property on collection

No dependency. Ship first.

  • Add a restrictedToMembers SchemaField (boolean, protection: Core, default false, not required) to the collection SchemaNode in packages/core/src/models/core_schemas.rs (entry ~L285, currently fields: vec![]).
  • In CollectionNodeBehavior::validate (packages/core/src/behaviors/mod.rs ~L1424), reject a non-boolean restrictedToMembers (mirror TaskNodeBehavior type-check ~L671). Absent/null → treated as false.
  • Verify SchemaProtectionLevel::Core actually blocks writes at the persistence boundary (not just advisory/UI-hidden) for arbitrary update_node callers — if advisory today, add a hard reject in the behavior + ensure the protection path runs on every collection update. (See Risk 1.)
  • Tests: absent→valid(false); true/false→valid; "true"/number→InvalidProperties.

Task B — permission value on member_of edges

No dependency; inert until persons exist.

  • Extend SqliteStore::add_to_collection (packages/core/src/db/sqlite_store.rs ~L2887) to accept optional permission and write it into the edge properties JSON alongside order (additive, no DDL — edge properties already exists ~L2934).
  • Add set_member_permission(member_id, collection_id, permission) updating properties->>'permission'.
  • Define a Permission enum (Admin/Modify/ReadOnly) serializing to admin/modify/readOnly; reads default to modify when absent.
  • Validate the enum at the ops boundary; reject unknown strings.
  • Tests: each level round-trips; absent→modify; unknown rejected; permission update.

Task C — Ops: set restriction, add person members, set permission, list members

Depends on Task B + #133 (person type).

  • set_collection_restriction(collection_id, bool) in collection_ops.rs — plain property write, no auto-admin grant (that is the pro bootstrap, deliberately omitted).
  • add_person_to_collection(person_id, collection_id, permission) — validates out_node is node_type='person' (person-only, ADR-037 §4); default modify.
  • set_member_permission(...) wrapping Task B.
  • Extend get_collection_members / _recursive (collection_ops.rs ~L164/L180; queries sqlite_store.rs ~L2991/L3084) to surface each member's permission (default modify).
  • Tests: non-person rejected; person at each level; permission change; list returns levels.

Suggested sequence: A ∥ B → (B + #133) → C.


Risks / open decisions (core side)

  1. Protection vs. fail-open RLS (highest risk). The pro RLS is open-by-default: any non-boolean restrictedToMembers reads as not restricted (soft-open). Core MUST guarantee the field is only ever a boolean — confirm SchemaProtectionLevel::Core blocks writes at persistence, not just UI. Treat a non-boolean write as a bug, not a soft-open.
  2. Auto-admin bootstrap is purely pro (ADR-037 §6). Keep set_collection_restriction a dumb property write — no local admin grant. Local restriction is inert (no RLS locally); document this. Do not add a "convenience" local bootstrap — it would create a second, divergent path.
  3. No local PersonNode instance. Decided: nothing reads a PersonNode in the free/local journey, so none is seeded (no inert placeholder). The person-only membership check in Task C simply has nothing to point at locally until Pro onboarding creates the first PersonNode — which is correct (a single-user local graph has no members).
  4. No migration/reset code — modify read-default + absent-=false cover legacy; reset is fine.

A separate, deferrable Pro-onboarding issue (pro/frontend) covers PersonNode instantiation + name prompt + Supabase identity bind at the start of the sync journey, plus the always-visible gated "Restrict to members" upgrade CTA (tier-aware via the existing WatchSyncStatus capability probe). Neither has a core backend dependency beyond the property/type existing.

Breakdown produced via senior-architect-reviewer against ADR-037 + the merged cloud-sync.md, grounded in current nodespace-core source. Revised: PersonNode type consolidated into #133; no local placeholder; instantiation deferred to Pro onboarding.

Activity

  1. added a commit that references this issue on Jun 9, 2026
  2. added a commit that references this issue on Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions