Skip to content

Enforce root-only content membership for member_of edges (store-level, ADR-059 §2) - #1768

Merged
mstomar125 merged 1 commit into
mainfrom
issue-1742-store-membership-guard
Jul 28, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-1742-store-membership-guard

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

What

Enforces root-only content membership for member_of edges (ADR-059 §2): a content node may be a member of a collection only when it is a root node (no has_child parent). collection nodes (nesting) and person nodes (grantee membership, ADR-037 §4) are exempt.

The rule is enforced at the store level so every write path is covered by construction — CLI, graph import, playbook add_relationship, and the sync-apply cold-sweep — rather than by a per-path check that a future path could miss.

How

A new SqliteStore::assert_root_only_membership(member_ids) runs before all three member_of INSERT sites:

  • add_to_collection (single, auto-order)
  • bulk_add_to_collections (the path the sync-apply cold-sweep and daemon import call directly)
  • create_generic_relationship when its rel_type is member_of — reached when a caller supplies an explicit order (NodeService::create_relationship's non-auto-order fork, playbook add_relationship, CLI relationship create --edge-data)

The bulk check is a single chunked IN (...) query (node type + parent presence in one round trip), so the performance-sensitive cold-sweep path stays one query, not 2×N point lookups. Interior nodes are rejected with an actionable, node-naming error (member_of_not_root: content node '<id>' …).

Acceptance criteria (issue #1742)

Tests

Two store-level tests: test_root_only_content_membership_is_enforced (root ✓, interior ✗ via both add_to_collection and create_generic_relationship, person/collection exemptions, restricted-task-in-open-project end-to-end) and test_bulk_root_only_membership_is_enforced (all-root batch applies; a batch with one interior node is refused — cold-sweep parity). Full core lib suite: 975 passed / 0 failed.

Review

Two independent adversarial reviews. The first caught a real High-severity bypass — create_generic_relationship was an unguarded third member_of writer reachable by adding one order key — which is now fixed and covered by a test. A focused second pass confirmed the fix is complete (exactly three member_of writers, all guarded) and introduces no false positives.

Closes #1742

…sites

A content node may hold a member_of edge only when it is a root node (no
has_child parent); collection and person nodes are exempt (collection nesting;
grantee membership per ADR-037 §4). Add assert_root_only_membership to
SqliteStore and call it at all three member_of write sites — add_to_collection,
bulk_add_to_collections, and create_generic_relationship (which carries
member_of when an explicit order is supplied) — so every write path is gated
without a per-path check: CLI, graph import, playbook add_relationship, and the
sync-apply cold-sweep. The bulk validation is one chunked query to keep the
cold-sweep path a single round trip. Interior nodes are rejected with an
actionable, node-naming error.

Closes #1742

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE

Store-level enforcement verified through two independent adversarial reviews.

  • Review 1 caught a real High-severity bypass: create_generic_relationship was a third, param-bound (?4) member_of writer reachable via NodeService::create_relationship's explicit-order fork (and playbook add_relationship / CLI relationship create --edge-data). Fixed at the store choke point + covered by a test that drives exactly that path.
  • Review 2 (focused) confirmed CONFIRMED SOUND: exhaustive sweep shows exactly three member_of writers, all now guarded; the guard checks the member (in_node) with the correct root definition; no false positives; the exemptions (collection nesting, person grantee membership) hold; tests are non-tautological.

Full core lib suite 975/975; clippy clean; pre-push gate (test:all + daemon build + e2e) green. Author=reviewer=mstomar125 self-approval per merge policy.

@mstomar125
mstomar125 merged commit 8f13db5 into main Jul 28, 2026
2 checks passed
@mstomar125
mstomar125 deleted the issue-1742-store-membership-guard branch July 28, 2026 09:52
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.

Enforce root-only content membership for member_of edges as a store-aware relationship validation

1 participant