Repository navigation
feat(cohorts): add version and sweep tables to cohort_membership - #89795
Merged
trunk-io[bot] merged 4 commits intoAug 28, 2026
Conversation
Contributor
🤖 CI report✅ Trunk lane — non-backend laneThis PR is assigned to the non-backend lane. It does not run backend Python tests and may merge in parallel with PRs in other lanes. |
matheus-vb
force-pushed
the
matheus-vb/cohort-membership-sweep-schema
branch
from
August 27, 2026 13:44
9e80916 to
cf830c4
Compare
haacked
approved these changes
Aug 27, 2026
haacked
left a comment
Contributor
There was a problem hiding this comment.
Nice, the lock_timeout and CONCURRENTLY handling are right. A few schema suggestions inline, mostly things that get expensive once these tables have rows.
matheus-vb
force-pushed
the
matheus-vb/cohort-membership-sweep-schema
branch
from
August 27, 2026 17:35
cf830c4 to
9db4b4b
Compare
matheus-vb
force-pushed
the
matheus-vb/cohort-membership-sweep-schema
branch
from
August 27, 2026 19:56
7421354 to
99ae613
Compare
The consumer only upserts, so a person who stops matching an edited cohort keeps in_cohort = true forever. Sweeping those rows needs a version column and per-run sweep bookkeeping tables. `version` is nullable with no default: the DDL is catalog-only and NULL reads as older than anything stamped. Must land before the consumer that writes it.
matheus-vb
force-pushed
the
matheus-vb/cohort-membership-sweep-schema
branch
from
August 28, 2026 13:21
1560d7e to
7be5ca9
Compare
|
This pull request was merged into |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Someone who stops matching an edited cohort keeps an
in_cohort = truerow forever, so feature flags still treat them as a member.Deleting those rows needs a way to tell a stale row from a current one, and
cohort_membershiphas no version column.This PR adds only the schema. The consumer and sweeper that use it are the next PR in the stack.
Part of #88014.
Changes
versionholds the producer's monotonic stamp, the same value ClickHouse already orders this data on.lock_timeoutbounds how long the DDL can park readers behind its lock.cohort_membership_sweepsrecords which reconcile run has certified a cohort, including when it turned ready and which pod holds its sweep claim.cohort_membership_consumer_progressrecords how far the consumer applied each partition, keyed by broker cluster so offsets survive a topic moving clusters without lying.(team_id, cohort_id, version)lets the sweep page through one cohort and stop early. It buildsCONCURRENTLYin its own no-transaction migration file, so the build never blocks the consumer's writes.Ships ahead of the code so the schema is live before the sweep flag ever flips. The next PR gates all new writes behind that flag.
How did you test this code?
Applied all three migrations against a local
test_behavioral_cohortsdatabase withrust/bin/migrate-entry behavioral-cohorts, then inspected the resulting schema.No tests here. The next PR in the stack exercises these tables.
👉 Stay up-to-date with PostHog coding conventions for a smoother review.
Automatic notifications
Docs update
None.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Authored with Claude Code (Opus) from a design document for issue #88014. Review fixes applied with Claude Code (Fable).
Skills invoked:
/implement-plan,/writing-pr-descriptions.Split out of a single branch so the migrations land on their own.
ci-migrations-service-separation-checkrejects a PR that touchesrust/behavioral_cohorts_migrations/*.sqltogether withnodejs/**, and the deploy order wants the schema first regardless.