Live activity: fix: improve push-to-start safety, backoff, and token-wait behaviour#625
Open
MtlPhil wants to merge 1 commit intoloopandlearn:feat/la-ios17-push-to-startfrom
Open
Conversation
- Keep old LA alive until APNs send confirms success, so a failed push-to-start (rate-limited, invalid token, network error) no longer leaves the user with no activity and nothing to replace it - Reset laPushToStartBackoff to 0 in adoptPushToStartActivity so a near-term renewal is not silently blocked by the 5-minute post-send base interval once the new LA is confirmed by activityUpdates - Add apns-collapse-id (bundle-id.la.start) so APNs coalesces redundant push-to-start sends that race (refresh tick + user restart) - Set apns-expiration to 10 minutes instead of 0 so a brief connectivity gap does not permanently lose the start notification, while avoiding delivery of clinically stale glucose data - Raise pushToStartForceRestartThreshold from 2 to 4 to reduce false positives on slow connections where activityUpdates delivery lags - Add a single automatic 10-second retry when the push-to-start token is not yet available, before surfacing the "could not start" error https://claude.ai/code/session_01GJZERMhqLmEy8p4cpVX53q
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.
Summary
Six targeted fixes to the iOS 17.2+ push-to-start implementation, scoped entirely to
LiveActivityManager.swiftandAPNSClient.swift.1. Keep old LA alive until APNs send confirms success
Previously
dispatchPushToStartended the old activity before sending to APNs. If the send failed (rate-limited, invalid token, network error) the user lost their existing Live Activity with nothing to replace it.The old activity is now ended only after a
.successresult fromsendLiveActivityStart. On any failure path the existing LA remains visible.2. Reset backoff to zero on adoption
After a successful send,
handlePushToStartResultsetlaPushToStartBackoffto the 5-minute base. That value was never cleared afteractivityUpdatesconfirmed the new LA, so a legitimate renewal arriving within 5 minutes of adoption was silently blocked.adoptPushToStartActivitynow resetslaPushToStartBackoffto0once the new activity is confirmed.3. Add
apns-collapse-idto push-to-start requestsWithout a collapse key, two sends racing (e.g. a background refresh tick and a user-initiated restart overlapping) could create two Live Activities. Added
<bundleID>.la.startas the collapse ID so APNs coalesces redundant sends.4. Set
apns-expirationto 10 minutes instead of 0apns-expiration: 0means "deliver right now or discard." A momentary connectivity loss at the wrong moment would permanently lose the start notification.Changed to
now + 10 minutes— long enough to survive a brief offline gap while the glucose reading in the payload is still clinically meaningful. The stale date of 8 hours was considered and rejected: delivering a start notification with hours-old glucose data is worse than not starting at all.5. Raise
pushToStartForceRestartThresholdfrom 2 to 4The FB21158660 workaround force-restarts the LA when N consecutive successful APNs sends have not been followed by an
activityUpdatesadoption. A threshold of 2 produced false positives on slow connections where theactivityUpdatesdelivery simply lagged the send confirmation. Raised to 4.6. Single automatic retry when push-to-start token is not yet available
On first install or after a permission toggle, the push-to-start token may not have arrived before the first LA start attempt. Previously this caused an immediate "could not start" notification after a 5-second poll timeout.
dispatchPushToStartnow accepts anisRetry: Bool = falseparameter. On first timeout it waits 10 seconds and retries once before surfacing the error to the user. ApushToStartTokenRetryDelay = 10constant is added alongside the existing poll constants.