feat: Evaluate custom targets in the feature flags runtime client - #1674
Open
stanleyphu wants to merge 2 commits into
Open
feat: Evaluate custom targets in the feature flags runtime client#1674stanleyphu wants to merge 2 commits into
stanleyphu wants to merge 2 commits into
Conversation
Contributor
Greptile SummaryThe PR extends local feature-flag evaluation to support typed built-in and custom target contexts while retaining legacy context support.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
|
Contributor
Author
|
/devin review |
Contributor
- Classify context shape by value shape, not key presence: unset keys and scalar extras on a legacy context no longer trip hybrid rejection - Normalize the context once per getAllFlags call so an invalid context warns once, not once per flag - Drop the incorrect claim that hybrid contexts fail to compile
| users: FlagTarget[]; | ||
| organizations: FlagTarget[]; | ||
| /** Absent until the API's custom-targets rollout flag is enabled. */ | ||
| custom_targets?: FlagCustomTarget[]; |
Contributor
There was a problem hiding this comment.
💭 I wonder if it makes sense to roll this out only after custom-targets rollout is enabled to avoid the optional state for custom_targets?
Contributor
Author
There was a problem hiding this comment.
The plan is to have the flag enabled when this is released, but I think we'll still need to keep this optional to avoid things breaking if we have to disable the flag for any reason?
Deborah-Digges
approved these changes
Aug 13, 2026
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.
Summary
Teaches the feature flags runtime client to evaluate the
targets.custom_targetscollection that the API now includes in theGET /sdk/feature-flagspoll payload behind thefeature-flags-custom-targetsrollout flag (workos/workos#68135). This is stage 4 of the Custom Targeting Hilltop rollout plan: ship the runtime contract before typed target management or docs.Typed evaluation context
isEnabled/getAllFlagsnow accept the Hilltop's direct target-type context map alongside the existing legacy shape:Per the Hilltop's pre-commitments:
TypedEvaluationContext's index signature makes any key acceptable to the union). Shape detection is by value, not key presence: unset keys and scalar extra fields on a legacy context are ignored, preserving today's behavior for callers passing wider objects.Evaluation semantics aligned with the Hilltop
enabled: falseis treated as not present (falls through to the flag default) instead of forcing the flag off. This field value is reserved for future disabled overrides, per the Hilltop's Forward compatibility for disabled overrides. The API only ever writesenabled: truetoday, so this is not an observable behavior change — but it does replace the previous user-over-organization short-circuit, which only mattered forenabled: falserows that cannot exist.Change detection
hasEntryChangednow also diffscustom_targets, so a poll cycle where only a custom rule changed emits thechangeevent.Compatibility
targets.custom_targetsis optional in the payload types: polls against servers with the rollout flag off (or older servers) behave exactly as before.Test plan
npx jest src/feature-flags— 93 tests passing, including new coverage for: exact custom matches, built-in types via the typed form,enabled: falsetreated as absent (including the default-true proof), hybrid-context rejection, unset-key and scalar-extra-field handling, once-per-call warnings in getAllFlags, invalid type/ID warnings, malformed context safety, and a change event fired when only custom targets differ.npm run build(tsdown + attw + publint) andnpx eslint src/feature-flagsclean.feature-flags-custom-targetsrollout flag enabled, add a custom rule in the dashboard, and confirmisEnabled(slug, { <type>: { id } })flips accordingly.🤖 Generated with Claude Code