Skip to content

Rewrite the restrictedToMembers and member_of permission comments as storage contracts - #3389

Merged
mstomar125 merged 1 commit into
mainfrom
issue-3301-storage-contract-comments
Sep 30, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-3301-storage-contract-comments

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3301

Summary

Rewrites the comment above the collection schema's fields in get_core_schemas so it states the two storage contracts that ADR-083 section 4 (proposed) defines, without naming a consumer:

  • restrictedToMembers: stored at properties.collection.restrictedToMembers as a JSON boolean; absent or false means open. Locally it bounds embedding roots and marks the personal AI-chat collection.
  • The permission property on a person's member_of edge: one of admin, modify or readOnly; a content node's membership edge carries none. Core stores it free-form, does not validate it, and reads admin back to find the personal AI-chat collection.

Both sentences that make each a contract ("This path and type are a storage contract ..." and "This path and these values are a storage contract ...") use ADR-083 section 4's wording. The new block names no Pro, RLS, Supabase, tenant or nodespace-sync wording.

The leading comment of test_collection_has_restricted_to_members_field now says its name, bucket and type are the contract and that the test pins them.

This is the first PR to lower a Pro-boundary baseline, so it exercises the ratchet workflow end to end.

Ratchet delta

Before (origin/main a7a1906) and after, from bun run scripts/check-pro-boundary.ts:

marker before after
proWording 282 281
cloudWording 74 72

The block removed one proWording line and two cloudWording lines, and --list proWording, --list cloudWording and --list tenantWording show no line from core_schemas.rs any more. The check exits 0.

Deviations from the issue text

  • Baseline numbers. The issue predicted 314 to 313 and 89 to 87, measured at af8ddb6. Main has moved (other Pro removals landed), so the real numbers are 282 to 281 and 74 to 72. The deltas (1 and 2) are exactly what the issue predicted.
  • Only two baselines lowered. The printed block also offers cloudSyncHooks 4 to 0. That headroom comes from an earlier merged change, not from this block, and the issue's criterion is that only proWording and cloudWording move. I left cloudSyncHooks alone to keep this diff scoped and to avoid a BASELINES line conflict with anything else queued. It is a one-line follow-up for whichever PR is next to touch the ratchet.
  • ADR-083 is not merged. It is docs PR Major Enhancement: Design System Integration with NodeViewer and Precision Cursor Positioning #93 (open). I used its section 4 wording from the PR branch, as authorized. If review changes that wording, this block should follow.
  • Test comment wrapping. The test's leading comment uses the issue's text, wrapped over three lines.

Verification

  • git diff origin/main changes only comment lines in packages/core/src/models/core_schemas.rs, plus two numbers in BASELINES.
  • Checked each local-behavior claim in the new comment against the code: seed_personal_ai_chat_collection_if_needed matches restrictedToMembers and a permission of admin and writes {"permission": "admin"} when seeding; restricted_collection_sql treats a restricted collection as an embedding-root boundary; nothing validates permission.
  • cargo fmt -p nodespace-core --check: clean.
  • cargo clippy -p nodespace-core --all-targets -- -D warnings -D clippy::unused-async: clean.
  • bun run scripts/check-pro-boundary.ts: exit 0. bun run scripts/check-code-references.ts: exit 0.
  • Both contract tests pass unchanged: core_schemas (lib) and scalar_field_type_validation_test:: (integration).
  • bun run test:changed: passed (rust and scripts tiers run; frontend and skill skipped by scope), on the branch, then again after each rebase onto a moved main. The commits that landed in between touch only desktop-app files and BASELINES (proSyncModule, proWording); after the last rebase the proWording conflict was resolved by taking main's value and re-deriving mine from the check output.
  • bun run scripts/check-pro-boundary.ts --changed: 0 hits in both changed files.

No new test: the change is comment-only, and the two tests above already pin the part of the contract core owns.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Review Type: Initial Review

Code Review Summary

Comment-only rewrite of the collection schema block above fields: vec![] in get_core_schemas, the leading comment of test_collection_has_restricted_to_members_field, and two ratchet numbers in BASELINES. The block now states the two storage contracts from ADR-083 section 4 without naming a consumer, and every local-behavior claim I checked against the code is true. The diff is what the issue asked for and nothing more. One merge-ordering note (ADR-083 is still unmerged) and one tiny follow-up, neither blocking.

Reviewed at e89e464 (one commit on top of current origin/main; git status shows ahead 1, behind 0 after a fresh fetch). I did not run cargo or any test command; the two contract tests and clippy are as reported in the PR body.

Requirements Check

