Skip to content

Generalize get_multi_membership_edges into member_of_edges with caller-supplied filters #3343

Closed

Description

@mstomar125

Summary

Replace SqliteStore::get_multi_membership_edges with SqliteStore::member_of_edges(min_memberships, exclude_member_types), as ADR-083 §4 recommends (proposed; decision 5-B).

After the change, the query describes only the graph. The Pro membership sweep's policy moves to the caller: the threshold of 2 and the exclusion of person members.

Context

  • The query lives in packages/core/src/db/sqlite_store/relationships.rs: doc ~924-937, function ~938-963.
    • It returns (member_id, collection_id) for every member_of edge whose member has more than one member_of edge and is not a person.
    • Its doc talks about the "atomic cloud node insert", the "cloud-sync membership sweep" and "server-side RBAC".
  • Its only test is get_multi_membership_edges_only_multi_membership_nodes in packages/core/src/services/collection_service.rs (~1199-1245). The person exclusion is untested.
  • Its only production caller is nodespaced-pro/src/cloud_sync/orchestrator.rs ~1941 (sync 17f9557).
    • Sync cannot run the SQL itself, because SqliteStore::read() is pub(crate).
    • The query stays in core because it reads core's tables.
    • The change lands in core first. At its pin bump, sync calls member_of_edges(2, &["person"]).

Scope

  • relationships.rs: the method and its doc.
  • collection_service.rs: the existing test and its doc, plus two new tests.

Out of scope

  • The rest of the collection and membership API.
  • Sync's sweep.

Steps

  1. Start up. Follow core CLAUDE.md's startup sequence:
    • EnterWorktree({name: "issue-<N>-member-of-edges"});
    • bun install;
    • the bun run test baseline;
    • gh:assign, then gh:status.
  2. Replace the method with pub async fn member_of_edges(&self, min_memberships: usize, exclude_member_types: &[&str]) -> Result<Vec<(String, String)>>:
    • Keep the GROUP BY in_node HAVING COUNT(*) >= ?1 subquery, bound to min_memberships.max(1).
    • When the slice is non-empty, add AND n.node_type NOT IN (?2, …) with one placeholder per type.
    • Keep the error context neutral, e.g. "Failed to read member_of edges".
  3. Doc. "Every member_of edge, as (member_id, collection_id), whose member node has at least min_memberships member_of edges and whose node_type is not in exclude_member_types. A min_memberships below 1 behaves as 1; an unknown type excludes nothing." Name no caller.
  4. Tests in collection_service.rs. Compare edges as sets, because the order is unspecified.
    • Rename the existing test to member_of_edges_with_threshold_two_skips_single_memberships. Call member_of_edges(2, &[]), and rewrite its doc in graph terms.
    • Add member_of_edges_excludes_listed_member_types. Add the local person (get_local_person) to two collections:
      • with (2, &[]), the person's edges appear;
      • with (2, &["person"]), they are absent, while a content node's edges remain.
    • Add member_of_edges_threshold_below_one_behaves_as_one. (0, &[]) and (1, &[]) return the same set, and it includes a single-membership node's edge.
  5. Grep. git grep -n get_multi_membership_edges -- packages prints nothing.
  6. Ratchet. Run bun run scripts/check-pro-boundary.ts, and set BASELINES to the printed counts. cloudSyncHooks drops.
  7. Finish:
    • run bun run test:changed, then bun run quality:fix, then commit;
    • push to issue-<N>-member-of-edges;
    • open the PR with gh pr create --repo NodeSpaceAI/nodespace-core --base main --head issue-<N>-member-of-edges, then set gh:status "In Review";
    • after approval, run bun run merge <PR#> in the background.

Acceptance criteria

  • The step 4 grep prints nothing.
  • No core doc or identifier here mentions cloud, push, a sweep or RBAC.
  • All three tests pass.
  • member_of_edges(2, &["person"]) returns the same result as get_multi_membership_edges did.
  • bun run scripts/check-pro-boundary.ts exits 0, and BASELINES equals its printed counts.
  • Core builds, all tests pass, and the free app's collections are unchanged.

Tests and verification

  • bun run test:changed
  • .tools/bin/cargo-nextest nextest run -p nodespace-core --lib member_of_edges
  • cargo clippy -p nodespace-core --all-targets -- -D warnings -D clippy::unused-async
  • Mutation checks:
    • drop the exclusion clause, and the exclusion test fails;
    • hard-code > 1, and the threshold test fails.

Dependencies

Risks and rollback

  • Dynamic placeholders. A numbering error fails loudly in the tests.
  • Rollback. Revert the PR.

Plan key: C7.7 (pro-boundary DAG).

🤖 Generated with Claude Code

Activity

  1. self-assigned this
    on Sep 30, 2026
  2. added
    pro-boundary
    on Sep 30, 2026
  3. mstomar125 commented on Sep 30, 2026

    @mstomar125
    ContributorAuthor

    Completed in #3383 (merged). Auto-close did not fire; closing manually.

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

Metadata

Metadata

Assignees

Labels

pro-boundary

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions