fix(tv): restore Shield focus navigation - #164
Conversation
|
Warning Review limit reached
Next review available in: 50 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe Android TV focus system now restores recommendation cards after detail returns, preserves the For You top anchor, routes Calendar control focus explicitly, and manages Diagnostics directional navigation with bounded retries. Recommendation sections now use stable metadata-based identities. ChangesAndroid TV focus restoration
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant TvMainShell
participant TvRecommendationsScreen
participant TvRecommendationsFocusBridge
participant TvMediaRow
TvMainShell->>TvRecommendationsScreen: start detail-return request
TvRecommendationsScreen->>TvRecommendationsFocusBridge: resolve stable recommendation target
TvRecommendationsFocusBridge->>TvMediaRow: prepare row and card restoration
TvMediaRow-->>TvRecommendationsScreen: report placement or disposal
TvRecommendationsScreen->>TvRecommendationsFocusBridge: retry focus within frame bound
TvRecommendationsFocusBridge-->>TvMainShell: consume completed return request
Possibly related PRs
🚥 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: 3
🤖 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/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/diagnostics/TvDiagnosticsSettingsScreen.kt`:
- Around line 238-246: Update tvDiagnosticsCrashFocusRequestResult so
Result.failure is classified as RETRY rather than DISPOSED, allowing transient
FocusRequester attachment failures to continue the bounded retry. Preserve
FOCUSED for successful true results, and update
failedFocusRequestIsTerminalBecauseTheScreenWasDisposed to expect RETRY for
transient detach failures; handle actual disposal through the existing
structured-concurrency path.
In
`@androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/shell/TvMainShell.kt`:
- Around line 356-362: Update the Home detail-return state around
detailReturnFallback and the LifecycleResumeEffect retry flow so the Home focus
requester remains selected until the retry consumes it. Defer clearing
restoreHomeContentAfterDetail, or introduce and maintain a Home-specific pending
flag matching forYouDetailReturnFocusPending, ensuring a failed synchronous
resume request still targets homeDetailReturnCardFocusRequester.
In
`@shared/src/commonMain/kotlin/org/siloserver/silo/viewmodel/RecommendationsViewModel.kt`:
- Around line 119-122: Update DiscoverRow.stableSectionId() to use the kind/key
identity only when both sectionKind and sectionKey are nonblank; otherwise
retain the existing type/label fallback. Add a regression test covering two rows
with the same sectionKind and absent sectionKey, verifying they use the fallback
identity rather than the shared kind/key form.
🪄 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: cdafafbd-b1e9-47b2-904f-94aa0949ba2f
📒 Files selected for processing (18)
androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvMediaRow.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/calendar/TvCalendarScreen.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/recommendations/TvRecommendationsFocusBridge.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/recommendations/TvRecommendationsScreen.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/diagnostics/TvDiagnosticsSettingsScreen.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/shell/TvMainShell.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/components/TvMediaRowFocusRestoreTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/calendar/TvCalendarFocusRoutingTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/recommendations/TvRecommendationsFocusBridgeTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/recommendations/TvRecommendationsTopAnchorTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/settings/diagnostics/TvDiagnosticsStateTest.ktdocs/superpowers/plans/2026-08-03-for-you-late-focus-relocation.mddocs/superpowers/plans/2026-08-03-shield-focus-restoration.mddocs/superpowers/specs/2026-08-03-for-you-late-focus-relocation-design.mddocs/superpowers/specs/2026-08-03-shield-focus-restoration-design.mdshared/src/commonMain/kotlin/org/siloserver/silo/model/recommendation/RecommendationModels.ktshared/src/commonMain/kotlin/org/siloserver/silo/viewmodel/RecommendationsViewModel.ktshared/src/commonTest/kotlin/org/siloserver/silo/viewmodel/RecommendationsSectionIdentityTest.kt
| private fun DiscoverRow.stableSectionId(): String = | ||
| sectionKind?.takeIf { it.isNotBlank() }?.let { kind -> | ||
| "discover:kind=$kind:key=${sectionKey.orEmpty()}" | ||
| } ?: "discover:type=$type:label=$label" |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Prevent IDs from colliding when sectionKey is absent.
sectionKey is optional. Two rows with the same sectionKind and no key both receive discover:kind=<kind>:key=. This breaks the stable-section identity contract and can restore focus to the wrong row after a refresh.
Use the sectionKind and sectionKey form only when both values are nonblank. Otherwise, fall back to the existing type and label identity. Add a regression test with two same-kind rows that omit sectionKey.
Proposed fix
-private fun DiscoverRow.stableSectionId(): String =
- sectionKind?.takeIf { it.isNotBlank() }?.let { kind ->
- "discover:kind=$kind:key=${sectionKey.orEmpty()}"
- } ?: "discover:type=$type:label=$label"
+private fun DiscoverRow.stableSectionId(): String {
+ val kind = sectionKind?.takeIf { it.isNotBlank() }
+ val key = sectionKey?.takeIf { it.isNotBlank() }
+ return if (kind != null && key != null) {
+ "discover:kind=$kind:key=$key"
+ } else {
+ "discover:type=$type:label=$label"
+ }
+}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| private fun DiscoverRow.stableSectionId(): String = | |
| sectionKind?.takeIf { it.isNotBlank() }?.let { kind -> | |
| "discover:kind=$kind:key=${sectionKey.orEmpty()}" | |
| } ?: "discover:type=$type:label=$label" | |
| private fun DiscoverRow.stableSectionId(): String { | |
| val kind = sectionKind?.takeIf { it.isNotBlank() } | |
| val key = sectionKey?.takeIf { it.isNotBlank() } | |
| return if (kind != null && key != null) { | |
| "discover:kind=$kind:key=$key" | |
| } else { | |
| "discover:type=$type:label=$label" | |
| } | |
| } |
🤖 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
`@shared/src/commonMain/kotlin/org/siloserver/silo/viewmodel/RecommendationsViewModel.kt`
around lines 119 - 122, Update DiscoverRow.stableSectionId() to use the kind/key
identity only when both sectionKind and sectionKey are nonblank; otherwise
retain the existing type/label fallback. Add a regression test covering two rows
with the same sectionKind and absent sectionKey, verifying they use the fallback
identity rather than the shared kind/key form.
Code reviewFound 5 issues (1 blocking, 4 lower confidence): 1. Calendar held-Up freezes mid-list — the
The branch above it already handles the boundary case inline ( This also breaks the PR's own stated Global Constraint in
2. Diagnostics Up is a one-way door Up clamps ( 3. The old Requires an older server emitting two rows sharing both type and label. 4. For You copies Home's detail-return state but not Home's reset The comment on L609-613 states why Home clears its token on explicit reselect (added by 5. Introduced and unit-tested as the encoding of the empty-feed fallback rule, but Checked and clear:
Minor: every checkbox in 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/shell/TvDetailReturnFocusStateTest.kt (1)
37-48: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the Home-return branch of
beginHomeDetailReturnRetryIfHome.
TvMainShell.kt(Lines 378-426) calls this conditional helper, but the test only coversisHomeDetailReturn = false. Add a Home-return case that verifies the request ID increments andfallbackPendingis true whenneedsRetryis true. Also coverneedsRetry = falseif immediate clearing is part of the contract.Suggested regression test
+ `@Test` + fun homeRetryArmsHomeFallback() { + val state = beginHomeDetailReturnRetryIfHome( + previousState = HomeDetailReturnFocusState(requestId = 7), + isHomeDetailReturn = true, + needsRetry = true, + ) + + assertEquals(8, state.requestId) + assertTrue(state.needsRetry) + assertTrue(state.fallbackPending) + }As per coding guidelines, add focused tests for shared logic only when behavior is critical or high risk.
🤖 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/shell/TvDetailReturnFocusStateTest.kt` around lines 37 - 48, Extend TvDetailReturnFocusStateTest around beginHomeDetailReturnRetryIfHome with a Home-return case using isHomeDetailReturn = true and needsRetry = true, asserting the request ID increments and fallbackPending becomes true while retry remains active. Also add the needsRetry = false Home-return case if the helper’s contract clears state immediately, preserving the existing non-home coverage.Source: Coding guidelines
docs/superpowers/plans/2026-08-04-pr-164-review-remediation.md (1)
33-82: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMark completed plan steps as complete.
The document says checkbox syntax tracks execution, but the implementation and validation steps remain
- [ ]. The PR objectives report that the remediation commits and automated checks passed. Mark completed steps as- [x]and leave only pending work, such as the Shield D-pad smoke gate, unchecked. This prevents agents from treating completed work as unfinished.Also applies to: 94-147, 162-269, 282-326, 337-391
🤖 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 `@docs/superpowers/plans/2026-08-04-pr-164-review-remediation.md` around lines 33 - 82, Update the remediation plan checkboxes for all completed implementation, test, validation, and commit steps across the referenced sections from “- [ ]” to “- [x]”. Leave only genuinely pending work, such as the Shield D-pad smoke gate, unchecked so agents do not repeat completed tasks.
🤖 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.
Nitpick comments:
In
`@androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/shell/TvDetailReturnFocusStateTest.kt`:
- Around line 37-48: Extend TvDetailReturnFocusStateTest around
beginHomeDetailReturnRetryIfHome with a Home-return case using
isHomeDetailReturn = true and needsRetry = true, asserting the request ID
increments and fallbackPending becomes true while retry remains active. Also add
the needsRetry = false Home-return case if the helper’s contract clears state
immediately, preserving the existing non-home coverage.
In `@docs/superpowers/plans/2026-08-04-pr-164-review-remediation.md`:
- Around line 33-82: Update the remediation plan checkboxes for all completed
implementation, test, validation, and commit steps across the referenced
sections from “- [ ]” to “- [x]”. Leave only genuinely pending work, such as the
Shield D-pad smoke gate, unchecked so agents do not repeat completed tasks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3c2b833e-c368-4c2a-8fee-6d99c9f9816f
📒 Files selected for processing (11)
androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/calendar/TvCalendarScreen.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/recommendations/TvRecommendationsFocusBridge.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/diagnostics/TvDiagnosticsSettingsScreen.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/shell/TvDetailReturnFocusState.ktandroidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/shell/TvMainShell.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/calendar/TvCalendarFocusRoutingTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/recommendations/TvRecommendationsFocusBridgeTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/settings/diagnostics/TvDiagnosticsStateTest.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/shell/TvDetailReturnFocusStateTest.ktdocs/superpowers/plans/2026-08-04-pr-164-review-remediation.mddocs/superpowers/specs/2026-08-04-pr-164-review-remediation-design.md
🚧 Files skipped from review as they are similar to previous changes (7)
- androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/diagnostics/TvDiagnosticsSettingsScreen.kt
- androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/settings/diagnostics/TvDiagnosticsStateTest.kt
- androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/recommendations/TvRecommendationsFocusBridgeTest.kt
- androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/recommendations/TvRecommendationsFocusBridge.kt
- androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/calendar/TvCalendarFocusRoutingTest.kt
- androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/shell/TvMainShell.kt
- androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/calendar/TvCalendarScreen.kt
|
Fixed both follow-up nitpicks in
Validation: |
|
Closing as superseded — everything here is already on Checked against
So the focus-restoration work landed through other PRs, and rebasing 108 commits of already-merged history would gain nothing. Reopen or re-cut from current |
Summary
Watchlist remains inside For You. Its behavior, navigation, layout, rendering, and generic detail callback are unchanged.
This PR includes and supersedes #162.
Verification
Device follow-up
The APK was built but was not installed or launched during this branch pass. Shield Pro focus and visual smoke checks remain the post-PR release gate.
Summary by CodeRabbit
Improvements
Tests