Issue #3301 acceptance criteria:

  • Block states both contracts in ADR-083 section 4's wording, gives each field's local meaning, names no consumer. The two contract sentences are word-for-word the ADR's (core_schemas.rs:528-533 "This path and type are a storage contract: ... or store a non-boolean." and :539-541 "This path and these values are a storage contract: ... as modify."). I diffed against the live docs PR Major Enhancement: Design System Integration with NodeViewer and Precision Cursor Positioning #93 branch (decisions/083-...md lines 303 and 311), not only the local copy; the wording is unchanged. Local meaning is given for both (embedding roots and personal AI-chat collection; admin read-back). I grepped the added lines for Pro, RLS, Supabase, tenant, nodespace-sync and #NNNN: no hits (the only match is the +++ b/scripts/check-pro-boundary.ts file header). Only ADR-037, which the old comment already cited, is referenced.
  • --list cloudWording / --list proWording show no line from this block. Ran both (and --list tenantWording); nothing from core_schemas.rs in any of them. --changed reports 0 hits in both changed files. Sanity-checked that the grep is not vacuous: the lists print file paths and line numbers (cloudWording 113 lines, proWording 366).
  • Ran the check, pasted the printed BASELINES, exits 0; only proWording and cloudWording moved, each by the lines dropped. Check exits 0. Diff is cloudWording 74 -> 72 and proWording 294 -> 293; both equal what the check prints (72 / 72, 293 / 293). The deltas match the old block: "the Pro RLS layer" (1 Pro, 1 RLS) plus "the RLS reads directly" (1 RLS) gives Pro -1, cloud -2. cloudSyncHooks is deliberately left at 4 (printed 0); consistent with "only these two move".
  • git diff origin/main changes only comment lines in core_schemas.rs, plus the BASELINES numbers. Filtered all added and removed lines of the Rust diff: every one matches ^[+-]\s*//; zero non-comment lines. The TS diff is exactly the two number changes. 2 files, +21/-7.
  • bun run scripts/check-code-references.ts passes. Ran it: exit 0, issue-number references 71 (baseline 71), doc-path references 0 (baseline 0).
  • [~] Both contract tests pass unchanged. Not re-run (a test run is using the worktree). The test body is untouched by the diff (comment lines only), and the PR body reports core_schemas and scalar_field_type_validation_test:: passing. Nothing in the diff can affect them.

Wording fidelity (ADR-083 section 4)

  • restrictedToMembers: the ADR's proposed sentence is "Stored at properties.collection.restrictedToMembers as a JSON boolean. This path and type are a storage contract: ...". The block folds the first sentence into "restrictedToMembers (ADR-037 opt-in restriction) is stored at ... as a JSON boolean; absent or false means open (organizational). Locally it bounds embedding roots and marks the personal AI-chat collection." The contract sentence that follows is identical. This is the text the issue prescribes and the additions are the "local meaning" the criterion asks for. No drift in meaning.
  • permission: the ADR sentence "A person's member_of edge to a collection carries properties.permission, one of admin, modify or readOnly" is preserved, with "a content node's membership edge carries none" (ADR bullet, line 307) and the free-form / not-validated / admin read-back statements (ADR lines 309-310) spliced between it and the identical contract sentence. Joined with a semicolon instead of a period; same meaning. The Pro daemon's client-side refusal to push a bad value (ADR line 309) is correctly left out, since that names a consumer.

