Skip to content

fix: queue membership count refreshes for cohort segments - #8438

Merged
gagantrivedi merged 4 commits into
mainfrom
fix/cohort-membership-refresh
Sep 2, 2026
Merged

fix: queue membership count refreshes for cohort segments#8438
gagantrivedi merged 4 commits into
mainfrom
fix/cohort-membership-refresh

Conversation

@gagantrivedi

@gagantrivedi gagantrivedi commented Sep 2, 2026

Copy link
Copy Markdown
Member
  • 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

Closes #8268.

Cohort segments never showed membership counts: cohort creation bypasses the segment serializer (where refreshes are queued), and cohort membership is the one way segment members change without a segment or identity edit.

  • create_cohort queues a membership refresh after creating its managed segment.
  • Membership deltas deliberately do not queue refreshes — the recount is an expensive per-project ClickHouse scan and delta volume is unbounded; changed counts pick up on the recurring refresh cycle.

The blocking prerequisite in #8268 (system traits missing from the ClickHouse identities mirror) shipped in edge-api and was verified end to end on staging: cohort member add/remove now moves the segment's membership count.

How did you test this code?

Unit tests for both call sites. The pipeline (CDC → ClickHouse → count) verified manually against staging.

@vercel

vercel Bot commented Sep 2, 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 2, 2026 7:06am UTC
2 Skipped Deployments
Project Deployment Actions Updated
flagsmith-frontend-preview Ignored Ignored Preview Sep 2, 2026 7:06am UTC
flagsmith-frontend-staging Ignored Ignored Preview Sep 2, 2026 7:06am UTC

Request Review

@gagantrivedi
gagantrivedi requested review from a team as code owners September 2, 2026 06:59
@gagantrivedi
gagantrivedi requested review from matthewelwell and removed request for a team September 2, 2026 06:59
@github-actions github-actions Bot added api Issue related to the REST API docs Documentation updates fix and removed docs Documentation updates labels Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

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

@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

create_cohort now queues a project membership refresh when CLICKHOUSE_ENABLED is active. A unit test verifies this call. The observability catalogue updates source line references for seven cohort events.

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

Merge Risk: 🟡 Moderate · up to db42c

Cohort creation now schedules an asynchronous membership-count refresh, but the refresh can run before the cohort and managed segment are committed, leaving counts stale or incomplete. The PR should defer scheduling until transaction commit before merging.


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 fix and removed fix docs Documentation updates labels Sep 2, 2026
@github-actions github-actions Bot added the docs Documentation updates label Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20051 (attempt 1)

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  1 minute, 2 seconds
commit  5177aef
info  🔄 Run: #20051 (attempt 1)

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

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

passed  4 passed

Details

stats  4 tests across 4 suites
duration  57.7 seconds
commit  5177aef
info  🔄 Run: #20051 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  40.9 seconds
commit  db42c76
info  🔄 Run: #20052 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.8 seconds
commit  db42c76
info  🔄 Run: #20052 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  40.5 seconds
commit  5177aef
info  🔄 Run: #20051 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  40.5 seconds
commit  5177aef
info  🔄 Run: #20051 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  56.5 seconds
commit  27883eb
info  🔄 Run: #20049 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  38.3 seconds
commit  27883eb
info  🔄 Run: #20049 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  24.9 seconds
commit  27883eb
info  🔄 Run: #20049 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  48.3 seconds
commit  b3f0136
info  🔄 Run: #20050 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.7 seconds
commit  b3f0136
info  🔄 Run: #20050 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  34.2 seconds
commit  27883eb
info  🔄 Run: #20049 (attempt 1)

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

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

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (894bfa4) to head (db42c76).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8438   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files        1621     1621           
  Lines       66118    66128   +10     
=======================================
+ Hits        65334    65344   +10     
  Misses        784      784           

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

@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: 9cfb2695-c676-4a49-9ee4-ce25278aa705

📥 Commits

Reviewing files that changed from the base of the PR and between 76da16c and db42c76.

📒 Files selected for processing (3)
  • api/cohorts/services.py
  • api/tests/unit/cohorts/test_services.py
  • docs/docs/deployment-self-hosting/observability/_events-catalogue.md

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

Comment thread api/cohorts/services.py
@gagantrivedi
gagantrivedi merged commit 37b5bdf into main Sep 2, 2026
34 checks passed
@gagantrivedi
gagantrivedi deleted the fix/cohort-membership-refresh branch September 2, 2026 08:25
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 docs Documentation updates fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cohort-managed segments never get membership counts queued

2 participants