Skip to content

feat: Support $.flags context values in segment conditions - #261

Open
khvn26 wants to merge 4 commits into
perf/local-eval-regressionfrom
feat/flags-context-values
Open

khvn26 wants to merge 4 commits into
perf/local-eval-regressionfrom
feat/flags-context-values

Conversation

@khvn26

@khvn26 khvn26 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Closes #245.

In this PR, we allow local evaluation's get_environment_flags to process segments without identity-specific segment conditions. In other words, if a segment only contains $.flags.* and $.environment.* conditions, it will apply to environment flags.

Lazy evaluation, introduced in #200, is now skipped for environments containing segments with $.flags.* conditions.

@khvn26
khvn26 requested a review from a team as a code owner October 16, 2026 17:18
@khvn26
khvn26 requested review from emyller and removed request for a team October 16, 2026 17:18
@khvn26
khvn26 marked this pull request as draft October 16, 2026 17:19
@khvn26
khvn26 force-pushed the feat/flags-context-values branch from 35891e0 to a029f90 Compare October 19, 2026 10:22
@khvn26
khvn26 changed the base branch from main to perf/local-eval-regression October 19, 2026 10:22
@khvn26
khvn26 force-pushed the feat/flags-context-values branch 2 times, most recently from aa94f73 to 8775019 Compare October 19, 2026 10:31
@khvn26
khvn26 marked this pull request as ready for review October 19, 2026 11:59
Environment flags are now evaluated with segments whose conditions all read
`$.environment` or `$.flags`, as `GET /api/v1/flags/` does since
Flagsmith/flagsmith#8576. Segments reading traits or identity context are
left out.

When segment conditions read `$.flags`, identity flags are evaluated at
once against the full context, as a context trimmed to one feature lacks
the flags it depends on. Otherwise, they are still evaluated lazily.

Closes #245
@khvn26
khvn26 force-pushed the feat/flags-context-values branch from b2d63e6 to f1af8bb Compare October 20, 2026 16:10
`_get_context_reads` and `LocalEvaluation.__init__` both combined reads
through booleans, then built a `_ContextReads` from them. `_ContextReads`
now combines with `|`, from empty defaults.
Renames `_get_context_reads` to `_get_context_reads_from_rules`, and adds
`_get_context_reads_from_segments` for `LocalEvaluation.reads`, as
suggested in review.
…lags

Identity-free segments are only used to evaluate environment flags, at
most once per environment document. They are now filtered there, rather
than eagerly for every environment document.
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.

Support $.flags context values in segment conditions

2 participants