Skip to content

feat(cohorts): expose sync state and allow updating the managed segment - #8386

Merged
Zaimwa9 merged 9 commits into
mainfrom
feat/cohort-resync
Aug 28, 2026
Merged

feat(cohorts): expose sync state and allow updating the managed segment#8386
Zaimwa9 merged 9 commits into
mainfrom
feat/cohort-resync

Conversation

@Zaimwa9

@Zaimwa9 Zaimwa9 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • 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

Backend support for the CSV cohort detail view:

  • Cohort retrieve now returns membership_counts (applied, pending_add, pending_remove) so the dashboard can derive sync status and progress.
  • PATCH on a cohort updates the managed segment's name and description. PUT is not exposed.
  • New Cohort.last_synced_at, stamped on every CSV sync.

How did you test this code?

Unit tests for the new counts, update permissions and the last_synced_at stamp. Manually QA'd with the stacked dashboard branch (feat/cohort-resync-frontend).

@Zaimwa9
Zaimwa9 requested a review from a team as a code owner August 26, 2026 13:17
@Zaimwa9
Zaimwa9 requested review from gagantrivedi and matthewelwell and removed request for a team August 26, 2026 13:17
@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview Aug 28, 2026 7:52am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ignored Ignored Preview Aug 28, 2026 7:52am
flagsmith-frontend-staging Ignored Ignored Preview Aug 28, 2026 7:52am

Request Review

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

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Review 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: Pro Plus

Run ID: 4910aa3d-1d01-4bba-9b92-6790f7a86da3

📥 Commits

Reviewing files that changed from the base of the PR and between b60aee0 and bc766a5.

📒 Files selected for processing (1)
  • api/tests/unit/cohorts/test_views.py

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


📝 Walkthrough

Walkthrough

The cohort model now stores an optional last_synced_at timestamp. CSV synchronisation updates this timestamp with the cohort version. Cohort responses now include membership counts for applied, pending-add, and pending-remove memberships. Cohorts support authorised partial updates for managed segment names, descriptions, and metadata. OpenAPI schemas, migrations, event references, and view tests were updated.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🔵 Low · up to bc766

The PR adds cohort synchronization state and allows updating the managed segment. It is mergeable with explicit owner awareness because synchronization timestamps may advance before downstream membership application completes, combined updates may partially persist on failure, and concurrent creation may still produce duplicate active source cohorts.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

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 Aug 26, 2026
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

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

@Zaimwa9

Zaimwa9 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c13fdc1e-9773-40da-a188-8f929dfc71eb

📥 Commits

Reviewing files that changed from the base of the PR and between 2fc223a and c30addb.

📒 Files selected for processing (8)
  • api/cohorts/migrations/0004_cohort_last_synced_at.py
  • api/cohorts/models.py
  • api/cohorts/serializers.py
  • api/cohorts/services.py
  • api/cohorts/views.py
  • api/tests/unit/cohorts/test_views.py
  • docs/docs/deployment-self-hosting/observability/_events-catalogue.md
  • openapi.yaml

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

Comment thread api/cohorts/serializers.py
Comment thread api/cohorts/serializers.py
Comment thread api/cohorts/serializers.py
Comment thread api/cohorts/serializers.py Outdated
@themis-blindfold

Copy link
Copy Markdown
Contributor

⚖️ Themis review: 🟠 Fix before merge

TL;DR: The new sync-state response makes cohort list requests issue an additional membership aggregate for every cohort, and the new PATCH contract accepts metadata but silently ignores it. CI reports a failing pre-commit.ci check; CodeQL and the completed static-analysis checks passed. Local targeted tests could not start because a pinned Git dependency could not be fetched.

Area Score
🎯 Correctness 2/5
🧪 Test coverage 3/5
📐 Code quality 2/5
🚀 Product impact 3/5

🟠 Majors

📝 Walkthrough
  • Cohort serialization - adds sync timestamps and per-state membership counts to cohort responses.
  • Cohort updates - enables PATCH for the managed segment name and description while retaining existing cohort permissions.
  • Schema and API contract - adds the nullable timestamp migration and publishes the expanded response and PATCH schemas.
🧪 How to verify
  1. Create several cohorts with memberships, request the cohort list, and assert the query count stays bounded rather than growing per cohort.
  2. PATCH a cohort with metadata plus a name or description, then verify the managed segment metadata changes; alternatively verify unsupported metadata is rejected with 400.
  3. Upload a CSV and verify last_synced_at is set and the three returned counts match persisted membership states after the worker drains them.
  4. Run cd api && uv run pytest tests/unit/cohorts/test_views.py -q.
    Automate: Add a list query-count regression test and a PATCH-metadata regression test.

Product take: Sync progress and inline cohort editing are a solid dashboard improvement, but list performance and a silently ineffective documented input would undermine that experience at scale.

🧭 Assumptions & unverified claims

No unverified assumptions or claims.

