Repository navigation
fix(tv): improve Fire TV selection and episode continuity - #157
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe change adds session-only semantic source and subtitle handoffs for Android TV episode transitions. It resolves preferences against target catalogs, carries results through playback state, improves Next Up race handling, and adds TV selector focus styling and picker scrolling. ChangesPlayback selection handoff
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (5)
androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailViewModel.kt (3)
1143-1164: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument why
sourceusesselectedVersionand subtitles useactiveVersion.The asymmetry is intentional. Source intent carries only for an explicit version choice, so automatic source behavior on the target stays unchanged. Subtitle intent must be captured against the version actually displayed, so it uses
activeVersion. The two locals are named similarly and declared two lines apart, so a future reader could unify them and silently change behavior. The regression testslastPlayedAutoSourceCapturesAndResolvesSubtitleAgainstTheDisplayedVersionsandpreferredQualityAutoSourceCapturesAndResolvesSubtitleAgainstTheDisplayedVersionsprotect this, but a comment states the intent at the call site.♻️ Suggested comment
+ // `source` intentionally uses only the explicitly selected version: an + // automatic/lastFileId choice must not become a carried source intent. + // Subtitles are captured against `activeVersion` because that is the + // track list the combined subtitle index was resolved against. val handoff = EpisodeSelectionHandoff( source = selectedVersion?.let(::captureEpisodeSourceIntent), subtitle = captureEpisodeSubtitleIntent(state.selectedNextUpSubtitleIndex, subtitleChoices), )🤖 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 `@androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailViewModel.kt` around lines 1143 - 1164, Add a concise comment in captureNextUpSelectionHandoff at the EpisodeSelectionHandoff call site documenting that source uses selectedVersion only for explicit source intent, while subtitle uses activeVersion to reflect the displayed version; preserve the distinct locals and behavior covered by the existing regression tests.
1001-1034: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueConsider cancelling the outstanding next-up detail job.
loadNextUpPlaybackDetailstarts a new coroutine per refresh and relies only on generation and identity fences to discard stale completions. The fences are correct, but the previous request keeps running and completes a fullgetItemDetailround trip that is then thrown away. Rapid next-up changes, for example repeated watched toggles on the episode rail, therefore issue overlapping requests.loadEpisodesalready cancels its in-flight job for the same reason (Line 766).Keeping a
nextUpDetailJobreference and cancelling it before launch would reduce redundant network work while the existing fences continue to protect correctness.♻️ Suggested change
+ private var nextUpDetailJob: Job? = null + private fun loadNextUpPlaybackDetail( episodeContentId: String, refreshGeneration: Long, selectorRevision: Long, identityGeneration: Long, handoff: EpisodeSelectionHandoff?, ) { - viewModelScope.launch { + nextUpDetailJob?.cancel() + nextUpDetailJob = viewModelScope.launch {🤖 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 `@androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailViewModel.kt` around lines 1001 - 1034, Update loadNextUpPlaybackDetail to retain its launched coroutine in a nextUpDetailJob reference, cancel the existing job before starting a new request, and assign the new launch result to that reference. Keep the existing generation and identity fences unchanged so cancellation remains an optimization rather than the sole stale-result protection.
1166-1215: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCall
resolveEpisodeSubtitleIntentdirectly to avoid resolving the source twice.Line 1174 already calls
resolveEpisodeSourceIntent.resolveEpisodeSelectionHandoffat Line 1196 resolves the source again over the samedetail.versions, and only its subtitle fields are consumed. The results agree, so this is duplicated pure work rather than a defect. Calling the subtitle resolver directly makes the data flow explicit.♻️ Suggested change
- val carried = resolveEpisodeSelectionHandoff( - handoff = handoff, - targetVersions = detail.versions, - targetSubtitles = targetSubtitleChoices, - ) + val carried = resolveEpisodeSubtitleIntent( + intent = handoff?.subtitle ?: EpisodeSubtitleIntent.auto(), + targetSubtitles = targetSubtitleChoices, + )This also requires swapping the
resolveEpisodeSelectionHandoffimport forresolveEpisodeSubtitleIntentandEpisodeSubtitleIntent, and readingcarried.intentSpecified/carried.trackIndexinstead of thesubtitle*names.🤖 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 `@androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailViewModel.kt` around lines 1166 - 1215, In resolveNextUpTrackSelection, replace the resolveEpisodeSelectionHandoff call with direct resolveEpisodeSubtitleIntent using the existing handoff subtitle data and targetSubtitles, avoiding a second source-resolution pass. Update imports to use resolveEpisodeSubtitleIntent and EpisodeSubtitleIntent, and read carried.intentSpecified and carried.trackIndex when selecting subtitleIndex.android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/video/EpisodeSelectionHandoffTest.kt (1)
318-321: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a valid-payload round-trip test.
The suite tests encoding and malformed decoding, but it does not test that a valid encoded payload decodes back to an equal handoff. The
Jsonconfiguration usesencodeDefaults = falseandexplicitNulls = false, so an omittedsubtitleobject must still restoreEpisodeSubtitleIntent.auto(). A round-trip test locks that wire contract.♻️ Suggested additional test
`@Test` fun encodedPayloadRoundTripsSemanticIntent() { val handoff = EpisodeSelectionHandoff( source = captureEpisodeSourceIntent(version(101, "2160p", "hevc", hdr = true, container = "mkv")), subtitle = EpisodeSubtitleIntent( mode = EpisodeSubtitleMode.TRACK, language = "en", codecFamily = "subrip", external = true, ), ) assertEquals(handoff, decodeEpisodeSelectionHandoff(encodeEpisodeSelectionHandoff(handoff))) assertEquals( EpisodeSubtitleIntent.auto(), decodeEpisodeSelectionHandoff("{}")?.subtitle, ) }🤖 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 `@android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/video/EpisodeSelectionHandoffTest.kt` around lines 318 - 321, Add a valid-payload round-trip test alongside malformedPayloadDecodesToNull that constructs an EpisodeSelectionHandoff with representative source and subtitle intents, encodes it with encodeEpisodeSelectionHandoff, and asserts decodeEpisodeSelectionHandoff returns an equal handoff. Also assert that decoding "{}" restores EpisodeSubtitleIntent.auto() when the optional subtitle payload is omitted.androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvNextUpSelectionHandoffTest.kt (1)
781-782: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueEmit JSON null for absent codec and container.
VersionFixture.codecandcontainerare nullable, butversionJsoninterpolates them inside quotes. A null value becomes the literal string"null", not JSON null.normalizedEpisodeTokenthen returns"null"instead of null, so a future test that passescodec = nullwould silently exercise a codec match rather than an absent codec. Every current call site uses the non-null defaults, so this is latent only.♻️ Suggested change
- private fun versionJson(version: VersionFixture): String = - """{"file_id":${version.fileId},"resolution":"${version.resolution}","codec_video":"${version.codec}","container":"${version.container}","subtitle_tracks":[${version.subtitles.joinToString(",", transform = ::subtitleJson)}],"audio_tracks":[${version.audio.joinToString(",", transform = ::audioJson)}]}""" + private fun jsonString(value: String?): String = value?.let { "\"$it\"" } ?: "null" + + private fun versionJson(version: VersionFixture): String = + """{"file_id":${version.fileId},"resolution":"${version.resolution}","codec_video":${jsonString(version.codec)},"container":${jsonString(version.container)},"subtitle_tracks":[${version.subtitles.joinToString(",", transform = ::subtitleJson)}],"audio_tracks":[${version.audio.joinToString(",", transform = ::audioJson)}]}"""🤖 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 `@androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvNextUpSelectionHandoffTest.kt` around lines 781 - 782, Update versionJson to serialize nullable VersionFixture.codec and VersionFixture.container as JSON null when absent, while retaining quoted JSON strings for non-null values; ensure normalizedEpisodeToken receives actual null rather than the literal "null".
🤖 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.
Inline comments:
In
`@androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/components/TvSelectorRowVisualStateTest.kt`:
- Around line 10-36: Remove the UI-only test class TvSelectorRowVisualStateTest
and the source-structure test TvHudPickerFocusWiringSourceTest; no replacement
tests are required.
In
`@androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvNextUpSelectionHandoffTest.kt`:
- Around line 554-560: Make the plain state polled by awaitCondition safely
visible across dispatchers: update episodeTwoRequests,
pendingEpisodeOneResponses, episodeOneResponses, FakeTokenManager.snapshotCalls,
and RecordingUserItemState.startedReads to use volatile or atomic counters, and
protect startedReads with a concurrent or synchronized set. Preserve the
existing polling behavior and MutableStateFlow handling.
---
Nitpick comments:
In
`@android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/video/EpisodeSelectionHandoffTest.kt`:
- Around line 318-321: Add a valid-payload round-trip test alongside
malformedPayloadDecodesToNull that constructs an EpisodeSelectionHandoff with
representative source and subtitle intents, encodes it with
encodeEpisodeSelectionHandoff, and asserts decodeEpisodeSelectionHandoff returns
an equal handoff. Also assert that decoding "{}" restores
EpisodeSubtitleIntent.auto() when the optional subtitle payload is omitted.
In
`@androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailViewModel.kt`:
- Around line 1143-1164: Add a concise comment in captureNextUpSelectionHandoff
at the EpisodeSelectionHandoff call site documenting that source uses
selectedVersion only for explicit source intent, while subtitle uses
activeVersion to reflect the displayed version; preserve the distinct locals and
behavior covered by the existing regression tests.
- Around line 1001-1034: Update loadNextUpPlaybackDetail to retain its launched
coroutine in a nextUpDetailJob reference, cancel the existing job before
starting a new request, and assign the new launch result to that reference. Keep
the existing generation and identity fences unchanged so cancellation remains an
optimization rather than the sole stale-result protection.
- Around line 1166-1215: In resolveNextUpTrackSelection, replace the
resolveEpisodeSelectionHandoff call with direct resolveEpisodeSubtitleIntent
using the existing handoff subtitle data and targetSubtitles, avoiding a second
source-resolution pass. Update imports to use resolveEpisodeSubtitleIntent and
EpisodeSubtitleIntent, and read carried.intentSpecified and carried.trackIndex
when selecting subtitleIndex.
In
`@androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvNextUpSelectionHandoffTest.kt`:
- Around line 781-782: Update versionJson to serialize nullable
VersionFixture.codec and VersionFixture.container as JSON null when absent,
while retaining quoted JSON strings for non-null values; ensure
normalizedEpisodeToken receives actual null rather than the literal "null".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d632c78a-57f5-4aef-955d-5df9c101b3c2
📒 Files selected for processing (27)
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/EpisodeSelectionHandoff.ktandroid-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/VideoPlaybackSessionCoordinator.ktandroid-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/VideoPlaybackStartRequest.ktandroid-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/VideoPlaybackStartResult.ktandroid-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/VideoPlayerUiState.ktandroid-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/video/EpisodeSelectionHandoffTest.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/di/AndroidTvModule.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvAnchoredSelectorMenu.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvSelectorRowVisualState.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/navigation/TvAppNavigation.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/navigation/TvRoute.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailViewModel.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvPlaybackSelectorRow.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerHud.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerScreen.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvVideoPlaybackStarter.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/components/TvSelectorRowVisualStateTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/navigation/TvPlayerRouteTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailSubtitlePreferenceTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvNextUpSelectionHandoffTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvTrackSelectionPersistenceTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/player/TvEpisodeHandoffPlaybackStartTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/player/TvHudPickerFocusWiringSourceTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayNextSelectionHandoffTest.ktdocs/superpowers/plans/2026-08-01-fire-tv-playback-selection-ux.mddocs/superpowers/specs/2026-07-31-fire-tv-playback-selection-ux-design.md
Summary
This fixes three related Android TV playback-selection defects:
Behavior decisions
lastFileIdand preferred quality.(server, profile, contentId, fileId)and are written only through existing explicit selector callbacks. Watch Together suppression and playback shutdown ordering are unchanged.Security and privacy boundary
The serialized handoff contains semantic resolution/codec/dynamic-range/container and subtitle language/accessibility/source/format intent only. It contains no file IDs, download IDs, track IDs or indexes, filenames, paths, credentials, tokens, or server URLs. The handoff is process/session scoped and is fenced across target generation and server/profile identity changes.
Verification
git diff --check upstream/main...HEAD— passed../scripts/test-check-build-supply-chain.sh— passed (All supply-chain policy self-tests passed)../scripts/check-build-supply-chain.sh— passed and changed no tracked/staged verification metadata../gradlew --no-daemon --max-workers=2 :android-shared:testDebugUnitTest :androidTvApp:testDebugUnitTest— passed; the initial complete gate wasBUILD SUCCESSFUL in 17s../gradlew --no-daemon --max-workers=2 :androidTvApp:assembleDebug :androidTvApp:assembleRelease -PallowDebugReleaseSigning=true— passed;BUILD SUCCESSFUL in 2m 22s../gradlew --no-daemon --max-workers=2 :android-shared:testDebugUnitTest :androidTvApp:testDebugUnitTest :androidTvApp:assembleRelease -PallowDebugReleaseSigning=true— passed;BUILD SUCCESSFUL in 1m 50s.Emulator limitation
Live D-pad smoke was not feasible under current authorization.
adb devices -llisted only a physical NVIDIA Shield (192.168.1.128:5555), which was not queried, installed to, or otherwise touched. A dedicatedSilo_TVAVD exists but was not running, so the exact current feature build was not already installed on a dedicated emulator. No older installed build is being claimed as validation.Scope
Production changes are limited to
android-sharedandandroidTvApp. There are no Android phone production, server, API, schema, database, proxy, or production-configuration changes. Phone and server behavior are unchanged.Summary by CodeRabbit