Repository navigation
fix(detail): label the Play button Resume when playback will resume - #622
Conversation
Problem: a series or movie detail page keeps the watch state it loaded with. When another device moved the position while the page stayed open, tapping Play showed "You stopped at" with the old time, and Resume passed that cached time to the player as an explicit position, which beats the fresh position the playback bridge reads from the server. Fix: a Play tap on the phone/iPad/Mac detail page now re-reads the item's watch state (the same watch-detail endpoint the bridge uses) before deciding. The resume prompt shows that position and Resume passes exactly that position to the player. The page's cached state is used only when the server is known unreachable, the read fails, or it takes longer than 3 seconds, so offline playback of downloads and slow servers still respond. Why this over passing no explicit position and letting the bridge resolve it: that alone fixes where streaming starts but leaves the prompt showing the stale time, and the explicit position is also what the downloaded-copy choice, the unreachable-server retry and the engaged-TV handoff carry. Refreshing once at the tap fixes the prompt and every one of those paths without touching the bridge or the other callers (Continue Watching cards, retries, replans). The prompt now appears whenever the fresh state has a resumable position, rather than keying on the cached in-progress flag. Test: DetailResumeStateTests covers the decision (fresh state beats the snapshot, fresh "no progress" suppresses a stale resume, near-end suppression, snapshot fallback) and the fetch wrapper (success, error, timeout cancels the stalled fetch).
Problem: the Apple TV detail page passed the watch position it loaded with to the player. When another device moved the position while the page stayed open, Resume started from the old time, because an explicit position beats the fresh one the playback bridge reads. The phone's Play on TV button had the same problem: it sent the page's cached position to the TV. Fix: Resume/Play on the tvOS movie and series pages (action row and the episode rail's quick play) re-reads the item's watch state with DetailResumeState before opening the player, and passes that position. The cached position is used only when the server is known unreachable, the read fails, or it takes longer than 3 seconds. Start Over skips the read. Version and track picks are captured at the press, and leaving the page cancels a pending read. Play on TV on iPhone/iPad/Mac does the same read before building the cast request. Continue Watching cards are unchanged: their positions come from the home feed, not a long-lived page snapshot.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 27 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (8)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| if let position { fields.append("\"positionSeconds\":\(position)") } | ||
| if let duration { fields.append("\"durationSeconds\":\(duration)") } | ||
| if position != nil { fields.append("\"isInProgress\":true") } | ||
| return try JSONDecoder().decode( |
There was a problem hiding this comment.
Decoder configuration mismatch in iosApp/Tests/DetailPlayLabelTests.swift pairs a default JSONDecoder with camelCase fixture keys, testing a different decoding convention that can miss failures in the actual server payload contract (also in iosApp/Tests/DetailResumeStateTests.swift:15-15). Use the production decoder configuration for this fixture, including .convertFromSnakeCase.
Kody rule violation: Use consistent API normalization and production-equivalent decoding
Prompt for LLM
File iosApp/Tests/DetailPlayLabelTests.swift:
Line 31:
Decoder configuration mismatch in `iosApp/Tests/DetailPlayLabelTests.swift` pairs a default `JSONDecoder` with camelCase fixture keys, testing a different decoding convention that can miss failures in the actual server payload contract (also in `iosApp/Tests/DetailResumeStateTests.swift:15-15`). Use the production decoder configuration for this fixture, including `.convertFromSnakeCase`.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
There was a problem hiding this comment.
Thanks—based on your description, that addresses the decoder mismatch in both test files. Using snake_case user_data, HTTPClient.makeJSONDecoder(), and the WatchRollup → LeafItemUserData(catalog:) projection aligns the fixtures with the production detail-read path.
No further changes are needed for this suggestion.
| } | ||
| resumeLookupTask = Task { | ||
| let state = await refreshedResumeState(contentId: id) | ||
| guard !Task.isCancelled, isPageVisible else { return } |
There was a problem hiding this comment.
Stale-scope playback in iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift can occur because the post-await guard checks cancellation and page visibility but not the authentication owner or server/profile scope, allowing a session or scope change while the page remains visible to start playback with an obsolete scope's resume position (also in iosApp/iosApp/Screens/Detail/ItemDetailView.swift:548-548). Capture the owner and active scope before starting the watch-state lookup task, verify both before clearing the task handle or invoking play, and invalidate the lookup when that scope changes.
Kody rule violation: Fence asynchronous results by scope and invalidation generation
Prompt for LLM
File iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift:
Line 624:
Stale-scope playback in `iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift` can occur because the post-await guard checks cancellation and page visibility but not the authentication owner or server/profile scope, allowing a session or scope change while the page remains visible to start playback with an obsolete scope's resume position (also in `iosApp/iosApp/Screens/Detail/ItemDetailView.swift:548-548`). Capture the owner and active scope before starting the watch-state lookup task, verify both before clearing the task handle or invoking play, and invalidate the lookup when that scope changes.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Not changing. This code comes from #621, and the same finding is answered there. A server, profile, or sign-in change takes the router out of .authenticated or re-keys the routed content, which removes this page. onDisappear then cancels the lookup, and the post-await guard drops it. On tvOS the profile and server controls are in the top bar, which is hidden while a detail page is pushed. SiloAPI.watchDetail also throws requestIdentityChanged if the owner changed during the read, so another owner's position is never used.
There was a problem hiding this comment.
Understood—I withdraw this suggestion for #622.
The finding assumed the detail page could remain active across a scope change. Your explanation addresses that: routing removes or re-keys the page, onDisappear cancels the lookup, and the post-await guard rejects canceled or no-longer-visible work. watchDetail also rejects owner changes during the read.
This code belongs to #621, where the finding was already addressed; #622’s review should cover only the final label-change commit. No change requested here.
… cancellation The Play tap's watch-state read raced a 3 second timer inside a task group. A task group waits for every child before it returns, so when the read was parked where cancellation does not reach, such as joining HTTPClient's shared token-refresh flight, the tap stayed unanswered until that wait ended instead of falling back to the page's position. The read and the timer now run as separate tasks and the first answer wins. The read is cancelled and left to finish in the background, and cancelling the caller returns at once as well. Tests cover a read that ignores cancellation and a cancelled caller.
DetailResumeStateTests decoded LeafItemUserData from camelCase keys with a default JSONDecoder. The app never decodes it that way: the watch read decodes the server's snake_case user_data into the v2 WatchRollup with HTTPClient's decoder and projects it. The fixtures now take that path, so a change to the wire model or the projection fails these tests too.
The iPhone series page's Play button always read "Play S1·E2", even when that episode was part-watched and the tap would ask to resume. The movie page always read "Play". The button now reads "Resume S1·E2" on a series and "Resume" on a movie when the item has a resume point: more than 30 seconds in and not within 5 seconds of the end. That is the PlaybackResumePoint rule the resume prompt uses, applied to the page's saved watch state. The resume-or-restart dialog is unchanged. DetailPlayLabelTests covers the series and movie titles and the 30-second and end-of-item thresholds. Found during the Series validation, silo-apple#337.
DetailPlayLabelTests decoded LeafItemUserData from camelCase keys with a default JSONDecoder, a path the app never uses. The fixtures now decode the server's snake_case user_data into the v2 WatchRollup with HTTPClient's decoder and project it, as the detail reads do.
8364e8b to
77e57af
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| private func refreshedResumeState(contentId: String) async -> DetailResumeState { | ||
| guard ConnectionMonitor.shared.isServerReachable else { return .unavailable } | ||
| let libraryId = libraryId | ||
| return await DetailResumeState.load { |
There was a problem hiding this comment.
Stale watch-state results can escape the shared refresh because it neither captures nor rechecks the authentication owner, active server/profile scope, or applicable invalidation generation; capturing libraryId alone does not fence these identities, including at iosApp/iosApp/Screens/Detail/ItemDetailView.swift:550-550 and iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift:624-624. Capture the request scope before loading, await into a local result, validate the scope and generation before returning usable state, and ensure callers distinguish invalidated operations from ordinary unavailability to prevent playback using an obsolete cached snapshot.
Kody rule violation: Fence asynchronous results by scope and invalidation generation
Prompt for LLM
File iosApp/iosApp/Screens/Detail/ItemDetailView.swift:
Line 838:
Stale watch-state results can escape the shared refresh because it neither captures nor rechecks the authentication owner, active server/profile scope, or applicable invalidation generation; capturing libraryId alone does not fence these identities, including at `iosApp/iosApp/Screens/Detail/ItemDetailView.swift:550-550` and `iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift:624-624`. Capture the request scope before loading, await into a local result, validate the scope and generation before returning usable state, and ensure callers distinguish invalidated operations from ordinary unavailability to prevent playback using an obsolete cached snapshot.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Not changing. This helper comes from #621 (7e75465), not from this PR's own commits. It is not a shared refresh. Each caller runs it inside a task the page owns: the cast-button lookup and the Movie/Series Play lookups on iOS, and resumeLookupTask on tvOS. onDisappear cancels that task, and the post-await guard drops a cancelled result. The read calls SiloAPI.watchDetail directly, with no request pool or response cache, so no result can carry over from another scope. watchDetail captures the owner before the request and throws requestIdentityChanged if the owner changed by the time it returns. Every server, profile, PIN or sign-in change re-keys the routed content or moves the router out of .authenticated, which removes the page and cancels the lookup. A PIN recovery that lands while a lookup is running posts siloProfileSelectionRequired. Its handler clears presentedPlayer and resets the path, so a player that opened from the fallback is closed. That fallback is the same profile's snapshot, which the Play tap used directly before this change.
There was a problem hiding this comment.
Understood. I withdraw this recommendation for #622.
The helper comes from #621 (7e754658), so it is outside this PR’s requested review scope. Calling it a “shared refresh” was also inaccurate.
Given the safeguards you described—page-owned task cancellation, post-await cancellation checks, watchDetail’s owner validation, routing changes that remove the page, and PIN-recovery handling that closes playback—I haven’t established a concrete path where an obsolete scope’s result reaches playback. The fallback also preserves the page-snapshot behavior that existed before this change.
The absence of a request pool or cache alone would not rule out an asynchronous race, but it does not justify demanding additional generation fencing without showing a gap in those existing safeguards. No change is warranted from this finding.
Problem
Related issue: N/A
Validation tasks: changes #337 C3
Merge order: this branch starts with the commits of #621. Merge that first; review only the commits after them here. Both change the detail page's Play button.
The iPhone series page's Play button always read "Play S1·E2", even when that episode was part-watched and the tap would ask to resume. The movie page always read "Play". The button now reads "Resume S1·E2" or "Resume" when the item has a resume point.
Approach
The label uses the
PlaybackResumePointrule the resume prompt uses (more than 30 s in and not within 5 s of the end), applied to the page's saved watch state. The tap still re-reads the server (#621), so if another device moved the position the label can be one state behind until the page reloads. The resume-or-restart dialog is unchanged.Validation
scripts/ci/check-no-api-v1.sh: pass.main(6242652): the full iOS unit suite ran 2,691 tests. The only failures areArtworkURLTests.testDeliveryCapabilityOnIOSUsesV2RouteAndResetsandImageSizeCapabilityTests.testResetClearsCapability, which fail the same way onmain. tvOSbuild-for-testingand the macOS build succeed.Simulator screenshots (iOS 26.5, tvOS 26.5):
Risks
None identified.
Checklist
AI Disclosure
mainat medium effort, checking behaviour, platform guards (iOS, tvOS, macOS), tests and commit hygiene. It found that the commit message described a change made in fix(detail): resume from the server's latest position #621's commit, and that a doc comment claimed the label always matches the tap. Both were reworded.