Skip to content

feat(Segment Membership): Skip traitless identities when seeding - #8455

Open
matthewelwell wants to merge 3 commits into
mainfrom
feat/seed-skip-traitless
Open

feat(Segment Membership): Skip traitless identities when seeding#8455
matthewelwell wants to merge 3 commits into
mainfrom
feat/seed-skip-traitless

Conversation

@matthewelwell

Copy link
Copy Markdown
Contributor
  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to https://github.com/Flagsmith/edge-api/pull/714

seed_organisation_identities mirrors every identity in an environment, including ones carrying no traits at all. Those can only match a segment by percentage split or is not set, and some environments accumulate them in the millions — one org's were expensive enough that we excluded their environment from the Edge CDC path outright. The edge-api PR above narrows that exclusion to just the traitless records, and this does the same for the backfill, so a seed doesn't load into ClickHouse what CDC is now filtering out.

It also decouples the two: that org's empty identities are being deleted by a long-running script, and without this, seeding them has to wait for it to finish.

The system_traits half of the check keeps cohort members, whose membership is the only thing on their document. Note the seed mapper doesn't read system_traits yet (edge-api's CDC mapper does, since Flagsmith/edge-api#707), so those identities are still mirrored with traits = NULL until that's fixed separately — this change just makes sure they aren't dropped entirely in the meantime.

How did you test this code?

Added test_seed_organisation_identities__traitless_identities__are_not_mirrored, covering an identity with no traits (dropped) and one carrying only a system trait (kept).

Ran tests/unit/segment_membership — 48 passed. The ClickHouse-marked tests were deselected; I don't have a local ClickHouse to run them against.

🤖 Generated with Claude Code

An identity carrying no traits at all can only match a segment by
percentage split or `is not set`, and some environments hold millions of
them. Leave them out of the ClickHouse mirror, matching the Edge CDC
filter that now drops them at the stream.

System traits count as traits here, so cohort members are kept.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@matthewelwell
matthewelwell requested a review from a team as a code owner September 3, 2026 18:04
@matthewelwell
matthewelwell requested review from emyller and removed request for a team September 3, 2026 18:04
@vercel

vercel Bot commented Sep 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated
docs Ignored Ignored Preview Sep 3, 2026 7:08pm UTC
flagsmith-frontend-preview Ignored Ignored Preview Sep 3, 2026 7:08pm UTC
flagsmith-frontend-staging Ignored Ignored Preview Sep 3, 2026 7:08pm UTC

Request Review

@github-actions github-actions Bot added the api Issue related to the REST API label Sep 3, 2026
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 444db4e4-e076-41d3-bd07-ec0ca6aa15bb

📥 Commits

Reviewing files that changed from the base of the PR and between 815cb66 and 63bfe41.

📒 Files selected for processing (1)
  • api/tests/unit/segment_membership/test_unit_segment_membership_tasks.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The identity seeding task excludes identities with neither identity traits nor system traits. It skips empty batches before inserting data into ClickHouse. Unit tests cover traitless identities and identities with cohort membership in system_traits. The events catalogue updates source line references for related telemetry events.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 63bfe

Identity seeding now omits traitless identities while retaining identities needed for cohort membership, with regression coverage for empty batches. No current merge-blocking risk is identified.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the feature New feature or request label Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-8455 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-8455 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-8455 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-8455 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-8455 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-8455 Finished ✅ Results

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 85a2210c-9809-44c8-8865-117e9e467499

📥 Commits

Reviewing files that changed from the base of the PR and between 4a8a84a and 7958188.

📒 Files selected for processing (2)
  • api/segment_membership/tasks.py
  • api/tests/unit/segment_membership/test_unit_segment_membership_tasks.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor
❌ oss · depot-ubuntu-latest-16 — run #20135 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

failed  8 failed
passed  10 passed

Details

stats  18 tests across 12 suites
duration  57.2 seconds
commit  63bfe41
info  📦 Artifacts: View test results and HTML report
🔄 Run: #20135 (attempt 1)

Failed tests

firefox › tests/environment-test.pw.ts › Environment Tests › Environments can be created, renamed, and deleted @oss
firefox › tests/flag-tests.pw.ts › Flag Tests › Feature flags can have tags added and be archived @oss
firefox › tests/initialise-tests.pw.ts › Signup › Create Organisation and Project @oss
firefox › tests/mv-options-tests.pw.ts › Multivariate Options › Repeated saves keep the variant set stable @oss
firefox › tests/mv-options-tests.pw.ts › Multivariate Options › Variants can be added and removed in a single save @oss
firefox › tests/onboarding-tests.pw.ts › Onboarding › New user connects via the single-page onboarding flow @oss
firefox › tests/segment-test.pw.ts › Segment test 1 - Create, update, and manage segments with multivariate flags @oss
firefox › tests/segment-test.pw.ts › Segment test 2 - Test segment priority and overrides @oss

🗂️ Previous results
❌ private-cloud · depot-ubuntu-latest-16 — run #20135 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

Details

stats  0 tests across 0 suites
duration  unknown
commit  63bfe41
info  📦 Artifacts: View test results and HTML report
🔄 Run: #20135 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20126 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  1 minute, 12 seconds
commit  7958188
info  🔄 Run: #20126 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #20126 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  32.7 seconds
commit  7958188
info  🔄 Run: #20126 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #20126 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  45.9 seconds
commit  7958188
info  🔄 Run: #20126 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #20128 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  39.5 seconds
commit  815cb66
info  🔄 Run: #20128 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #20126 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  34.4 seconds
commit  7958188
info  🔄 Run: #20126 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #20128 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  17 passed
skipped  1 skipped

Details

stats  18 tests across 12 suites
duration  1 minute, 4 seconds
commit  815cb66
info  🔄 Run: #20128 (attempt 1)

Skipped tests

firefox › tests/onboarding-tests.pw.ts › Onboarding › New user connects via the single-page onboarding flow @oss

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

19 screenshots compared. See report for details.
View full report

One identity per batch, so the traitless one forms a batch with nothing
left to write, and assert no INSERT is issued with an empty row list.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request docs Documentation updates labels Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant