Skip to content

Fix LA not refreshing on foreground after stale overlay#576

Merged
bjorkert merged 1 commit intoloopandlearn:live-activityfrom
achkars-org:fix/la-stale-foreground-refresh
Mar 26, 2026
Merged

Fix LA not refreshing on foreground after stale overlay#576
bjorkert merged 1 commit intoloopandlearn:live-activityfrom
achkars-org:fix/la-stale-foreground-refresh

Conversation

@MtlPhil
Copy link
Copy Markdown

@MtlPhil MtlPhil commented Mar 26, 2026

Summary

  • startIfNeeded() reused stale activities on cold start — when the app is killed while the renewal overlay is showing, willEnterForeground is never sent on relaunch, so handleForeground() never runs. The cold-start path (viewDidAppear → startFromCurrentState → startIfNeeded) found the existing stale activity and rebound to it, leaving the overlay visible. Fix: before reusing an existing activity, check existing.content.staleDate and the renewal window; if stale, end it (awaited) and restart.
  • "Live Activity Expiring" notification not cleared on foreground restarthandleForeground() cleared laRenewalFailed and laRenewBy but never called cancelRenewalFailedNotification(), leaving the system notification visible after the LA successfully restarted.

Test plan

  • Let the LA run until the renewal overlay appears (or advance the clock), then force-quit the app. Relaunch — the LA should restart automatically without needing the Restart button.
  • Let the LA run until the renewal overlay appears, background the app, then foreground it — the LA should restart and the "Live Activity Expiring" notification should be dismissed.
  • Tap the Restart button — unchanged behaviour, LA restarts and notification clears.

🤖 Generated with Claude Code

startIfNeeded() unconditionally reused any existing activity, which
meant that on cold start (app killed while stale overlay was showing)
willEnterForeground is never sent, handleForeground never runs, and
viewDidAppear → startFromCurrentState → startIfNeeded just rebinds to
the stale activity — leaving the overlay visible.

Fix: before reusing an existing activity in startIfNeeded(), check
whether its staleDate has passed or the renewal window is open. If so,
end it (awaited) and call startIfNeeded() again so a fresh activity
with a new 7.5h deadline is started.

Also add cancelRenewalFailedNotification() to handleForeground() so
the "Live Activity Expiring" system notification is dismissed whenever
the foreground restart path fires, not only via forceRestart().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bjorkert bjorkert merged commit 6f98fac into loopandlearn:live-activity Mar 26, 2026
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