Skip to content

fix: send the push unregister DELETE even after opt-out (#675) - #688

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

fix: send the push unregister DELETE even after opt-out (#675)#688
dmarchuk merged 4 commits into
mainfrom
fix/push-unregister-optout-675

Conversation

@dmarchuk

@dmarchuk dmarchuk commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Problem

Opting out did not stop Workflows push. unregisterPushNotificationToken() resolves before the DELETE runs, and performUnregister began with if (closed || config.optOut) return. The normal opt-out flow — unregisterPushNotificationToken() then setOptOut(true) — let opt-out flip config.optOut before the executor ran the unregister, so the DELETE silently parked. The server-side subscription stayed active for the whole opted-out period and Workflows kept delivering to a device that opted out (#675).

Change

performUnregister no longer gates on config.optOut, only on closed. A DELETE removes data rather than collecting it, so opt-out must block registration and sends but not cleanup. The register and send paths keep their config.optOut guards unchanged.

How did you test this code?

  • New unit test opt-out during an in-flight unregister strands the DELETE (#675): registers a token, blocks the manager's single executor thread, queues unregisterCurrent() behind it, flips config.optOut before it runs, then releases. Asserts a DELETE reaches the mock server. Fails on the pre-fix code (reproduces the bug), passes with the fix.
  • Updated the existing opted-out unregister test to assert the DELETE is sent, not skipped.
  • Full PostHogPushSubscriptionManagerTest suite passes via ./gradlew :posthog:test.
  • Emulator E2E against a local stack (via adb reverse). Registered a token, then ran unregisterPushNotificationToken() then optOut(). The DELETE reached the backend (200). Rebuilt with the pre-fix config.optOut guard and the same flow logged the unregister but sent no DELETE.

Not in this PR

#675 also reports that optIn() does not refetch the token or re-register. That half is fixed separately in #689.

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-android Compliance Report

Date: 2026-08-10 16:59:56 UTC
Duration: 117965ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 274ms
Format Validation.Event Has Uuid 22ms
Format Validation.Event Has Lib Properties 22ms
Format Validation.Distinct Id Is String 21ms
Format Validation.Token Is Present 22ms
Format Validation.Custom Properties Preserved 25ms
Format Validation.Event Has Timestamp 22ms
Retry Behavior.Retries On 503 7021ms
Retry Behavior.Does Not Retry On 400 4019ms
Retry Behavior.Does Not Retry On 401 4019ms
Retry Behavior.Respects Retry After Header 7021ms
Retry Behavior.Implements Backoff 17030ms
Retry Behavior.Retries On 500 7015ms
Retry Behavior.Retries On 502 7016ms
Retry Behavior.Retries On 504 7018ms
Retry Behavior.Max Retries Respected 17031ms
Deduplication.Generates Unique Uuids 29ms
Deduplication.Preserves Uuid On Retry 7015ms
Deduplication.Preserves Uuid And Timestamp On Retry 12017ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7016ms
Deduplication.No Duplicate Events In Batch 30ms
Deduplication.Different Events Have Different Uuids 29ms
Compression.Sends Gzip When Enabled 16ms
Batch Format.Uses Proper Batch Structure 13ms
Batch Format.Flush With No Events Sends Nothing 11ms
Batch Format.Multiple Events Batched Together 25ms
Error Handling.Does Not Retry On 403 4017ms
Error Handling.Does Not Retry On 413 4018ms
Error Handling.Retries On 408 5022ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 26ms
Request Payload.Flags Request Uses V2 Query Param 18ms
Request Payload.Flags Request Hits Flags Path Not Decide 17ms
Request Payload.Flags Request Omits Authorization Header 20ms
Request Payload.Token In Flags Body Matches Init 14ms
Request Payload.Groups Round Trip 16ms
Request Payload.Groups Default To Empty Object 21ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 17ms
Request Payload.Disable Geoip Omitted Defaults To False 15ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 18ms
Request Lifecycle.No Flags Request On Init Alone 9ms
Request Lifecycle.No Flags Request On Normal Capture 17ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 29ms
Request Lifecycle.Mock Response Value Is Returned To Caller 16ms
Retry Behavior.Retries Flags On 502 316ms
Retry Behavior.Retries Flags On 504 317ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 16ms

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

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
### Issue 1
posthog/src/test/java/com/posthog/internal/PostHogPushSubscriptionManagerTest.kt:363
**Remove stale failure claim**

This comment says the regression test “fails today,” even though this PR fixes the behavior and the test now passes, making the test’s current status harder for maintainers to interpret.

```suggestion
    // Regression test for posthog-android#675.
```

---

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

Reviews (1): Last reviewed commit: "chore: point changeset at the posthog co..." | Re-trigger Greptile

Comment thread posthog/src/test/java/com/posthog/internal/PostHogPushSubscriptionManagerTest.kt Outdated
Comment thread .changeset/push-unregister-optout.md
@dmarchuk
dmarchuk merged commit 7825f07 into main Aug 11, 2026
16 checks passed
@dmarchuk
dmarchuk deleted the fix/push-unregister-optout-675 branch August 11, 2026 10:14
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