Skip to content

feat(feature-flags): Align rule and target management with API contracts - #1719

Open
stanleyphu wants to merge 13 commits into
mainfrom
codex/auth-7099-rule-management
Open

stanleyphu wants to merge 13 commits into
mainfrom
codex/auth-7099-rule-management

Conversation

@stanleyphu

@stanleyphu stanleyphu commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Why

I hit a 400 while testing rule authoring with the flags app: the SDK sent feature_flag, while the API requires flag_slug. Rule creation, listing, and the convenience helper now accept flagSlug and send the correct field. Target lookup and filtered pagination handle both API contracts: a FlagTarget exposes ruleId; a LegacyFlagTarget exposes value and valueType.

Membership creation sends only rule_id and target_id. The helper retains the created rule and confirmed memberships after a later failure, and existing target aliases remain available.

This stacks on #1717, which removes the v1 polling types, so the API's target object takes the plain FlagTarget name. Retarget to main once #1717 merges.

Release prerequisite: deploy the target membership API contract tested at revision 7a0095af09e7, and enable rule authoring for the affected teams with the legacy target contract off.

Not covered by CI

  • Verified the changed contract tests fail against the previous SDK and pass with this update.
  • Ran the built SDK directly against the local API at 7a0095af09e7, without request translation: rule CRUD and evaluation-order pagination, membership lookup and combined filters, ascending/descending cursor pagination, duplicate/conflicting targets, helper success, partial failure, recovery, and sibling preservation all passed.
  • Checked the flags app with SDK rule authoring: matching user exclusion before organization inclusion produces v1 true and v2 false; reversing the rules changes the live decision to true.
  • Restored the legacy compatibility flag and verified target lookup/listing expose value/valueType without ruleId. Membership-only creation returns 400 in this mode, and the helper reports its retained empty rule.
  • Removed all disposable fixtures and restored the local compatibility override.

Repeat the successful membership check against the deployed API before release.

Proof

The updated SDK sent this request directly to the local API:

POST /flag_rules
{"flag_slug":"sdk-rule-update-1791399585805","target_type":"user","value":false}

HTTP 201
{"object":"flag_rule","id":"flag_rule_01M4BVRT8FQ3N94ZPEVQX31SFZ","position":0,"value":false}

It then sent POST /flag_targets with {"rule_id":"flag_rule_01M4BVRT8FQ3N94ZPEVQX31SFZ","target_id":"user_01KM490ND31XPKGTYFAC9APFJ4"}. The API returned HTTP 201 with membership flag_target_01M4BVRTACYNBCS05B5N3W7Y6W, the same rule_id, and no value/value_type fields. Lookup and filtered listing returned the same membership.

A later missing organization returned 404: CreateRuleWithTargetsError retained rule flag_rule_01M4BVRZBSC0MCY1ASQTC6230Q and its one confirmed membership; the next target was not attempted. Adding that next target to the retained rule succeeded.

Response excerpts omit unchanged fields. These IDs belonged to disposable local fixtures that have been removed.

Fixes AUTH-7099

@linear-code

linear-code Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

AUTH-7099

AUTH-7214

@stanleyphu
stanleyphu marked this pull request as ready for review October 2, 2026 17:32
@stanleyphu
stanleyphu requested review from a team as code owners October 2, 2026 17:32
@stanleyphu
stanleyphu requested a review from tribble October 2, 2026 17:32
@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no actionable new issues remain.

Summary

Adds feature flag rule and membership management using the API’s field names.

  • Callers can manage flag rules and their target memberships through the SDK.
  • The rule helper keeps confirmed memberships when adding a target fails.
  • Target reads keep the response shape returned by the API.

The earlier, unnumbered deployment finding is addressed by stanleyphu’s confirmation that the compatible API is in production. stanleyphu also states that rule authoring requires the legacy target contract to be off. Retaining partial helper progress is intentional so callers can recover.

Review checks covered source code, contract tests, and dependent callers in PR #1721. No tests or live API calls were run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Create rule] --> B{Rule created?}
  B -->|No| C[Return original error]
  B -->|Yes| D[Add next membership]
  D --> E{Request succeeded?}
  E -->|Yes| F{More targets?}
  F -->|Yes| D
  F -->|No| G[Return rule and targets]
  E -->|No| H[Throw CreateRuleWithTargetsError]
  H --> I[Keep rule and confirmed memberships]
Loading

Reviews (4) · Last reviewed commit: "docs: Remove rollout notes from feature ..." · Reviewed by Greptile

Comment thread src/feature-flags/feature-flags.ts Outdated
@stanleyphu stanleyphu changed the title feat(feature-flags): Add rule-first management methods feat(feature-flags): Align rule and target management with API contracts Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

Updated at 79c70669721269c3d45fdd909c54105bcfbbb02b to match the target contracts from workos/workos#75124. Direct live SDK checks against API revision 7a0095af09e7 now pass for membership creation, lookup/listing under both contracts, partial failure and recovery. The PR description retains the deployed-API prerequisite and compatibility gate requirements.

stanleyphu and others added 4 commits October 15, 2026 17:13
BREAKING CHANGE: getFlag() and change-event snapshots now expose v2 rule entries with off_value and rules instead of legacy targets.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@workos-shipyard

Copy link
Copy Markdown

⚓ Shipyard review suggestion

Suggested team: dx, based on recent contributors to the changed files (@gjtorikian, @nicknisi).

Links open Shipyard for confirmation. Choosing a reviewer overrides availability; “Pick for me” skips known absences.
Comment /tag <team> for a team or /tag to infer one. Tag the same team again to reroll.

Shipyard Analysis

⏳ Generating analysis...

⚓ Explore the analysis in depth in Shipyard · 🔄 Re-run analysis

@workos-shipyard
workos-shipyard Bot requested a review from nicknisi October 17, 2026 16:57
@workos-shipyard

Copy link
Copy Markdown

⚓ Review requested from @nicknisi for team dx, requested by @stanleyphu.

Shipyard Analysis

⏳ Generating analysis...

⚓ Explore the analysis in depth in Shipyard · 🔄 Re-run analysis

@stanleyphu
stanleyphu changed the base branch from main to codex/auth-7097-node-rules October 19, 2026 07:21
@stanleyphu
stanleyphu force-pushed the codex/auth-7099-rule-management branch from 79c7066 to c110e5d Compare October 19, 2026 07:21
@stanleyphu

Copy link
Copy Markdown
Contributor Author

@greptileai review

stanleyphu and others added 2 commits October 19, 2026 01:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uator

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@stanleyphu
stanleyphu force-pushed the codex/auth-7099-rule-management branch from c110e5d to 464a215 Compare October 19, 2026 19:41
@stanleyphu

Copy link
Copy Markdown
Contributor Author

@greptileai review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@stanleyphu
stanleyphu force-pushed the codex/auth-7099-rule-management branch from 464a215 to 8e088a8 Compare October 19, 2026 20:04
Base automatically changed from codex/auth-7097-node-rules to main October 19, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants