Skip to content

[codex] Fix tvOS Home wake recovery - #17

Merged
Quick104 merged 1 commit into
mainfrom
codex/tvos-home-wake-recovery
Jun 23, 2026
Merged

Quick104 merged 1 commit into
mainfrom
codex/tvos-home-wake-recovery

Conversation

@Quick104

@Quick104 Quick104 commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Retry one transient empty Home load before surfacing the generic server error.
  • Refresh Home on tvOS foreground/wake while the app is authenticated.
  • Remove the sign-out fallback from generic retryable errors so users are not steered toward signing out for a network hiccup.

Verification

  • Built SiloTV for the tvOS simulator.
  • Paired the tvOS simulator app to the dev server through the TV pairing flow, selected a profile, and confirmed Home loaded media content.
  • Simulated display sleep/wake in the tvOS simulator and confirmed authenticated Home remained visible without the generic server/sign-out error.
  • Ran git diff --check.
  • Ran privacy-leak-check on the staged diff, commit message, and PR body.

Summary by CodeRabbit

  • Bug Fixes

    • Added automatic retry mechanism for temporary loading failures, improving app resilience
    • Enhanced home content refresh behavior on tvOS when returning to the app from the background
  • User Experience

    • Simplified error dialogs with streamlined action buttons

@coderabbitai

coderabbitai Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

HomeViewModel gains a fetchAndApplySections() helper and a retryTransientInitialLoad() method that retries after 750ms when the initial fetch fails with a transient error and no sections are displayed. ContentView posts a .homeSectionsShouldRefresh notification on tvOS when the app returns to the foreground while authenticated. ErrorView suppresses the "Sign In Again" primary button and "Sign Out" secondary button for the relevant error condition by returning nil.

Changes

tvOS Home Resilience

Layer / File(s) Summary
Home section fetch and transient retry logic
iosApp/iosApp/Screens/Home/HomeViewModel.swift, iosApp/iosApp/ContentView.swift
loadSections() routes transient initial-load failures to a new retryTransientInitialLoad() helper that waits 750ms before re-invoking fetchAndApplySections(). On tvOS, ContentView now posts .homeSectionsShouldRefresh via NotificationCenter whenever the scene becomes active while the router is authenticated.
ErrorView Sign In / Sign Out button suppression
iosApp/iosApp/Components/ErrorView.swift
primaryAction returns nil instead of a "Sign In Again" button, and secondaryAction returns nil instead of a "Sign Out" button, for the previously handled resolvedOnSignOut condition.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: fixing tvOS Home wake recovery through error handling and refresh mechanisms.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/tvos-home-wake-recovery

Comment @coderabbitai help to get the list of available commands.

@Quick104
Quick104 marked this pull request as ready for review June 23, 2026 19:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
iosApp/iosApp/Screens/Home/HomeViewModel.swift (1)

31-56: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Race condition when loadSections() is called concurrently.

Multiple concurrent calls to loadSections() can interleave at await points, causing the retry logic to run even after a subsequent call has succeeded. For example:

  1. First call encounters a transient error and suspends in retryTransientInitialLoad() for 750ms
  2. Second call (triggered by foreground notification or user navigation) starts and successfully fetches sections
  3. First call resumes, retries the fetch, and potentially overwrites sections or sets error, negating the successful second load

This can cause incorrect UI state and unnecessary network calls.

Recommended fix: cancel in-flight tasks

Store the in-flight task and cancel it when a new load starts:

 `@Observable`
 `@MainActor`
 class HomeViewModel {
     var sections: [ResolvedSection] = []
     var isLoading = false
     var isRefreshing = false
     var error: ErrorState?
+    private var loadTask: Task<Void, Never>?

     func loadSections() async {
+        loadTask?.cancel()
+        loadTask = Task {
+            await performLoad()
+        }
+        await loadTask?.value
+    }
+
+    private func performLoad() async {
         if sections.isEmpty {
             isLoading = true
         } else {

And check Task.isCancelled before updating state in retryTransientInitialLoad() and after the fetch completes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iosApp/iosApp/Screens/Home/HomeViewModel.swift` around lines 31 - 56, The
loadSections() method has a race condition where concurrent calls can interleave
at await points, causing the retry logic in retryTransientInitialLoad() to
overwrite successful state updates from later calls. Fix this by storing a
reference to the in-flight task as a property, canceling any previous task at
the start of loadSections(), and checking Task.isCancelled before updating state
in both retryTransientInitialLoad() and after the fetchAndApplySections() call
completes to ensure cancelled tasks don't modify the UI state.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@iosApp/iosApp/Screens/Home/HomeViewModel.swift`:
- Around line 31-56: The loadSections() method has a race condition where
concurrent calls can interleave at await points, causing the retry logic in
retryTransientInitialLoad() to overwrite successful state updates from later
calls. Fix this by storing a reference to the in-flight task as a property,
canceling any previous task at the start of loadSections(), and checking
Task.isCancelled before updating state in both retryTransientInitialLoad() and
after the fetchAndApplySections() call completes to ensure cancelled tasks don't
modify the UI state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 71298378-d94e-4d82-8788-b684401985f8

📥 Commits

Reviewing files that changed from the base of the PR and between 4fa87cb and 8d90e31.

📒 Files selected for processing (3)
  • iosApp/iosApp/Components/ErrorView.swift
  • iosApp/iosApp/ContentView.swift
  • iosApp/iosApp/Screens/Home/HomeViewModel.swift

@Quick104
Quick104 merged commit 7c75c2a into main Jun 23, 2026
1 check passed
@Quick104
Quick104 deleted the codex/tvos-home-wake-recovery branch June 23, 2026 19:49
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