Skip to content

fix(flags): honor cohort not_in - #431

Merged
marandaneto merged 6 commits into
PostHog:mainfrom
o-mid:fix/flag-cohort-not-in
Nov 11, 2026
Merged

marandaneto merged 6 commits into
PostHog:mainfrom
o-mid:fix/flag-cohort-not-in

Conversation

@o-mid

@o-mid o-mid commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

  • Local cohort evaluation treated operator: "not_in" as membership, so a person in the cohort still matched the release condition. Apply the inverse only after membership resolves successfully.
  • Preserve errors for unavailable membership rather than turning them into a local match. Regression cases cover a missing cohort definition and a missing required person property.
  • in and an omitted cohort operator remain membership checks. Legacy release conditions continue to ignore the negation field; negative operators express negative conditions.

No public API changes. Unsupported-group composition is outside this PR's scope.

💚 How did you test it?

  • go test -v -count=1 -timeout=90s -run '^TestCohortNotInAndConditionNegation$' .
  • Controlled mutation checks: each new error case fails when its error path is temporarily changed to return a local match. Restored production code passes; no production changes remain from these checks.
  • go build ./...
  • go vet ./...
  • go test -race -count=1 -timeout=5m ./...
  • git diff --check and Go formatting checks.

Only root-module tests changed in the review follow-up; nested-module checks were not rerun locally.

📝 Checklist

  • All commits are signed and verified by GitHub.
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No documentation update is needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Existing patch changeset included: .changeset/flag-cohort-not-in.md.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

The original implementation is by @o-mid. Pi, directed by @marandaneto and using Go, Git, and GitHub CLI, added the two unresolved-not_in regression cases and corrected the PR metadata. This review follow-up makes no production behavior changes. Human review is required.

@o-mid
o-mid requested a review from a team as a code owner November 9, 2026 13:59
@signed-commit-check

signed-commit-check Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Commit signatures resolved

GitHub now verifies every commit signature in this PR. No further action is needed.

@o-mid
o-mid force-pushed the fix/flag-cohort-not-in branch from f3cdf81 to 328dc79 Compare November 9, 2026 17:37
Local evaluation treated a cohort not_in filter as membership, and a
release condition with negation set still required the property to match.
@o-mid
o-mid force-pushed the fix/flag-cohort-not-in branch from 328dc79 to d7a19d6 Compare November 9, 2026 17:37

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated advisory code review. Reproduced blocking findings from the requested review.

Comment thread featureflags.go Resolved
@marandaneto
marandaneto requested a review from a team November 10, 2026 12:35
An invalid regex is a non-match for both regex and not_regex. Condition negation was complementing that failure and enabling the flag for every value.
@o-mid

o-mid commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@marandaneto invalid regex stays a non-match under negation, so a bad pattern no longer turns the condition on. Can you review again?

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up on the cross-SDK comparison: release-condition negation changes legacy backend semantics.

Comment thread featureflags.go Resolved
@marandaneto
marandaneto requested a review from a team November 10, 2026 13:41
@marandaneto

Copy link
Copy Markdown
Member

also missing changeset

Cohort not_in still excludes members. A negation field on a legacy release condition is left unused, matching the backend.
@o-mid

o-mid commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@marandaneto the changeset is in .changeset/flag-cohort-not-in.md.

@o-mid

o-mid commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@marandaneto

Unrelated to this PR, so feel free to ignore it here.

I applied for the Technical Support Engineer role today. The careers form returned an application-limit error, so I sent the application to careers@posthog.com instead.

Working through the mobile SDKs over the last two months, I kept running into the same kinds of gaps: surveys behaving differently on Flutter, iOS and Android, opt-out not fully stopping replay or integrations, and beforeSend not covering every capture path on Flutter web. I have ideas for dealing with the patterns behind those and not only the individual bugs, and I'd like the chance to work on them properly.

Would you be open to a short chat about it, or to pointing me to the right person on the talent team? Happy to do it async, wherever suits you.

ioannisj
ioannisj previously approved these changes Nov 11, 2026

@ioannisj ioannisj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 An AI agent wrote this on behalf of @ioannisj.

Nothing here blocks the merge. The title and description still mention release-condition negation, and not_in has no test for a cohort that can't be resolved locally, both nits.

Comment thread featureflags.go Resolved
Comment thread feature_flags_cohorts_test.go Resolved
@ioannisj
ioannisj requested a review from marandaneto November 11, 2026 09:18
@marandaneto marandaneto self-assigned this Nov 11, 2026
@marandaneto marandaneto changed the title fix(flags): honor cohort not_in and condition negation fix(flags): honor cohort not_in Nov 11, 2026
@ioannisj
ioannisj dismissed their stale review November 11, 2026 09:57

Manoel is looking into possible changes

@marandaneto

Copy link
Copy Markdown
Member

Why the release-condition negation change was removed

We removed that part to preserve compatibility with the legacy backend semantics, independently of the unsupported-cohort-group discussion.

In the legacy filters.groups format, the backend does not apply a release-condition filter's negation field. Negative comparisons use operators such as is_not and not_in. For example, country exact CA, negation: true still matches CA on the backend; applying that field locally would instead exclude CA and include other countries, making local and remote evaluation disagree.

This is separate from negation inside dynamic-cohort leaves, which remains supported and was not removed. The cohort not_in fix also remains: it negates definitive membership only, preserving errors when membership cannot be resolved locally.

The release-condition behavior was removed in af480b0 following the earlier review. The subsequent title, description, and changeset edits simply reflect that narrower scope. Adding release-condition negation support would need a separate coordinated backend/spec change, rather than a Go-only behavior change bundled into this bug fix.

@marandaneto
marandaneto merged commit 1b62fef into PostHog:main Nov 11, 2026
36 checks passed
@marandaneto

Copy link
Copy Markdown
Member

@marandaneto

Unrelated to this PR, so feel free to ignore it here.

I applied for the Technical Support Engineer role today. The careers form returned an application-limit error, so I sent the application to careers@posthog.com instead.

Working through the mobile SDKs over the last two months, I kept running into the same kinds of gaps: surveys behaving differently on Flutter, iOS and Android, opt-out not fully stopping replay or integrations, and beforeSend not covering every capture path on Flutter web. I have ideas for dealing with the patterns behind those and not only the individual bugs, and I'd like the chance to work on them properly.

Would you be open to a short chat about it, or to pointing me to the right person on the talent team? Happy to do it async, wherever suits you.

we've received your application and we'll be in contact if its a good fit.
thank you for the issues/PRs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants