Repository navigation
fix: [SDK-5580] end duplicate Live Activities and keep the update token - #1780
Conversation
Activities with the same OneSignal activityId share one update token registration, so dismissing a duplicate froze the survivor and only the last registered widget updated.
There was a problem hiding this comment.
Multi-model review
Reviewed with Claude Opus 5.5, GPT 5.6 Sol, and Grok 4.7. Substantive diff is 311 lines after excluding project.pbxproj.
Act on (3/3): Setup now ends duplicates in an unstructured Task, while the existing activityUpdates loop still ends every other live instance and listens to whoever the stream yields. Those policies disagree (cached token vs newest), and Apple already notes the same activity can appear in both places on push-to-start. If they interleave, both widgets can be ended, or listeners attach to the copy setup is about to kill.
Act on (3/3): endDuplicates chooses a keeper once, then still ends remaining live copies if that keeper dies mid-await. testEndDuplicates_whenTheKeeperEndsDuringTheAwaits_returnsNothing locks that in. The caller then attaches no listeners and never exits, so the backend can keep a dead token.
Consider: Skipping exit on dismiss does not enter the survivor's token, so the last registration can still belong to the dismissed activity. Ended-but-still-listed activities are omitted from duplicateGroups and can still enter. cachedUpdateToken treats a pending/unsuccessful OSRequestSetUpdateToken as the backend token. activityToKeep can pick the wrong instance while pushToken is still nil.
Noted: Keeper listeners wait until all ends finish, so contentUpdates in that window are missed. Activity.activities order is unspecified for the no-token fallback.
Sent by Cursor Automation: PR Reviews
Setup kept the activity with the cached token and the activityUpdates loop kept the newest, so both at once could end every duplicate. A dismissal with a live duplicate now registers that duplicate's token, because the dismissed activity may hold the registration. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Replies to the other points in the Cursor review summary:
|
abdulraqeeb33
left a comment
There was a problem hiding this comment.
The two earlier comments are fixed. The activityUpdates loop waits for this call's setup dedupe and skips a yield that is no longer live, and endDuplicates picks a new keeper if the current one ends during await end.
Dismissal still leaves the update token in place when the survivor has no token yet, and a second setup() can start a second loop.
|
Same as ar's assessment. |
When an activity is dismissed and several live activities share its activityId, the SDK registers the token of one that has a token. It used to take the first live one, which could have no token yet.
abdulraqeeb33
left a comment
There was a problem hiding this comment.
Commenting, not requesting changes.
The description covers one setup() call. The activityUpdates loop waits for that call's dedupe, so those two rules do not run at once. A second setup() for the same activity type is only in the thread reply. On main both paths keep the activity just yielded, so a second call lands on the same one. Here the second dedupe keeps the cached-token activity while the first loop keeps the new one. If those ends overlap, nothing stays live and endDuplicates calls exit.
On the skipped exit: an exit built while the survivor's token reads nil is older than a later enter, and the enter replaces it in the cache. The case that stays is when no enter follows, enablePushToUpdate off or a survivor that never receives a push token. The dismissed token stays registered. That is not in the description. The description says the new dismissal behavior runs only when enablePushToUpdate is on, and that nothing changes for apps that call enter and exit themselves.
|
Replies to the two points in the latest review:
|
fadi-george
left a comment
There was a problem hiding this comment.
LGTM, the remaining cases are documented and low impact.
abdulraqeeb33
left a comment
There was a problem hiding this comment.
Approving. The earlier blocking items are fixed and the two residuals in the description are fine.
handleDismissalis the only new helper without a seam, so exit / enter / leave-registered are untested, and dismissal-while-duplicate was not manually tested. A puredismissalActionoverFakeActivitywould close that.- The "keeping duplicate" log is the same when the token is re-entered and when it is left registered. Worth a debug line on the leave path.
- The
exitcomment atendDuplicatesoverclaims. That call covers groups that never got a state listener; a latersetup()can still hithandleDismissal.
abdulraqeeb33
left a comment
There was a problem hiding this comment.
Re-reviewed 005a8dcb. Prior blockers are fixed: setup awaits its dedupe, keeper re-pick works, and liveDuplicate prefers a tokened survivor. The skipped exit when no survivor has a token, and the second-setup() residual, still look right as documented.
Two nits only.


Description
One Line Summary
End duplicate Live Activities at startup and keep their shared update token when one is dismissed. SDK-5580.
Details
Motivation
When two subscriptions on one device hold the same push-to-start token, one push starts two Live Activities with the same OneSignal activityId. They share one update token registration, so only the activity registered last receives updates, and dismissing either one removed the registration and froze the other.
Scope
exit. WithenablePushToUpdateon, it also registers the token of a live duplicate that has one. The dismissed activity can hold the registration, because the lastenterfor an activityId wins.setup(), live activities that share an activityId are reduced to one. The SDK keeps the activity whose push token matches the cached update token, otherwise the first one with a token, ends the rest immediately, and attaches listeners only to the kept one. If the kept activity ends during the dedupe, the SDK picks another live one. If none stays live, it callsexitfor that activityId. Needs iOS 16.2, like the existing dedupe of newly started activities.activityUpdatesloop now waits for the setup dedupe before it handles a yielded activity, and it skips an activity that is no longer live. The two dedupes keep different activities (cached token versus newest), so if both run at once they can end every duplicate. The liveness check also stops the existing loop from ending both activities when the stream yields one that the loop already ended.setup(). For apps that do, every change above applies withenablePushToUpdateon or off, except registering a duplicate's token on dismissal. For activities without a duplicate, the only change is that theactivityUpdatesloop no longer attaches listeners to an activity that has already ended, on any iOS version.Two cases are left as they are, because each needs several unlikely things at once:
enterafterwards, which meansenablePushToUpdateis off or the remaining activity never receives a token. The remaining widget is not affected, andexitruns when it is dismissed.setup()call for the same activity type can end every copy. The second call has to arrive while two activities share an activityId, its dedupe has to keep a different activity from the one the first call's loop keeps, and both have to end an activity at the same moment.Testing
Unit testing
Tests with fake activities cover grouping by activityId (ended and dismissed activities excluded), choosing the activity to keep, ending all but one per group, and finding a live duplicate on dismissal. They also cover picking a new keeper when the keeper ends during the dedupe, and calling
exitwhen no activity stays live. Two executor tests cover reading the cached update token, including when a removal is pending. ActivityKit activities cannot be created in unit tests, so the wiring inlistenForActivityandhandleDismissalis not covered.Manual testing
On an iPhone 17 simulator (iOS 26.5), the full Reduced unit test plan passed 650 of 651 tests. The one failure is
UserJwtLifecycleTests.testUpdateUserJwtSendsTheCreateUserThatARejectedTokenHeldinOneSignalUserTests, which does not depend on Live Activities. It passed 3 of 3 runs alone.On an iPhone running iOS 26 with two subscriptions sharing one push-to-start token (a second user and push subscription created after clearing the SDK cache), the app was swiped away and one push-to-start was sent. It reached both subscriptions, and one widget remained once the app launched and
setup()ran.On an iPhone 17 Pro simulator (iOS 26.5), a demo build from main was compared with a build from main with this branch merged in. On 19 November one push-to-start reached the device once, even with two subscriptions sharing its token, so these runs sent the start twice with the same activityId.
setup()and kept one.setup()ran, because the simulator gives no update token to an activity started by push.Dismissing one widget while a duplicate is live was not tested.
Affected code checklist
Checklist
Overview
Testing
Final pass
🤖 Generated with Claude Code