Skip to content

Fix Live Activity restart classification, foreground race, and add troubleshooting logs#615

Merged
marionbarker merged 3 commits intodevfrom
fix/live-activity-restart-foreground-race
May 4, 2026
Merged

Fix Live Activity restart classification, foreground race, and add troubleshooting logs#615
marionbarker merged 3 commits intodevfrom
fix/live-activity-restart-foreground-race

Conversation

@bjorkert
Copy link
Copy Markdown
Member

Summary

Two fixes plus diagnostics for Live Activity restart paths, split out from the broader background-renewal work so they can land independently.

Restart classification + foreground race

  • handleExpiredToken, endOnTerminate, forceRestart: mark endingForRestart before ending so the state observer doesn't misclassify the resulting .dismissed as a user swipe (which would set dismissedByUser=true and block auto-restart on the next background refresh).
  • Defer foreground restart from willEnterForeground to didBecomeActive so Activity.request() isn't called before the scene is active (avoids the "visibility" failure).
  • Remove duplicate orphan LiveActivitySettingsView.swift under Settings/ (not referenced by the Xcode project).

Troubleshooting logs

  • startIfNeeded: log entry state (authorized, activities, current, flags) and enrich Activity.request failure with NSError domain/code + scene state.
  • renewIfNeeded: enrich catch with NSError domain/code + authorization state.
  • handleForeground / handleDidBecomeActive: include applicationState and the existing activities count at entry.
  • observePushToken: log token fingerprint (last 8 chars) and prior value so token rotations are visible.
  • update: log when the direct ActivityKit update is skipped (app backgrounded) and when APNs is skipped because no push token has been received yet.
  • performRefresh: log the gate that blocks LA updates — especially dismissedByUser=true, which previously caused silent extended outages.
  • handleExpiredToken: log current id, activities count, and flags before ending so APNs 410/404 events are correlatable to the restart path.
  • bind: include activityState and the previous endingForRestart value so the dismissal-classification path is traceable.

- handleExpiredToken, endOnTerminate, forceRestart: mark endingForRestart
  before ending so the state observer does not misclassify the resulting
  .dismissed as a user swipe (which would set dismissedByUser=true and
  block auto-restart on the next background refresh).
- Defer foreground restart from willEnterForeground to didBecomeActive
  so Activity.request() is not called before the scene is active
  (avoids the "visibility" failure).
- Remove duplicate orphan LiveActivitySettingsView.swift under Settings/
  (not referenced by the Xcode project).
- startIfNeeded: log entry state (authorized, activities, current, flags)
  and enrich Activity.request failure with NSError domain/code + scene state.
- renewIfNeeded: enrich catch with NSError domain/code + authorization state.
- handleForeground / handleDidBecomeActive: include applicationState and
  the existing activities count at entry.
- observePushToken: log token fingerprint (last 8 chars) and prior value so
  token rotations are visible.
- update: log when the direct ActivityKit update is skipped (app backgrounded)
  and when APNs is skipped because no push token has been received yet.
- performRefresh: log the gate that blocks LA updates — especially
  dismissedByUser=true, which previously caused silent extended outages.
- handleExpiredToken: log current id, activities count, and flags before
  ending so APNs 410/404 events are correlatable to the restart path.
- bind: include activityState and the previous endingForRestart value so
  the dismissal-classification path is traceable.
bjorkert added a commit that referenced this pull request Apr 27, 2026
Copy link
Copy Markdown
Collaborator

@marionbarker marionbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve by test that the app builds and LiveActivity shows on the watch and phone.

This has been used successfully by the developer on his personal phone.

@marionbarker marionbarker merged commit 22dc308 into dev May 4, 2026
1 check passed
@marionbarker marionbarker deleted the fix/live-activity-restart-foreground-race branch May 4, 2026 02:51
MtlPhil pushed a commit to achkars-org/LoopFollow that referenced this pull request May 6, 2026
Brings in all changes from loopandlearn/LoopFollow dev up to 6.1.0.
Resolved conflicts by taking upstream throughout, except LogManager
where both the watch and telemetry log categories are kept.

Key changes from upstream:
- Add iOS 17.2+ push-to-start for Live Activity renewal (loopandlearn#622)
- Fix LA restart classification, foreground race, troubleshooting logs (loopandlearn#615)
- Redact secrets from log output (loopandlearn#623)
- Add anonymous telemetry (loopandlearn#626)
- Add units selection (loopandlearn#558)
- Fix stats inclusive date range (loopandlearn#629)
- Deduplicate Nightscout treatment entries by id (loopandlearn#569)
- Fix alarm sound session activation failures in background (loopandlearn#596)
- Recognize Atlas DASH pod in Omnipod heartbeat scan (loopandlearn#633)
- Default migrationStep to latest on fresh installs (loopandlearn#631)
- Update to fastlane 2.233.1 (loopandlearn#632)

https://claude.ai/code/session_01VK2furpEaEmysQvEd1h77f
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