Repository navigation
[codex] Fix tvOS Home wake recovery - #17
Conversation
📝 WalkthroughWalkthrough
ChangestvOS Home Resilience
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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 liftRace condition when
loadSections()is called concurrently.Multiple concurrent calls to
loadSections()can interleave atawaitpoints, causing the retry logic to run even after a subsequent call has succeeded. For example:
- First call encounters a transient error and suspends in
retryTransientInitialLoad()for 750ms- Second call (triggered by foreground notification or user navigation) starts and successfully fetches sections
- First call resumes, retries the fetch, and potentially overwrites
sectionsor setserror, negating the successful second loadThis 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.isCancelledbefore updating state inretryTransientInitialLoad()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
📒 Files selected for processing (3)
iosApp/iosApp/Components/ErrorView.swiftiosApp/iosApp/ContentView.swiftiosApp/iosApp/Screens/Home/HomeViewModel.swift
Summary
Verification
SiloTVfor the tvOS simulator.git diff --check.privacy-leak-checkon the staged diff, commit message, and PR body.Summary by CodeRabbit
Bug Fixes
User Experience