Target feature flags by build channel - #7859
lawrencecchen wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughPostHog analytics now sets an explicit build-channel property before reloading feature flags. ChangesFeature flag initialization
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant PostHogAnalytics
participant PostHogSDK
participant CmuxFeatureFlags
PostHogAnalytics->>PostHogSDK: Set cmux_build_channel
PostHogAnalytics->>PostHogSDK: Reload feature flags
PostHogSDK-->>CmuxFeatureFlags: Deliver feature-flag payload
CmuxFeatureFlags->>CmuxFeatureFlags: Apply loaded flags
Possibly related PRs
🚥 Pre-merge checks | ✅ 24 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (24 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThis PR lets PostHog feature flags target cmux builds by release channel. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (3): Last reviewed commit: "Defer feature flag preload until channel..." | Re-trigger Greptile |
| #expect(PostHogAnalytics.featureFlagEvaluationProperties(buildFlavor: .stable) == [ | ||
| "cmux_build_channel": "stable", | ||
| ]) |
There was a problem hiding this comment.
When this test compares featureFlagEvaluationProperties(...) to a dictionary literal, the left side is [String: Any]. Swift only provides dictionary equality when the value type is Equatable, so this can fail the test target at compile time instead of checking the channel value.
| #expect(PostHogAnalytics.featureFlagEvaluationProperties(buildFlavor: .stable) == [ | |
| "cmux_build_channel": "stable", | |
| ]) | |
| let stableProperties = PostHogAnalytics.featureFlagEvaluationProperties(buildFlavor: .stable) | |
| #expect(stableProperties["cmux_build_channel"] as? String == "stable") |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| // CmuxFeatureFlags installs its observer during app launch, before | ||
| // analytics initialization reaches this point. Reload only after the | ||
| // build-channel evaluation context is ready. | ||
| PostHogSDK.shared.reloadFeatureFlags() |
There was a problem hiding this comment.
App launch starts analytics asynchronously, then starts CmuxFeatureFlags, whose startup path also calls reloadFeatureFlags(). That earlier reload can run before this work-queue block installs cmux_build_channel, so the first flag notification can apply Stable/default targeting to a Nightly app until this later reload corrects it.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: afc602544f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // CmuxFeatureFlags installs its observer during app launch, before | ||
| // analytics initialization reaches this point. Reload only after the | ||
| // build-channel evaluation context is ready. | ||
| PostHogSDK.shared.reloadFeatureFlags() |
There was a problem hiding this comment.
Avoid racing the channel-scoped flag reload
When CmuxFeatureFlags.shared.start() runs immediately after PostHogAnalytics.shared.startIfNeeded() in AppDelegate, analytics setup is still asynchronous on the utility queue, and CmuxFeatureFlags.start() still calls PostHogSDK.shared.reloadFeatureFlags() before this new cmux_build_channel property is installed. If that reload reaches the SDK after setup has created remoteConfig but before setPersonPropertiesForFlags runs, the manual reload added here can be ignored while the earlier request is loading, leaving channel-targeted PostHog rules evaluated without the channel for that launch. Defer/remove the earlier reload or start feature flags only after this property has been installed.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 87080c7. Configure here.
| PostHogSDK.shared.reloadFeatureFlags() | ||
| // PostHogAnalytics reloads after installing its build-channel | ||
| // evaluation context. Starting a request here would race that setup | ||
| // during launch and could cache a result for the wrong channel. |
There was a problem hiding this comment.
Observer misses initial flag reload
Medium Severity
Removing the startup reloadFeatureFlags() from CmuxFeatureFlags.start() leaves the only reload on PostHog’s async work queue, while AppDelegate still enqueues analytics before registering the didReceiveFeatureFlags observer. A fast reload (e.g. cached flags) can finish first, so applyLoadedFlags() never runs and CmuxFeatureFlags can keep defaults for the whole session.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 87080c7. Configure here.


Adds
cmux_build_channelto PostHog feature-flag evaluation asstable,nightly, ordev.PostHog rules can now target Nightly independently from the production app. The SDK reloads flags only after the channel property is installed.
Test:
./scripts/lint-feature-flags.py.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Note
Medium Risk
Changes launch-time feature-flag fetch ordering and evaluation context; a mistake could cache wrong flag values per channel at startup, affecting gated release UI.
Overview
PostHog feature-flag evaluation now receives
cmux_build_channel(stable,nightly, ordev) viasetPersonPropertiesForFlags, so dashboard rules can roll flags out to one desktop release channel without affecting the others.Startup ordering is tightened: SDK
preloadFeatureFlagsis off,CmuxFeatureFlags.start()no longer callsreloadFeatureFlags(that could run before the channel property was set), andPostHogAnalyticssets the channel property then performs a singlereloadFeatureFlagsafter analytics setup. A smallfeatureFlagEvaluationProperties(buildFlavor:)helper documents the PostHog person property; tests assert the three channel values.Reviewed by Cursor Bugbot for commit 87080c7. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Enables build-channel targeting for
PostHogfeature flags so rules can targetstable,nightly, ordevwithout affecting other channels. Defers flag loading until the build-channel context is set to avoid wrong early evaluations.New Features
cmux_build_channelfor flag evaluation viafeatureFlagEvaluationProperties(buildFlavor:).config.preloadFeatureFlags = false) and reloads flags only after setting the channel;CmuxFeatureFlags.start()no longer triggers an earlyPostHogSDK.reloadFeatureFlags().Migration
PostHog, target thecmux_build_channelperson property withnightly,stable, ordevto scope rollouts by desktop release channel.Written for commit 87080c7. Summary will update on new commits.
Summary by CodeRabbit