Skip to content

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

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

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

Conversation

@matthewelwell

@matthewelwell matthewelwell commented Sep 3, 2026

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

Ignores empty1 identities when seeding identity data for segment membership purposes.

This comes with a slight compromise in that percentage split segments and segments containing only 'Is not set' operators may report inaccurate counts, but is an accepted compromise in order to reduce the amount of data in ClickHouse for now.

1 an empty identity is an identity with identity_traits == [] and system_traits == []

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).

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.

Project Deployment Actions Updated
docs Ready Ready Preview Sep 8, 2026 5:31pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
flagsmith-frontend-preview Ignored Ignored Preview Sep 8, 2026 5:31pm UTC
flagsmith-frontend-staging Ignored Ignored Preview Sep 8, 2026 5:31pm 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 StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 808fa5c9-5a2f-4b70-930d-ef7b5bce3f6a

📥 Commits

Reviewing files that changed from the base of the PR and between d8f71e0 and dfdace5.

📒 Files selected for processing (2)
  • api/segment_membership/tasks.py
  • docs/docs/deployment-self-hosting/observability/_events-catalogue.md

Included review availability: Your plan provides up to 8 included reviews per hour; 6 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 dfdac

Identity seeding now omits traitless identities while preserving identities with system traits, preventing unnecessary ClickHouse mirror rows without affecting cohort membership. The change is ready to merge.


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-api:pr-8455 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-8455 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud: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
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20302 (attempt 2)

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  1 minute, 3 seconds
commit  7e385ca
info  🔄 Run: #20302 (attempt 2)

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

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

failed  2 failed

Details

stats  2 tests across 2 suites
duration  1 minute, 9 seconds
commit  7e385ca
info  📦 Artifacts: View test results and HTML report
🔄 Run: #20302 (attempt 1)

Failed tests

firefox › tests/environment-permission-test.pw.ts › Environment Permission Tests › Environment-level permissions control access to features, identities, and segments @enterprise
firefox › tests/project-permission-test.pw.ts › Project Permission Tests › Project-level permissions control access to features, environments, audit logs, and segments @enterprise

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  48.2 seconds
commit  7e385ca
info  🔄 Run: #20302 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  39.6 seconds
commit  7e385ca
info  🔄 Run: #20302 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.4 seconds
commit  7e385ca
info  🔄 Run: #20302 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20298 (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, 1 second
commit  5c26f9d
info  🔄 Run: #20298 (attempt 1)

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

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  35 seconds
commit  5c26f9d
info  🔄 Run: #20298 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  35.1 seconds
commit  057d54b
info  🔄 Run: #20299 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  40.4 seconds
commit  5c26f9d
info  🔄 Run: #20298 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  47.4 seconds
commit  5c26f9d
info  🔄 Run: #20298 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  48.8 seconds
commit  f29aea5
info  🔄 Run: #20275 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  39 seconds
commit  f29aea5
info  🔄 Run: #20275 (attempt 1)

@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

@emyller emyller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

I'm pretty sure you do. ClickHouse related tests seem to fail.

Also, a couple comments.

Comment thread api/segment_membership/tasks.py Outdated
Comment thread api/segment_membership/tasks.py Outdated
Minor code refactor for readability
@github-actions github-actions Bot added feature New feature or request and removed docs Documentation updates labels Sep 8, 2026
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Sep 8, 2026
@matthewelwell

matthewelwell commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

I'm pretty sure you do. ClickHouse related tests seem to fail.

Also, a couple comments.

Thanks for the review (and the slop tolerance!)

I've fixed the test, and actioned the comments. I'll be honest, I'm still not 100% confident on the compromise, but I think it's the right decision.

Given the implementation here though (where we're skipping empty identities for all environments), we might want to update the CDC side to only send non-empty identities for all environments too? What do you think?

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.82%. Comparing base (be14dc7) to head (7e385ca).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #8455    +/-   ##
========================================
  Coverage   98.81%   98.82%            
========================================
  Files        1621     1622     +1     
  Lines       66300    66726   +426     
========================================
+ Hits        65515    65941   +426     
  Misses        785      785            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@emyller emyller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code looks like what we need, but I'd suggest another anti-slop pass for the sake of our better understanding of this decision, and why we made it, in the future.

Comment thread api/tests/unit/segment_membership/test_unit_segment_membership_tasks.py Outdated
Comment thread api/segment_membership/tasks.py Outdated
Co-authored-by: Evandro Myller <22429+emyller@users.noreply.github.com>
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Sep 8, 2026
@emyller

emyller commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Given the implementation here though (where we're skipping empty identities for all environments), we might want to update the CDC side to only send non-empty identities for all environments too? What do you think?

If I understand all this correctly: this PR caters for historical identities, while https://github.com/Flagsmith/edge-api/pull/714 caters for live identities, so yes, I guess they should go together.

@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request docs Documentation updates labels Sep 8, 2026
@matthewelwell

Copy link
Copy Markdown
Contributor Author

If I understand all this correctly: this PR caters for historical identities, while Flagsmith/edge-api#714 caters for live identities, so yes, I guess they should go together.

I agree. I've added this PR stacked on top of Flagsmith/edge-api#714 which adds support for system_traits, and makes the filter generic to all environments.

@emyller emyller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewing the other pull request led me to think we're potentially missing on an opportunity to apply the filter at DDB query-level, and save on resources/cost/time.

Given we're already dragging this and the above is a late finding, I'm ready to approve as to unblock the goal, but would love a follow up.

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.

2 participants