A little cohort status goes a long way—once it stops counting one cohort at a time · reviewed at c30addb

@Zaimwa9
Zaimwa9 force-pushed the feat/cohort-resync branch from c30addb to a5f02fe Compare August 26, 2026 13:49
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request docs Documentation updates labels Aug 26, 2026

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: de270ccb-8280-40d8-8f50-ea2dd8c9a723

📥 Commits

Reviewing files that changed from the base of the PR and between c30addb and a5f02fe.

📒 Files selected for processing (6)
  • api/cohorts/migrations/0005_cohort_last_synced_at.py
  • api/cohorts/models.py
  • api/cohorts/serializers.py
  • api/cohorts/services.py
  • docs/docs/deployment-self-hosting/observability/_events-catalogue.md
  • openapi.yaml

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

Comment thread api/cohorts/models.py
Comment thread openapi.yaml
@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (0f0e09a) to head (94c8051).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8386   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files        1620     1621    +1     
  Lines       66018    66102   +84     
=======================================
+ Hits        65234    65318   +84     
  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.

@github-actions

github-actions Bot commented Aug 26, 2026

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

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  45.1 seconds
commit  94c8051
info  🔄 Run: #19903 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  32.9 seconds
commit  94c8051
info  🔄 Run: #19903 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  44.9 seconds
commit  94c8051
info  🔄 Run: #19903 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  38 seconds
commit  94c8051
info  🔄 Run: #19903 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 9 seconds
commit  7cf092c
info  🔄 Run: #19889 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  38.2 seconds
commit  7cf092c
info  🔄 Run: #19889 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  39.9 seconds
commit  7cf092c
info  🔄 Run: #19889 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  36.5 seconds
commit  7cf092c
info  🔄 Run: #19889 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  36 seconds
commit  1dcbb18
info  🔄 Run: #19887 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  37.7 seconds
commit  1dcbb18
info  🔄 Run: #19887 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #19887 (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  1dcbb18
info  🔄 Run: #19887 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.9 seconds
commit  1dcbb18
info  🔄 Run: #19887 (attempt 1)

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

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

@github-actions github-actions Bot added docs Documentation updates and removed feature New feature or request labels Aug 27, 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 Aug 27, 2026
@Zaimwa9
Zaimwa9 force-pushed the feat/cohort-resync branch from 1dcbb18 to 7cf092c Compare August 27, 2026 14:10
@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 Aug 27, 2026
@Zaimwa9

Zaimwa9 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

@themis-blindfold

Copy link
Copy Markdown
Contributor

⚖️ Themis review: ✅ Ship it

The cohort detail and list responses now expose synchronisation progress without an N+1 query path, and PATCH preserves the managed-segment and metadata semantics. No new actionable defects found. CI was still running at review time; completed CodeQL, pre-commit, documentation, and preview checks succeeded, with no completed failures.

Area Score
🎯 Correctness 5/5
🧪 Test coverage 4/5
📐 Code quality 5/5
🚀 Product impact 4/5

⚖️ Acknowledged

  • List membership counts used one query per cohort — thread resolved by @Zaimwa9
  • PATCH metadata was accepted but discarded — thread resolved by @Zaimwa9
📝 Walkthrough
  • Cohort API - adds synchronisation timestamp and state counts to list and detail responses.
  • Managed segment updates - enables permission-protected PATCH for the cohort-owned name, description, and metadata.
  • CSV synchronisation - records the successful sync timestamp alongside the version increment.
  • API contract - publishes the new response fields and PATCH operation in OpenAPI.
🧪 How to verify
  1. Run uv run pytest tests/unit/cohorts/test_views.py from api/.
  2. Create memberships in each state and GET both the cohort list and detail endpoints; confirm all three counts.
  3. PATCH a cohort with name, description, and metadata, then retrieve its managed segment to confirm the persisted values.
  4. Upload a valid CSV and confirm last_synced_at is populated and membership deltas progress to applied.
    Automate: keep the focused cohort view tests in the required API test suite.

Product take: Solid dashboard-enabling improvement: users can see cohort sync progress and correct cohort labels without leaving the cohort flow.

🧭 Assumptions & unverified claims
  • The focused pytest suite could not be run because the sandbox could not download the pinned psycopg2-binary dependency.

The cohorts can now report their whereabouts without sending the database on a scavenger hunt · reviewed at 7cf092c

@Zaimwa9
Zaimwa9 force-pushed the feat/cohort-resync branch from 7cf092c to 94c8051 Compare August 28, 2026 07:52
@github-actions github-actions Bot added the docs Documentation updates label Aug 28, 2026
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request docs Documentation updates labels Aug 28, 2026
@Zaimwa9
Zaimwa9 merged commit bbc4bd1 into main Aug 28, 2026
35 checks passed
@Zaimwa9
Zaimwa9 deleted the feat/cohort-resync branch August 28, 2026 11:11
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