Repository navigation
feat: person cohorts (dynamic + static) with cohort filters in every insight - #13
Merged
Merged
Conversation
…insight - person_cohorts / cohort_people / cohort_counts tables; /api/v2/cohorts (v1 /api/v1/cohorts stays the acquisition cohort matrix) - dynamic cohorts: nested AND/OR groups of person-property criteria, behavioural criteria (performed event, N times >=/<=/=, stopped, restarted, first time, regularly in M of N periods, with event property filters) and cohort-in-cohort references, each negatable; compiled to SQL UNION/INTERSECT/EXCEPT over the project's known visitors and materialised atomically; cycle detection; deleting a referenced cohort is refused - recalculation on create/update, on demand (/calculate) and every 5 minutes for cohorts older than 30 minutes, claim-based so instances do not collide; member count history - static cohorts: add by visitor id or user id, CSV import, remove, duplicate any cohort as static, create from any insight's actors - members list and CSV export (identity module required) - insights: new `cohort` property filter type (exact / is_not), scoped to the querying project, usable in trends, funnels, retention, stickiness, lifecycle and paths Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46961b2236
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…module for cohort filters, claim lease with recovery, full CSV export
Insight authorization now takes DataNeeds { person, cohorts } instead of a
person-only flag, so every path (insight routes, actors, saved insights,
dashboards, share links) enforces the cohorts module for cohort filters.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
3 tasks done
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.
What and Why
Pulse's "segments" are flat, evaluated in memory on every request, and can't be used in insights. This adds PostHog-style person cohorts:
cohortfilter type that works in every insightStacked on #12 (base
ayush/dashboards-v2); retarget tomainonce the stack below merges.Reference followed: PostHog's
Cohortmodel and cohort filters (posthog/models/cohort/,frontend/src/scenes/cohorts/):type: OR/AND→valuesproperty-group tree,person/behavioral/cohortcriteria withnegationvalues:performed_event,performed_event_multiple,stopped_performing_event,restarted_performing_event,performed_event_first_time,performed_event_regularlycohortproperty filter in insightsChanges
person_cohorts,cohort_peopleandcohort_counts(count history)./api/v2/cohorts:/calculateand/history/people: list, add, remove/people.csvexport and/people/csvimport/duplicate-static/from-actors/api/v1/cohortsacquisition matrix is unchanged.UNION/INTERSECT/EXCEPTover the project's known visitors (sessions ∪ profiles), and membership is swapped atomically.is_calculating) so multiple instances don't collide, and failures are recorded inlast_error.from-actorssaves the people behind any trends, funnels, retention, stickiness, lifecycle or paths data point.{"type": "cohort", "key": "<cohort id>", "operator": "exact" | "is_not"}works in every insight. It checks membership withEXISTS, joined to the cohort's project, so another project's cohort id matches nothing. To support that, the virtual event stream now carriesproject_id.cohortsmodule.identity.from-actorsneeds the same access as the actor endpoints.Reviews and Follow-up
saved_segments.Files Changed
migrations/033_person_cohorts.{up,down}.sqlservices/person_cohorts.rs,routes/cohorts.rs(new)services/insights/{filters,mod}.rs: cohort filter type,project_idon the event streamroutes/insights.rs,routes/mod.rs,services/mod.rs,main.rs(routes and background task)Scope and Non-scope
In scope: person cohorts and cohort filters in insights. Out of scope: flag targeting by cohort, UI, and the excluded LLM/account features.
Validation
I ran this on Postgres 18 with the seeded dataset. Every cohort's membership was compared with independent Python set logic over the raw rows, in 31 checks:
Testing
cargo test: 129 passed, including new tests for tree parsing and validation, set-operation compilation, CSV parsing and project scoping of the cohort filter.Size and Notes
About 1,540 changed lines. Migration 033 only creates tables. Adding
project_idto the virtual event stream is additive, since existing queries select columns by name.🤖 Generated with Claude Code