Repository navigation
Conversation
Switch Profile on Android TV replaced the whole back stack with Who's watching and cleared the profile, so Back closed the app. Back on that picker now reopens the same profile with the proof it already had (no PIN prompt) on the page the switch started from. The launch picker, and a picker found after leaving the app, still close the app on Back. Closes #917 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A profile edited or deleted in Manage mode may no longer match the proof the switch kept, so entering Manage drops the way back, and Back in Manage mode no longer reopens the closed profile. The close-again fallback also skips a cast identity, whose id isn't this TV's profile. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
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:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| // switched or a cast identity installed since makes this ScopeChanged. | ||
| val result = profileRepository.selectProfile(back.profileId, back.profileToken, back.clearedScope) | ||
| if (result != ProfileCommitResult.Committed) return@launch | ||
| if (revision != foregroundRevision || navController.currentBackStackEntry?.id != back.pickerEntryId) { |
There was a problem hiding this comment.
Profile-switch cancellation can navigate after losing identity ownership
An identity transition after selectProfile commits can cause navigation and content seeding for a replacement identity. Capture the committed authentication generation and validate it against the current authority before navigating or publishing related side effects.
Also found in:
androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/navigation/TvAppNavigation.kt:635-635
Kody rule violation: Revalidate asynchronous ownership before publication, launch, and cleanup
Prompt for LLM
File androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/navigation/TvAppNavigation.kt, line 630:
Profile-switch cancellation can navigate after losing identity ownership
Also verify that the committed profile selection still owns the current authentication generation immediately before entering Main. `selectProfile` suspends, and another identity transition can occur after it commits while the foreground revision and picker entry remain unchanged; in that case this callback can navigate and seed content for a replacement identity. Capture the committed generation and validate it against the current authority before publishing navigation and related side effects.
**Also found in:**
- `androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/navigation/TvAppNavigation.kt:635-635`
Kody rule violation: [Revalidate asynchronous ownership before publication, launch, and cleanup](https://kodus.siloserver.org/settings/code-review/1247142403/kody-rules/8ee8ffaf-7856-4c08-a084-f52e4c5e5f57?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)
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.
🤖 Claude Code (claude-opus-5-5)
Fixed by 560f3ba on this branch. After selectProfile commits, Back enters Main only while the live identity is still that commit's own: the same server and profile, the generation exactly one past the switch's clear, and no remote-playback identity. Otherwise it neither enters nor clears. 6706144 also fences the undo clear to the scope that commit left, so it can't reach an identity that replaced it.
There was a problem hiding this comment.
Thanks for the update. The fix keeps Back scoped to the identity created by the profile switch, and the undo clear is likewise fenced so it cannot clear a replacement identity.
| val pickerEntryId = navController.currentBackStackEntry?.id | ||
| activeProfileReset.clearActiveProfile() | ||
| val cleared = tokenManager.snapshotCurrentScope() |
There was a problem hiding this comment.
Back remains unhandled while the profile reset is in progress
Pressing Back while clearActiveProfile() is suspended can still exit the app. Install the Back handler before displaying the picker and defer cancellation until the reset completes.
Prompt for LLM
File androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/navigation/TvAppNavigation.kt, lines 1571-1573:
Back remains unhandled while the profile reset is in progress
The picker is displayed before the suspending profile reset finishes and before its Back handler is installed, so pressing Back during that interval still exits the app. Install a handler before displaying the picker and defer cancellation until the reset completes.
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.
🤖 Claude Code (claude-opus-5-5)
Fixed by 560f3ba and 6706144. The picker handles Back from the moment Switch Profile opens it. A press during the clear reopens the profile once the clear finishes, and a navigation-level handler covers the frames before the picker registers its own. On an Android TV emulator, Switch Profile followed by Back about 300 ms later now returns to the page it came from three out of three times, where it had closed Silo before.
There was a problem hiding this comment.
Thanks for the update. Commits 560f3ba18 and 6706144ee reportedly address the Back-handling gap, and the emulator check passed three out of three attempts. I haven’t independently verified the fix.
| switchReturn = TvProfileSwitchReturn( | ||
| profileId = closing.profileId!!, | ||
| profileToken = closing.profileToken, | ||
| clearedScope = cleared, | ||
| shellRoute = shellRoute, | ||
| pickerEntryId = pickerEntryId, | ||
| ) |
There was a problem hiding this comment.
In-flight switch can restore the return path after Manage starts
Manage can invalidate switchReturn while clearActiveProfile() is suspended, allowing the reset to reinstate an old profile proof. Prevent publication after Manage starts, including when Add Profile opens directly from the picker.
Prompt for LLM
File androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/navigation/TvAppNavigation.kt, lines 1581-1587:
In-flight switch can restore the return path after Manage starts
Manage mode can start while `clearActiveProfile()` is suspended, before `switchReturn` is published, so its invalidation runs too early and the completed reset reinstates the old profile proof. Prevent publishing the return after Manage has started, including when Add Profile opens directly from the picker.
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.
🤖 Claude Code (claude-opus-5-5)
Fixed by 560f3ba. The switch reads a revision before it starts, and entering Manage bumps it, so a clear that finishes after Manage started doesn't publish a way back.
Add Profile straight from the picker keeps the way back on purpose. Creating a profile doesn't change the closed profile or its proof, and Back from the new-profile form returns to the picker, where Back still cancels the switch.
There was a problem hiding this comment.
The revision check addresses the reported race: if Manage starts while the profile clear is in flight, the switch should no longer publish the return path.
Keeping the return path when Add Profile opens directly from the picker is a deliberate distinction. If Back from the form returns to the picker without changing the closed profile or its proof, the next Back can still cancel the switch.
I haven’t independently verified commit 560f3ba18 or those navigation paths.
| val switchProfileFromHere: () -> Unit = { | ||
| onSwitchProfile(currentRoute.takeIf { '{' !in it }) |
There was a problem hiding this comment.
Switch Profile loses parameterized originating screens
Back reopens Home instead of the originating screen when currentRoute is parameterized. Preserve the destination arguments and reconstruct the route when restoring the shell.
Prompt for LLM
File androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/shell/TvMainShell.kt, lines 790-791:
Switch Profile loses parameterized originating screens
Switching from a parameterized destination such as request detail discards its route, so Back reopens Home instead of the screen the user came from. Preserve the concrete destination arguments and reconstruct the route when restoring the shell.
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.
🤖 Claude Code (claude-opus-5-5)
This is a known limit, listed under Risks in the PR body. A page whose route carries arguments (a request's detail page, for example) reopens on Home, because rebuilding it needs the original arguments, not just the route pattern. Those pages are rare places to start Switch Profile from, so this PR leaves it; a fuller restore can follow if it turns out to matter.
There was a problem hiding this comment.
Understood. The Home fallback for parameterized routes is an intentional, documented limitation of this PR. I’ll withdraw the suggestion as a required change; restoring those destinations can be considered as a follow-up if it becomes important.
Back on the picker waits while Switch Profile is still closing the profile instead of leaving the app. Manage mode, or Silo leaving the foreground, now also stops a switch still in flight from saving a way back. Back's reopen and its undo run to the end even if the screen is torn down, and only enter or undo the profile while the reopen's own commit is still the live identity. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Quick104
left a comment
There was a problem hiding this comment.
🤖 Claude Code (claude-opus-5-5)
Maintainer review of a32e0f0. The approach matches the Apple TV fix and I'm keeping it. Four findings below. I'm fixing all of them in commits on this branch, so there's no need to change anything yourself. A summary with scores follows once the fixes are pushed and checked on an emulator.
A second Back while Back was reopening the profile reached the system and closed Silo, because the picker stopped handling Back as soon as the reopen started. The picker now handles Back from the moment Switch Profile opens it until the reopen finishes: a press during the clear runs once the way back exists, and further presses wait for the reopen. A handler registered at the navigation level also covers the frames after Main's handlers go and before the picker registers its own, where a quick Back closed Silo. Undoing a reopen that is no longer wanted now clears the profile only while the reopen's own selection is still the live identity, through an optional expected-scope fence on ProfileRepository.clearProfile, like selectProfile's. A second Switch Profile press while one is running is ignored, and entering any profile drops the way back and its proof. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
Main starts on Home and only then opens the page a cancelled switch restores. A Back in those first frames reached the system and closed Silo, so a quick double Back on the picker still could. Main now reports the restored page once it has composed, and Back is held until then. A fenced clear that its scope no longer allows now returns before the identity transition starts, as clearStaleProfile does, so the identity that replaced it sees no gates. A Back pressed during the clear is replayed only while the picker is still showing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
| // no screen does. It also holds Back while a cancelled switch re-enters | ||
| // Main, until Main reports the restored page is showing. | ||
| BackHandler(enabled = reenteringMain || (switchState != null && switchState?.pickerEntryId == currentEntry?.id)) { | ||
| if (!reenteringMain) onSwitchPickerBack() |
There was a problem hiding this comment.
Restoration Back hold loses priority to the shell's handlers
Later-registered shell handlers can process a second Back on the initial Home frame before the restored page is ready. Suppress the shell and nested navigation Back handlers during restoration, or register BackHandler at a higher priority.
Prompt for LLM
File androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/navigation/TvAppNavigation.kt, lines 1105-1108:
Restoration Back hold loses priority to the shell's handlers
The hold is registered before the nested shell's Back handlers, so those later handlers take priority and can process a second Back on the initial Home frame before the restored page is ready. Suppress the shell and nested navigation Back handlers during restoration or register the hold at a higher priority.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
|
🤖 Claude Code (claude-opus-5-5) Maintainer review summaryReviewed head: Fit: 8/10 · Readiness: 9/10 — conditional (assuming CI is green)
Addressed in this review
Open for the maintainers
Checks
|
Problem
On Android TV, choosing Switch Profile (from the profile menu or from Settings' profile row) and then pressing Back on Who's watching? closed Silo. Back is supposed to return to the screen the picker was opened from. The switch replaced the whole back stack with the picker and closed the open profile, so the picker was the only screen left and Back went to the system.
Closes #917
Related issue: Silo-Server/silo-apple#1200 (the Apple TV fix for the same bug)
Validation tasks: unblocks #320 C6 (Android TV: Back returns to the previous usable screen)
Other clients: Apple Silo-Server/silo-apple#1200; Roku N/A (its picker is pushed over the open profile, and Back already returns to it); Web N/A (no remote Back that closes the app)
Approach
Back on a picker that Switch Profile opened now cancels the switch. As decided for the Apple fix, it reopens the same profile with the proof it already had (no PIN prompt), on the page the switch started from. Android TV only.
ProfileRepository.selectProfile, fenced to the scope the switch's clear left. A profile chosen, an account switched or a cast identity installed since makes it fail, and the picker stays. It then runs the same steps as choosing a tile, and also reloads card overlays and card presentation, which the switch had cleared. If Silo left the foreground or the picker went while the profile reopened, the reopen is undone with a clear fenced to the reopen's own scope:ProfileRepository.clearProfiletakes an optional expected scope, checked before the identity transition (asclearStaleProfiledoes, so a rejected clear fires no gates) and again inside it, so the undo can't reach an identity that replaced it. Existing callers pass none and behave as before.savedStateHandlehand-off that Manage Servers already uses. Pages whose routes have arguments reopen on Home.The phone app does not have this bug. It opens its picker over the current screen without closing the profile, and Back already returns there. Checked on unfixed
main(see Validation), so the phone is unchanged.Validation
Target: a Silo dev deployment built from silo-server
main, with an account holding three profiles ("qa917", "Kids", and "Locked" with a PIN), Profile Selection set to Ask Every Time. Debug builds on an Android TV 1080p emulator and a Pixel 7 emulator, both API 36.main(40d34e6d9). Signed in as "Locked" on Calendar, profile menu → Switch Profile → Back closed Silo; the foreground activity became the TV launcher. Settings → profile row → Back did the same.6091fb9e6, and the main flow again ona32e0f01a). The same steps return to Calendar and to Settings as "Locked", with no PIN prompt. Focus lands on the page (the Following filter on Calendar, General in Settings). Movies → Switch Profile → Back returns to Movies, and For You to For You, with focus on the first card.fa9424500, on a fresh sandbox from silo-servermain, Android TV 1080p emulator, API 36). Before them, two Backs sent in the same instant on the picker closed Silo, and so did Switch Profile followed by Back about 300 ms later (three runs out of three). After: both return to Calendar as "Locked" in every checked run (fifteen double-Back trials at the final build), and so does Settings' profile row. After a restore, Back walks Calendar → bar → Home and then closes Silo as before. Single Back, the PIN pad, Change account, Manage, leaving with Home, and the launch picker behave as listed below. A Back injected in the same millisecond as Switch Profile still closed Silo in one of two runs; a remote can't send presses that close together.main: Calendar → Switch profile → Back returns to Calendar as the same profile. Tablet and foldable run the same phone navigation, which this PR doesn't change.:androidTvApp:assembleDebugbuilds,:androidTvApp:testDebugUnitTestpasses, and:androidApp:compileDebugKotlinbuilds against the shared change. One test added, for the shared fence:ProfileRepositoryTestchecks that a fenced clear leaves an identity that replaced its scope, without starting an identity transition, and clears when the scope still holds. It fails on6706144ee, where the rejected clear still started a transition. The TV navigation itself has no tests, per the repository's testing rules.Evidence: https://evidence.siloserver.org/r/silo-android/issue-917/
Risks
Follow-ups
maindoes the same from the launch picker, so this PR leaves it alone.Council review
Rounds: 2, last reviewed 6706144;
fa9424500answers round 2Fixed: Back handled through the whole switch and while Main re-enters (double Back, fast Back, Back during the clear), a fenced undo that doesn't start a transition when rejected (all three members raised it in round 2), a guard against a second Switch Profile press, the way back dropped when a profile is entered, and a queued Back replayed only while the picker is showing. Answered: a token refresh doesn't break the fence (the interceptor's refresh leaves the credential epoch alone), the
NonCancellablereopen can't be discarded between its check and entering Main, and the SiloCast standby overlay takes no Back on any screen. Left for the maintainer: pushing the picker over Main instead of clearing first.AI Disclosure
560f3ba18, and the later commits) by Claude Code (claude-opus-5-5) in maintainer review sessions.a32e0f0returned two findings, fixed in560f3ba18. The maintainer review's code review (three finders and a validation check) and two council rounds are summarized under Council review.🤖 Generated with Claude Code