Skip to content

feat(Segment Membership): Seed identities on Beta opt-in#7899

Draft
khvn26 wants to merge 11 commits into
mainfrom
feat/segment-membership-opt-in-seed
Draft

feat(Segment Membership): Seed identities on Beta opt-in#7899
khvn26 wants to merge 11 commits into
mainfrom
feat/segment-membership-opt-in-seed

Conversation

@khvn26

@khvn26 khvn26 commented Jun 27, 2026

Copy link
Copy Markdown
Member

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

Closes #7471.

In this PR, we convert backfill_identities_to_clickhouse to a seed backfill expected to run once per org.

  • seed_organisation_identities(org_id) — on-demand one-shot seed for one org. Stamps inserted_at at scan start so a CDC write landing mid-scan wins ReplacingMergeTree dedup.
  • reconcile_segment_membership_seeds (hourly) — fires the seed once per allowed org, tracked by SegmentMembershipSeed model.
  • refresh_all_segment_counts every 6 hours.
  • Django admin action to force a re-seed (clears SegmentMembershipSeed for a given org).

All tasks that run the expensive ClickHouse queries are debounced.

Review complexity: 2/5.

How did you test this code?

Added new tests and modified existing where needed; will test extensively in staging.

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

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

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Jun 27, 2026 8:56pm
flagsmith-frontend-preview Ignored Ignored Preview Jun 27, 2026 8:56pm
flagsmith-frontend-staging Ignored Ignored Preview Jun 27, 2026 8:56pm

Request Review

@github-actions github-actions Bot added api Issue related to the REST API feature New feature or request labels Jun 27, 2026
khvn26

This comment was marked as outdated.

khvn26 and others added 2 commits June 27, 2026 17:55
Run seed tests against live ClickHouse with a mocked Dynamo source,
inline the pending-task check, assert the whole skip event, use the
ClickHouseIdentityRow type, and replace the management command with a
Django admin re-seed action that clears the seed marker.

beep boop
Claude-Session: https://claude.ai/code/session_01EgZ5iHpDASZzCapiHRxHLB
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
Comment thread api/tests/unit/segment_membership/test_unit_segment_membership_admin.py Outdated
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
Comment thread api/tests/unit/segment_membership/test_unit_segment_membership_tasks.py Outdated
Comment thread api/tests/unit/segment_membership/test_unit_segment_membership_tasks.py Outdated
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
…t-in

Replace the daily all-org backfill with an on-demand
seed_organisation_identities(organisation_id) task and a lightweight
reconcile_segment_membership_seeds tick that fires it once per opted-in
org, tracked by a SegmentMembershipSeed marker. Seeded rows are versioned
at scan start so a CDC write landing mid-scan wins ReplacingMergeTree
dedup.

Keep a count-refresh safety-net as a separate recurring
refresh_all_segment_counts task (cadence via
SEGMENT_MEMBERSHIP_REFRESH_INTERVAL_HOURS, default 6) so cached counts
track CDC identity churn between segment edits. All refresh enqueues -
edit-triggered, seed fan-out, and the recurring sweep - route through
enqueue_membership_refresh, the single flag and debounce gate, so a
project never has duplicate refreshes queued.

Add a Django admin action to force a re-seed by clearing the marker.

beep boop
Claude-Session: https://claude.ai/code/session_01EgZ5iHpDASZzCapiHRxHLB
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 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 Jun 27, 2026
@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.62%. Comparing base (c153c3f) to head (33cb498).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7899    +/-   ##
========================================
  Coverage   98.62%   98.62%            
========================================
  Files        1487     1490     +3     
  Lines       58493    58637   +144     
========================================
+ Hits        57687    57831   +144     
  Misses        806      806            

☔ 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 added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Jun 27, 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.

Retire backfill_identities_to_clickhouse task

1 participant