Factual accuracy against the code

  • "Locally it bounds embedding roots": true. restricted_collection_sql (embedding_roots.rs:26-32) is the predicate access_boundary uses (embedding_roots.rs:68) to find the nearest restricted collection governing a node, which is what cuts an embedding root's vector.
  • "marks the personal AI-chat collection": true. seed_personal_ai_chat_collection_if_needed (node_service/mod.rs:1802) creates the collection with {"collection": {"restrictedToMembers": true}} (:1880-1883) and matches an existing one on .and_then(|v| v.as_bool()) == Some(true) (:1820-1826).
  • "a JSON boolean" is what core writes: true. The seed writes a JSON true (:1882), the schema default is json!(false) (core_schemas.rs, the field's default), and the field is field_type: "boolean", so the node API rejects a string. Note the embedding-root SQL is intentionally more lenient (accepts JSON true and the string "true", embedding_roots.rs:26-31); the comment's "do not store a non-boolean" is still the right instruction, because the AI-chat lookup at mod.rs:1820-1826 is strict boolean.
  • "absent or false means open": true of the code. Both readers only treat boolean true (seed) or true / "true" (embedding SQL) as restricted; absent, false and null all fall through to unrestricted.
  • "a content node's membership edge carries none": true as a convention. Core's content-node member_of edges carry order (collection_membership_test.rs:445-486 shows order added by add_to_collection), never permission. Core does not enforce this: the same test stores {"permission": "admin"} on a content node's edge and reads it back. The comment's "does not validate it" covers that.
  • "stores it as a free-form edge property (no schema field) and does not validate it": true. relationship.properties is a plain TEXT JSON column (db/schema.rs:97), relationships: vec![] on the schema says member_of is native, and a grep of packages/ for "permission", readOnly and "modify" finds no validator. The only core readers/writers are mod.rs:1827 (read admin), :1865 and :1891 (write {"permission": "admin"}). The pro_sync.rs hits are a Tauri DTO, not core validation.
  • "it reads admin back to find the personal AI-chat collection": true (mod.rs:1827 edge.get("permission").and_then(|v| v.as_str()) == Some("admin")).
  • Claims about outside layers ("treat any value whose text form is not true as unrestricted", "treat an absent value as modify") cannot be checked from core; they are ADR-083 section 4's statements and this PR faithfully carries them.
  • Test comment: "Its name, bucket and type are a storage contract ...; this test pins them." The test pins name (get_field), type (boolean), protection and default. The "bucket" is pinned by looking the field up on the schema whose id == "collection", which is what determines properties.collection.*. Fair enough for a comment.

Findings

Critical Issues

None.

Suggested Improvements

Nitpicks

  • Nit: cloudSyncHooks is left at 4 while the check prints 0, so the ratchet allows four new cloud-sync hooks to slip in on that marker. Leaving it out of this PR is the right call (scoped to the issue, avoids a BASELINES conflict with anything queued, and the PR body says so), but please make sure someone picks up the one-line follow-up in the next ratchet PR so the headroom does not become permanent.
  • Nit: the second paragraph (the member_of permission contract) sits above fields: vec![, whose only entry is restrictedToMembers. The paragraph says "(no schema field)" and the adjacent relationships: vec![], // member_of is a native edge, not schema-defined backs it up, so a reader will not be misled. No change needed.

Nothing in the comment would lead a core engineer to rename the field, move it out of the collection bucket, or store a string: the "do not" sentence is explicit, the field type is boolean, and the test pins it.

Recommendation: APPROVE. Hold the merge until nodespace-docs#93 (ADR-083) is merged, or re-check the two contract sentences against the merged text first.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment: GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125
mstomar125 force-pushed the issue-3301-storage-contract-comments branch from e89e464 to 6fe6dbd Compare September 30, 2026 11:22
@mstomar125

Copy link
Copy Markdown
Contributor Author

Address Review (round 1)

Review: APPROVE, 0 critical, 1 improvement note, 2 nits.

Triage

  • Will address: none. No code change is warranted by any finding.
  • Skipped, with reasons:
    1. [Improvement] ADR-083 is not merged (docs PR Major Enhancement: Design System Integration with NodeViewer and Precision Cursor Positioning #93 open). No code action. The PR body already discloses it, the two contract sentences match the ADR's proposed section 4 wording word for word (the reviewer re-diffed them against the docs PR branch), and the block cites no unmerged ADR. This is a merge-timing note for the coordinator: hold the merge until the ADR lands, or re-diff the two sentences at merge time. Revisit the local-effect sentences if the ADR's question 6 or ADR-085 removes the AI-chat privacy machinery from core.
    2. Nit: cloudSyncHooks left at 4 while the check prints 0. Out of scope: that headroom came from an earlier merged change, and the issue's criterion is that only proWording and cloudWording move. Revisit in the next ratchet PR (one line).
    3. Nit: the member_of paragraph sits above a fields list holding only restrictedToMembers. No change: "(no schema field)" and the adjacent relationships comment already prevent the misreading.

Rebase after the review

Main moved after the review (a merged change lowered proWording 294 to 282 and proSyncModule 370 to 368), which conflicted with this PR's adjacent BASELINES line. I rebased onto current main (now 6fe6dbd9), took main's check-pro-boundary.ts, and re-derived the two numbers from the check's own output rather than merging by hand: proWording 282 to 281 and cloudWording 74 to 72, the same deltas of 1 and 2.

  • git diff e89e464d 6fe6dbd9 -- packages/core/src/models/core_schemas.rs is empty: the Rust file is byte-identical to the reviewed commit.
  • scripts/check-pro-boundary.ts exits 0; --changed shows 0 hits in both changed files; check-code-references.ts exits 0; cargo fmt -p nodespace-core --check is clean.
  • The PR is MERGEABLE again.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: No finding required a change. The only edit since the review is the mechanical resolution of a BASELINES number conflict, and its values are the ones the check itself prints; the code the reviewer read is unchanged.

🤖 Generated with Claude Code

…storage contracts

The collection schema comment named a Pro consumer and did not say what core
must not change. State the two storage contracts without naming a consumer:
restrictedToMembers is a JSON boolean at properties.collection.restrictedToMembers,
and a person's member_of edge carries a free-form permission of admin, modify
or readOnly. Also note each field's local effect in core.

The test that pins restrictedToMembers now says its name, bucket and type are
the contract. Lower the proWording and cloudWording baselines by the 1 and 2
lines the old block held.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rewrite the restrictedToMembers and member_of permission comments as storage contracts

1 participant