Skip to content

feat: Evaluate flags that depend on other flags - #44

Merged
emyller merged 6 commits into
mainfrom
feat/sdk-11-flag-dependency
Nov 2, 2026
Merged

emyller merged 6 commits into
mainfrom
feat/sdk-11-flag-dependency

Conversation

@emyller

@emyller emyller commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

The Rust engine ignores segments that target flags by other flags, so the Rust SDK and edge-proxy-rs serve different flags than Flagsmith.

Closes SDK-11. Tested by engine-test-data v3.12.1.

Changes

  • Flags can depend on other flags being enabled, or having a given value or variant, including chains of dependencies.
  • Flags that depend on themselves report a circular dependency error.
  • Flag results report the variant served, and whether a flag has any targeting.
  • Environment flags can be evaluated without segments that need an identity.

🤖 Generated with Claude Code

Closes #40

emyller and others added 3 commits October 30, 2026 15:57
serde_json_path keeps parsed paths private, while jsonpath-rust exposes them,
so conditions can tell which flag a path reads.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Segment conditions can read another flag's `enabled`, `value` or `variant`
through `$.flags.<feature>`, as in flagsmith-engine. Flags in a dependency
cycle get `ERROR; code=CIRCULAR_DEPENDENCY`.

Also, as engine-test-data v3.12.1 expects:
- Flag results report the selected multivariate variant.
- Untargeted flags report `STATIC`, and targeted ones left at their default `DEFAULT`.
- Segments evaluate in context order, which also breaks override priority ties.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Environment flags can't resolve segments that need an identity, so
`remove_identity_from_context` keeps only those reading the environment or
other flags, as Flagsmith does for `/api/v1/flags`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@emyller
emyller requested a review from a team as a code owner October 30, 2026 20:11
@emyller
emyller requested review from khvn26 and removed request for a team October 30, 2026 20:11
@linear-code

linear-code Bot commented Oct 30, 2026

Copy link
Copy Markdown

SDK-11

@khvn26

khvn26 commented Oct 30, 2026

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

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: 0b8b3f3c-ea83-4d1b-9663-d765307c39df
Recent 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: 4a2e73d4-ecea-4e94-aba6-fccee4627cb1
Commits

Reviewing files that changed from the base of the PR and between f083e82 and 0552139.

Files selected for processing: 11
  • .gitmodules
  • Cargo.toml
  • src/engine.rs
  • src/engine_eval/context.rs
  • src/engine_eval/mappers.rs
  • src/engine_eval/mod.rs
  • src/engine_eval/result.rs
  • src/engine_eval/segment_evaluator.rs
  • tests/engine_eval_test.rs
  • tests/engine_tests/engine-test-data
  • tests/mappers_test.rs

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 preserves segment insertion order and supports removing identity data while filtering segments by their rule conditions. Segment conditions can resolve referenced flags lazily, with cycle tracking and cached results. The engine selects segment overrides by priority, assigns fallback reasons to untargeted or targeted features, and uses resolved dependency flags in evaluation results. Flag results now include an optional selected variant key. The test data submodule reference and evaluation test deserialisation were also updated.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: Moderate · previous review 05521

Resolve cyclic-evaluation performance and incorrect targeting results before merging, populate selected variant keys, and declare the public API changes as breaking.

- [ ] 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.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Nitpick comments: 1
tests/mappers_test.rs: 1

344-348: Trivial · Maintainability & Code Quality · Quick win

Add an end-to-end assertion for retained flag paths.

The new cases only assert that remove_identity_from_context(&context) retains the segment. They do not evaluate $.flags.banner.enabled or assert a selected banner override. A regression in flag-path resolution or override selection can therefore pass these tests.

Additional comments: 1
src/engine_eval/segment_evaluator.rs-262-272: 1

262-272: Minor · Potential issue · Poor tradeoff

Unverified finding
We couldn't verify this from the code. It is shown for review, not as a verified issue.

get_segment_override evaluates even weaker overrides after finding a winner, so a self-referencing condition in a weaker segment can mark the feature cyclic although an independent, higher-priority override already wins.

A can receive a circular-dependency error, and the other flag cannot target on A, despite the independently determined winning value.

This can occur when: Feature A has a matching priority-1 override and a later priority-2 segment whose condition reads $.flags.A.enabled; another flag reads A during evaluation.


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: 4a2e73d4-ecea-4e94-aba6-fccee4627cb1
Commits

Reviewing files that changed from the base of the PR and between f083e82 and 0552139.

Files selected for processing: 11
  • .gitmodules
  • Cargo.toml
  • src/engine.rs
  • src/engine_eval/context.rs
  • src/engine_eval/mappers.rs
  • src/engine_eval/mod.rs
  • src/engine_eval/result.rs
  • src/engine_eval/segment_evaluator.rs
  • tests/engine_eval_test.rs
  • tests/engine_tests/engine-test-data
  • tests/mappers_test.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread src/engine_eval/context.rs Resolved
Comment thread src/engine_eval/mappers.rs Resolved
Comment thread src/engine_eval/result.rs Resolved
Comment thread src/engine_eval/segment_evaluator.rs Resolved
Comment thread src/engine.rs Resolved
emyller and others added 3 commits October 30, 2026 18:53
Read JSONPaths made of member names only, such as `$.identity.identifier`
or `$.flags.<feature>.enabled`, straight from the context, without
serialising it or evaluating JSONPath. Other paths are still evaluated
by jsonpath-rust.

Reuse the segment matches memoised while resolving flag dependencies when
evaluating segments, so segments read through a dependency are evaluated
once. Memoise only once a condition has read a flag.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
emyller added a commit to Flagsmith/flagsmith-rust-client that referenced this pull request Nov 2, 2026
Flagsmith/flagsmith-rust-flag-engine#44 @ c261f544

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@emyller
emyller merged commit e8b5eeb into main Nov 2, 2026
2 checks passed
@emyller
emyller deleted the feat/sdk-11-flag-dependency branch November 2, 2026 16:20
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