Repository navigation
fix(flags): drop flag loads in flight across reset() - #1048
Merged
Merged
Conversation
reset() cleared the flag cache and queued a reload for the new identity, but a /flags request already in flight for the previous identity still wrote its flags into the cache, notified onFeatureFlags listeners and posted didReceiveFeatureFlags when it completed, until the queued reload corrected it. PostHogRemoteConfig now bumps a reset generation in clear() and drops a response, or a queued notification, from an older generation: it doesn't write the cache, reach listeners or post didReceiveFeatureFlags, so it can't be replayed to a late listener either. The queued post-reset reload still runs, and a reloadFeatureFlags callback of the dropped load gets that reload's flags instead, or nil when no reload is queued. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 tasks done
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
posthog-ios Compliance ReportDate: 2026-11-09T23:54:47.388965+00:00
|
| Test | Status | Duration |
|---|---|---|
| Format Validation.Event Has Required Fields | ✅ | 3709ms |
| Format Validation.Event Has Uuid | ✅ | 451ms |
| Format Validation.Event Has Lib Properties | ✅ | 3132ms |
| Format Validation.Distinct Id Is String | ✅ | 2930ms |
| Format Validation.Token Is Present | ✅ | 2922ms |
| Format Validation.Custom Properties Preserved | ✅ | 2919ms |
| Format Validation.Event Has Timestamp | ✅ | 3012ms |
| Format Validation.Non Utc Event Timestamp Is Converted To Utc | ✅ | 2999ms |
| Retry Behavior.Retries On 503 | ✅ | 9209ms |
| Retry Behavior.Does Not Retry On 400 | ✅ | 4986ms |
| Retry Behavior.Does Not Retry On 401 | ✅ | 2560ms |
| Retry Behavior.Respects Retry After Header | ✅ | 7969ms |
| Retry Behavior.Implements Backoff | ✅ | 21845ms |
| Retry Behavior.Retries On 500 | ✅ | 9427ms |
| Retry Behavior.Retries On 502 | ✅ | 9324ms |
| Retry Behavior.Retries On 504 | ✅ | 9372ms |
| Retry Behavior.Max Retries Respected | ❌ | 15542ms |
| Deduplication.Generates Unique Uuids | ✅ | 3325ms |
| Deduplication.Preserves Uuid On Retry | ✅ | 9190ms |
| Deduplication.Preserves Uuid And Timestamp On Retry | ✅ | 16347ms |
| Deduplication.Preserves Uuid And Timestamp On Batch Retry | ✅ | 8016ms |
| Deduplication.No Duplicate Events In Batch | ✅ | 3051ms |
| Deduplication.Different Events Have Different Uuids | ✅ | 2943ms |
| Compression.Sends Gzip When Enabled | ✅ | 2827ms |
| Batch Format.Uses Proper Batch Structure | ✅ | 2875ms |
| Batch Format.Flush With No Events Sends Nothing | ✅ | 297ms |
| Batch Format.Multiple Events Batched Together | ✅ | 3052ms |
| Error Handling.Does Not Retry On 403 | ✅ | 4825ms |
| Error Handling.Does Not Retry On 413 | ✅ | 4704ms |
| Error Handling.Retries On 408 | ✅ | 9269ms |
Failures
retry_behavior.max_retries_respected
Expected 4 requests, got 5
Feature_Flags Tests
✅ 17/17 tests passed
View Details
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ✅ | 3030ms |
| Request Payload.Flags Request Uses V2 Query Param | ✅ | 2866ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ✅ | 2774ms |
| Request Payload.Flags Request Omits Authorization Header | ✅ | 2818ms |
| Request Payload.Token In Flags Body Matches Init | ✅ | 2870ms |
| Request Payload.Groups Round Trip | ✅ | 2868ms |
| Request Payload.Groups Default To Empty Object | ✅ | 2830ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ✅ | 2755ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ✅ | 2872ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ✅ | 2873ms |
| Request Lifecycle.No Flags Request On Init Alone | ✅ | 89ms |
| Request Lifecycle.No Flags Request On Normal Capture | ✅ | 2841ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ✅ | 5366ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ✅ | 2839ms |
| Retry Behavior.Retries Flags On 502 | ✅ | 2909ms |
| Retry Behavior.Retries Flags On 504 | ✅ | 2820ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ✅ | 2967ms |
turnipdabeets
marked this pull request as ready for review
November 9, 2026 21:53
dustinbyrne
approved these changes
Nov 9, 2026
Re-check the reset generation under sessionReplayLock before a /flags response (success or quota-limited) applies its linked-flag decision, so a reset() that lands between the early staleness check and the replay update can't re-enable recording for the new identity with the previous user's flags. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
turnipdabeets
enabled auto-merge (squash)
November 9, 2026 23:36
turnipdabeets
added a commit
that referenced
this pull request
Nov 10, 2026
…cated Brings in #1048 (drop flag loads in flight across reset()). PostHogRemoteConfig.swift and its tests take the 4.0 resolution from #1044 (fix/v4-drop-flag-loads-across-reset), which keeps 4.0's FeatureFlagsLoadResult callback and the removed didReceiveFeatureFlags. PostHog.podspec stays deleted.
This was referenced Nov 10, 2026
6 of 18 tasks
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.
💡 Motivation and Context
sdk-specs requires that a flag load in flight when
reset()orclose()runs never reaches a listener and isn't replayed to one registered later (on-feature-flags, "Loads discarded by reset or close reach no listener", from PostHog/sdk-specs#161). iOS met this forclose()but notreset().reset()cleared the flag cache and queued a reload for the new identity, but the/flagsrequest already in flight for the previous identity had no staleness check. When it completed it wrote the previous user's flags into the cache, notifiedonFeatureFlagslisteners and posteddidReceiveFeatureFlags, until the queued reload replaced them. Listeners and getters briefly saw the previous user's flags, and a listener registered in that window got them replayed.Changes
PostHogRemoteConfigkeeps a reset generation, bumped byclear()(called fromreset()) underfeatureFlagsLock:onFeatureFlagsLoaded, doesn't postdidReceiveFeatureFlags, and so is never stored for replay to a late listener. The check is repeated under the cache lock, so areset()that lands mid-response can't be undone.reset()ran since it was sent.reset()queued still runs. AreloadFeatureFlagscallback of the dropped load gets that reload's flags instead, ornilif no reload is queued (the callback already takes an optional, so there's no API change).close()is unchanged (it already drops these). No public API change; patch changeset added.Merging into 4.0
When
mainis next merged intochore/v4-remove-deprecated, this conflicts inPostHog/PostHogRemoteConfig.swift: 4.0 passes aFeatureFlagsLoadResultto the reload callback (#913) and no longer postsdidReceiveFeatureFlags(#965). Keep the generation checks and adapt the callback to the 4.0 type. With no reload queued, the 4.0 callback should get a failed result (errorsLoading: true) with the cleared flags.💚 How did you test it?
New tests in
PostHogFeatureFlagsTest/TestOnFeatureFlags, each holding the first/flagsresponse until afterreset():reloadFeatureFlagscallback gets the post-reset flags.didReceiveFeatureFlagspost happens while the previous user's flags are cached.With the fix reverted, all three fail (7 issues: the listener, cache, callback and notification all see
previous-user). With the fix:make test filter="'PostHogFeatureFlagsTest'": 79 tests in 14 suites passed.make test filter="'PostHogFeatureFlags|PostHogRemoteConfig|PostHogSDKTest|Survey'": 367 tests in 58 suites passed.make lint: 0 serious violations (same 30 warnings asmain).iOS simulator (iPhone 17, iOS 26.4.1):
Unit tests:
xcodebuild test-without-buildinghung after "unable to connect to com.apple.instruments.deviceservice.lockdown", before any test ran. So the bundle fromxcodebuild build-for-testing -scheme PostHog -destination 'id=<udid>' -derivedDataPath <dd>was run directly in the booted simulator:PostHogFeatureFlagsTestPostHogRemoteConfigTestmain'sPostHogRemoteConfig.swiftwith the new testsExample app:
PostHogExample, changed locally (not committed) and pointed at a local stub server that holds/flagsforprevious-userfor 3 s. It callsidentify("previous-user"), thenreset()0.5 s later, with a listener registered and the flag read every second.mainprevious-user, thennew-usernew-usernew-useronlynew-user📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
PostHogRemoteConfigrather than only at listener delivery, so it never reaches the cache or flag getters either.🤖 Generated with Claude Code