Skip to content

fix: [SDK-5468] retry failed Live Activity token uploads in the same run - #1822

Draft
nan-li wants to merge 1 commit into
mainfrom
nan/sdk-5468
Draft

nan-li wants to merge 1 commit into
mainfrom
nan/sdk-5468

Conversation

@nan-li

@nan-li nan-li commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Description

One Line Summary

The Live Activities executor retries a failed token upload in the same run, instead of waiting for the next app launch.

Details

Motivation

After a retryable failure, the Live Activities executor kept the request in its cache and sent it again only on the next app launch. Until then the server did not have the activity's update token, so the activity could miss every update for the rest of the run. A same-token enter call did not help, because the executor dropped it as a duplicate of the unsent cached request. A push subscription change also re-sent only start tokens, so update tokens kept the old subscription ID. Reported in #1769.

#1775 fixed the same problem for the other executors. This change uses the same OSRequestRetryBackoff and OSOperationRetryTrigger.

Scope

  • A retryable failure now gets a backoff wait from OSRequestRetryBackoff (5 s doubling to 300 s, with jitter, and Retry-After as the minimum). Then the executor sends the request again. Non-retryable failures still remove the request, as before.
  • OSOperationRetryTrigger ends the wait early on foreground, and when the network returns while the app is in the foreground. Retry-After is still obeyed. OneSignalTracker forwards focus and unfocus to the Live Activities module through NSClassFromString, so apps without the module are not affected.
  • A repeat call that matches an unsent cached request (for example a same-token enter) now sends that cached request, unless it is in flight or waiting out a backoff.
  • A push subscription change now re-sends update tokens as well as start tokens. Receipts and click events are not re-sent.
  • A backoff retry is skipped if a newer request replaced the failed one in the cache, so an old token is never sent again.
  • Each request runs inside a background task, so a request that starts just before the app goes to the background can finish.
  • Backoff state is in memory. After a relaunch, the 30 s poll sends cached requests as before. On the first foreground they now go out at once.
  • Not changed: OneSignalClient still resends status 0 and 5xx on its own 5/15/45/135 s schedule before the executor sees the failure. The privacy consent check in executeRequest is unchanged.

Testing

Unit testing

New tests in OSLiveActivitiesExecutorTests:

  • A retryable failure is sent again in the same run.
  • Foreground sends a failed request before its backoff ends, but still waits out Retry-After.
  • A same-token enter after a relaunch sends the unsent cached request, and does not resend a request that is in flight.
  • A subscription change re-sends update tokens but not receipts.
  • Each request ends its background task.

The full UnitTestApp_TestPlan_Reduced plan passes locally (826 tests). Each new behavior was removed one at a time, and the matching test failed each time. Removing the in-flight check also fails 3 existing dedup tests.

Manual testing

Not done yet. The unit tests mock the network. A device run of the #1769 repro is still needed: call enter with no network, restore the network, and check that the update token uploads without a relaunch.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

A retryable failure used to wait for the next app launch, so a running activity could miss every update until then.

Co-authored-by: Cursor <cursoragent@cursor.com>
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