Skip to content

fix: send the push unregister DELETE even after opt-out (#746) - #759

Merged
dmarchuk merged 5 commits into
mainfrom
fix/push-unregister-optout-746
Aug 11, 2026
Merged

dmarchuk merged 5 commits into
mainfrom
fix/push-unregister-optout-746

Conversation

@dmarchuk

@dmarchuk dmarchuk commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Opting out did not stop Workflows push. unregister deferred on guard isAllowedProvider() (false while opted out) and re-checked it after the async identity-token mint. The normal opt-out flow — unregisterPushNotificationToken() then optOut() — parked the DELETE: the persisted intent kept deferring on every retry while opted out. The server-side subscription stayed active for the whole opted-out period, so Workflows kept delivering to a device that opted out (#746).

Change

Split the cleanup gate from the send gate. Added an isEnabledProvider (SDK enabled, ignoring opt-out) and gated the unregister DELETE on it, instead of isAllowedProvider (enabled and not opted out). A DELETE removes data, so opt-out must block registration and sends but not cleanup. The register and send paths keep isAllowedProvider.

How did you test this code?

  • New test PostHogPushOptOutReproTest: registers a token, parks the unregister's identity mint, flips opt-out mid-flight via the logout path (unregisterCurrentToken), then releases the mint. Asserts the DELETE reaches the mock server. Fails on the pre-fix code (reproduces the bug), passes with the fix.
  • Split the existing unregisterGuarded test into "disabled, no DELETE" and "opted out, DELETE still sent". These run in CI on test-ios-simulator.
  • Real-device E2E on a physical iPhone against a local stack. Registered a token, then ran the opt-out flow (unregisterPushNotificationToken() then optOut()) with the identity mint delayed to force the race. The DELETE reached the backend (200). Rebuilt with the pre-fix isAllowedProvider guard and the same flow sent no DELETE. The fix is what stops the strand.

Not in this PR

#746 also reports that opting back in does not refetch the APNs token or re-register. That half is fixed separately in #760.

Note

Draft. Directed by @dmarchuk; implemented and verified locally by Claude while @ioannisj is out.

@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

posthog-ios Compliance Report

Date: 2026-08-10 19:58:39 UTC
Duration: 222141ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

✅ 29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 3064ms
Format Validation.Event Has Uuid ✅ 507ms
Format Validation.Event Has Lib Properties ✅ 2888ms
Format Validation.Distinct Id Is String ✅ 2923ms
Format Validation.Token Is Present ✅ 346ms
Format Validation.Custom Properties Preserved ✅ 2867ms
Format Validation.Event Has Timestamp ✅ 2986ms
Retry Behavior.Retries On 503 ✅ 5510ms
Retry Behavior.Does Not Retry On 400 ✅ 4823ms
Retry Behavior.Does Not Retry On 401 ✅ 4913ms
Retry Behavior.Respects Retry After Header ✅ 7972ms
Retry Behavior.Implements Backoff ✅ 21775ms
Retry Behavior.Retries On 500 ✅ 9289ms
Retry Behavior.Retries On 502 ✅ 9311ms
Retry Behavior.Retries On 504 ✅ 5382ms
Retry Behavior.Max Retries Respected ✅ 21722ms
Deduplication.Generates Unique Uuids ✅ 3001ms
Deduplication.Preserves Uuid On Retry ✅ 9378ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 16330ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 8155ms
Deduplication.No Duplicate Events In Batch ✅ 2978ms
Deduplication.Different Events Have Different Uuids ✅ 2969ms
Compression.Sends Gzip When Enabled ✅ 3138ms
Batch Format.Uses Proper Batch Structure ✅ 2734ms
Batch Format.Flush With No Events Sends Nothing ✅ 236ms
Batch Format.Multiple Events Batched Together ✅ 2888ms
Error Handling.Does Not Retry On 403 ✅ 2486ms
Error Handling.Does Not Retry On 413 ✅ 4674ms
Error Handling.Retries On 408 ✅ 9254ms

Feature_Flags Tests

✅ 16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 2844ms
Request Payload.Flags Request Uses V2 Query Param ✅ 2846ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 2947ms
Request Payload.Flags Request Omits Authorization Header ✅ 2832ms
Request Payload.Token In Flags Body Matches Init ✅ 3019ms
Request Payload.Groups Round Trip ✅ 2847ms
Request Payload.Groups Default To Empty Object ✅ 2894ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It ✅ 2835ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 2753ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 2778ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 2738ms
Request Lifecycle.No Flags Request On Init Alone ✅ 77ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 2902ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 5732ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 2893ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 3126ms

@dmarchuk
dmarchuk marked this pull request as ready for review August 10, 2026 16:16
@dmarchuk
dmarchuk requested a review from a team as a code owner August 10, 2026 16:16
@greptile-apps

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
### Issue 1
PostHogTests/PostHogPushOptOutReproTest.swift:13
**Regression test missing from Xcode target**

The new regression suite is absent from the Xcode test target’s Sources phase, so `test-ios-simulator` and local Xcode test runs silently omit it. Add this file to the `PostHogTests` target so the advertised iOS simulator coverage executes.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix(push): add missing isEnabledProvider..." | Re-trigger Greptile

@marandaneto
marandaneto requested a review from a team August 10, 2026 18:51
@dmarchuk
dmarchuk merged commit ad199d2 into main Aug 11, 2026
46 checks passed
@dmarchuk
dmarchuk deleted the fix/push-unregister-optout-746 branch August 11, 2026 10:08
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.

2 participants