You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: Evaluate flags that depend on other flags in local evaluation - #314
Local evaluation now serves flags whose segments depend on other flags, matching flagsmith-engine 11.1.1.
Closes SDK-10. Tested by engine-test-data v3.12.1, and by sdk-spec's local evaluation scenarios once #310 bumps the spec to v0.7.0.
Changes
Segment conditions can read other flags through $.flags.<feature>.enabled, .value and .variant, including chains of dependencies. A flag caught in a cycle serves its environment default, with the reason ERROR; code=CIRCULAR_DEPENDENCY.
Segments are evaluated without an identity. getEnvironmentFlags leaves out segments that need one (traits or identity), as the Flagsmith API does.
Flag results report the variant they were evaluated to.
Flags that no segment overrides now have the reason STATIC instead of DEFAULT.
npm run generate-engine-types works again, and the context types now include flags.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
Walkthrough
The evaluation context now supports evaluated flag results. Local evaluation filters environment segments and resolves flag dependencies during segment checks. Feature results include variant information and distinguish static targeting from defaults for features with segment overrides. The segment evaluator API now checks one supplied segment. The type-generation script and engine test-data reference are updated. The SDK spec adds a client factory with local evaluation enabled. The benchmark workflow separates build and run targets and uses configured runner and mode values.
The changes are mergeable with bounded follow-up: confirm the benchmark mode is configured or restore its fallback, and strengthen the two targeted test assertions. No production flag-evaluation failure was established.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
⚠️2 benchmarks with a significant change ran on different hardware
Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Note
Follow-up findings are listed below so you can review them separately from inline comments.
Follow-up (1)
Minor (1)
Minor · Avoid copying the key array for each override. · index.ts:126-129
flagsmith-engine/index.ts:126-129 Minor · Performance & Scalability · Quick win
Avoid copying the key array for each override.
The index getter creates a new array for every override. For k segments that override one feature, this costs about k²/2 element copies. The index is rebuilt on each evaluation that reads $.flags. Append to the existing array instead.
Add a test for identity-less segment matching on $.environment.key.
The new isContextInSegment tests all build their context from baseContext, which always has an identity. No test checks a segment whose only condition is $.environment.key against a context without an identity. The current code matches such a segment, so the gap affects regression coverage, not current behaviour. Add a case where identity is omitted and the segment rule compares $.environment.key, and assert true.
Add a test for a configured segment override that does not match.
No test under tests/engine asserts TARGETING_REASONS.DEFAULT. This change replaces the only such assertion, at engine.test.ts:42, with STATIC. A feature with a segment override that the identity does not match returns DEFAULT. A regression to STATIC would pass every reason assertion. Add a test for that case that asserts DEFAULT.
Additional comments: 1
flagsmith-engine/index.ts-52-54: 1
52-54: Minor · Potential issue · Quick win
Unverified finding
We couldn't verify this from the code. It is shown for review, not as a verified issue.
For a cyclic flag, getEvaluationResult changes only the reason of the already evaluated result. A separate, valid segment override can therefore leave its value in place despite the stated environment-default-on-cycle behavior.
The returned A is enabled with reason ERROR; code=CIRCULAR_DEPENDENCY rather than disabled at its environment default.
This can occur when: Flag A has a self-dependent segment that triggers cycle detection and a second, independently matching segment that enables A, while A's environment default is disabled.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: a30e27ed-1e75-477d-8a0e-978101a1cf8a
Commits
Reviewing files that changed from the base of the PR and between c386862 and 9a5c115.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
Give the mv_feature option a distinct key in the fixture and assert that key.
The option in tests/sdk/data/environment.json sets value and key to bar. The variant.key assertion at tests/engine/unit/mappers.test.ts:107 therefore also passes if the mapper copies value into key. Setting a different key in the fixture makes the assertion detect that regression. The value assertion at line 108 stays bar.
Assert the evaluated variant key for a keyed multivariate winner.
The multivariate evaluation test at tests/engine/unit/engine.test.ts:343-366 defines its variants without key. It asserts only flags['Multivariate Feature'].value. No engine unit test asserts variant on an evaluated flag. A keyed winner therefore has no unit-level check on the returned variant key.
Add a key to the winning option in that test and assert that the evaluated flag's variant equals that key. This covers the path where the winning option's key is returned.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
Run CodSpeed on the runner and in the mode set by the CODSPEED_RUNS_ON and CODSPEED_MODE organisation variables.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Assert the omitted segment in the environment-evaluation test.
The test at tests/engine/unit/mappers.test.ts:282 checks only that context.segments is defined. An empty object, or a result that keeps the identity-dependent segment, also passes. Add an assertion that segment '1' is absent in environment-evaluation mode.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
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
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.
Local evaluation now serves flags whose segments depend on other flags, matching flagsmith-engine 11.1.1.
Closes SDK-10. Tested by engine-test-data v3.12.1, and by sdk-spec's local evaluation scenarios once #310 bumps the spec to v0.7.0.
Changes
$.flags.<feature>.enabled,.valueand.variant, including chains of dependencies. A flag caught in a cycle serves its environment default, with the reasonERROR; code=CIRCULAR_DEPENDENCY.getEnvironmentFlagsleaves out segments that need one (traits or identity), as the Flagsmith API does.variantthey were evaluated to.STATICinstead ofDEFAULT.npm run generate-engine-typesworks again, and the context types now includeflags.🤖 Generated with Claude Code
Closes #292