Skip to content

fix: fetch flags only when storage holds another identity's flags - #95

Draft
Zaimwa9 wants to merge 7 commits into
mainfrom
fix/identity-scoped-flag-lookup
Draft

Zaimwa9 wants to merge 7 commits into
mainfrom
fix/identity-scoped-flag-lookup

Conversation

@Zaimwa9

@Zaimwa9 Zaimwa9 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Follow-up to #94. Based on feat/experimentation; retarget to main once that merges.

The client now remembers which identity the stored flags were fetched for (null for environment flags, reset() and a fresh process). Lookups that take a user fetch from the API only when that identity differs from the stored one, and read storage otherwise. An explicit reload still wins.

  • getExperimentFlag(user:) no longer hits /identities on every call; same identity as the last fetch is served from storage, a different identity is fetched. Exposures keep the guarantee from feat: surface experiment metadata on flags and add event tracking #94: never attributed against another identity's assignment.
  • hasFeatureFlag, isFeatureFlagEnabled and getFeatureFlagValue share the same rule through _getFlagByName. Previously a user different from the last fetch silently returned the previous identity's flags from storage; now it fetches once. Same identity or no user: unchanged, no request.

Behaviour change to the three existing methods only on the path that returned the wrong identity's flags.

How did you test this code?

flutter analyze clean, flutter test 165 passing. New cases: same identity makes no request; environment flags overwriting storage trigger a fetch for the cached identity; hasFeatureFlag with a switched identity fetches once and then reads storage.

🤖 Generated with Claude Code

Base automatically changed from feat/experimentation to main September 21, 2026 12: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.

1 participant