Skip to content

fix(tvos): return to the previous screen on Back from Switch Profile - #1200

Merged
Quick104 merged 4 commits into
mainfrom
fix/silo-issue-1164
Nov 16, 2026
Merged

Quick104 merged 4 commits into
mainfrom
fix/silo-issue-1164

Conversation

@Quick104

@Quick104 Quick104 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #1164
Related issue: N/A
Validation tasks: unblocks #310 C6; changes #310 C2, #310 C5, #304 C3, #308 C5, #333 C2, #335 C2 (minor: these switch profiles, and choosing a profile works as before; the picker opened from Settings now starts with a profile focused)

Other clients: Android Silo-Server/silo-android#917; Roku N/A (Roku's picker is pushed over the open profile, and Back already returns to it); Web N/A (no remote Back that closes the app)

On Apple TV, choosing Switch Profile and then pressing Back (Menu) on Who's watching? closed the app. Back is supposed to return to the screen the picker was opened from. The switch closes the open profile and replaces the whole tab shell with the picker. The picker had no Back handler, so Menu went to tvOS.

Opened from Settings, the picker also started with nothing focused, so Back went to tvOS even once the picker could handle it.

Approach

Back on a picker that Switch Profile opened now cancels the switch. As decided for this issue, it reopens the same profile with the proof it already had (no PIN prompt), on the same page. This is Apple TV only.

  • AppRouter.switchProfile() captures the open profile (AuthService.openProfileForSwitch), the pushed screens (the existing SessionReturnPoint) and the shell page (TVShellPlace: tab, Watchlist/Favorites/Requests page, library section). It keeps them in memory while that picker is up. The switch still marks selection required and closes the profile as before. Quitting on the picker still shows it at the next launch.
  • ProfileSelectionView handles Menu only while that return exists and nothing is pushed over the picker. On any other picker, including the one at launch, Menu still goes to tvOS.
  • AppRouter.cancelProfileSwitch() reopens the profile through AuthService.reopenProfile. That reuses the existing activateProfile commit: HTTP identity barrier, cache reset, Top Shelf mirror, remembered profile, selection-required cleared. The commit is fenced in the token store against a different account and against any profile opened since the switch. It then runs the same capability refresh as a profile selection and goes back through resetToHome(), which already restores pushed screens for the same owner. TVMainTabView starts on the saved page. Player settings refresh in the background afterwards.
  • The switch swaps to the picker without the stack crossfade, as the account flows already do, so the picker opened from Settings gets focus.

The way back is dropped when:

  • any route change happens, including another account's picker;
  • the app goes to the background, so a picker found later needs a profile choice and its PIN again (a switch or Back still in flight then gives up too, and a profile already reopened is closed again);
  • the reopen fails (the picker stays, takes focus again, and Back goes to tvOS).

Back is ignored while the picker is opening a profile, checking a PIN, lending the primary profile to Add Profile, or showing the remember offer.

Validation

  • Reproduced on unfixed main (8ba9c514) on an Apple TV 4K simulator against a Silo dev deployment built from silo-server main. The account had three profiles, one with a PIN. Movies → profile menu → Switch Profile → Menu closed the app. Settings → profile row → Menu did the same, and that picker showed nothing focused.
  • On the fix (06e1db46), the same steps returned to Movies and to Settings as the same profile, with focus on the page.
  • A PIN profile opened on Series came back to Series with no PIN prompt. The server log showed one PIN check (the one typed) and no 4xx responses.
  • Unchanged behavior, checked live:
    • Menu on the launch picker still closes the app.
    • Leaving the app on the Switch Profile picker and coming back leaves Menu closing the app.
    • Menu on the PIN pad closes only the PIN pad.
    • Change Account → Menu returns to the picker.
    • Quitting on the picker shows it again at the next launch.
  • 127 SiloTVTests across the session-return, account, profile-launch, profile-menu, password-change, remote-playback, profile-verification and server-connect classes pass.
  • After the review fixes, the head (120cad1b) was checked again on a new sandbox and simulator: Movies, Settings, the PIN profile on Series, and the picker after leaving the app. The same 127 tests pass.
  • 7ed2ea93 changes only the case where the picker Back was pressed on is replaced while the profile reopens: the profile now closes again. That case can't be produced from the remote. The head builds for tvOS, iOS and macOS, and the paths checked above take the same branch.
  • Silo (iOS) and SiloMac build. Their code paths are unchanged apart from a shared helper extracted in AuthService and an opt-in parameter on TokenStore.activateProfile.

Evidence: https://evidence.siloserver.org/r/silo-apple/issue-1164/

Risks

  • The closed profile's token stays in memory only while the picker is up. A token the server has since retired, for example after the PIN changed on another device, fails on the first request, and the existing recovery returns to the picker.
  • Watchlist, Favorites and Requests restoring was checked in code only: those pages weren't in this account's profile menu.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code, GitHub CLI, agent-device (simulator control), silo-build, silo-evidence
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated; not yet verified by a human
  • Adversarial review: Before implementing, gpt-6.1-sol (Codex, xhigh) attacked the plan and claude-opus-5-5 (high) cut it down. From the cut: dropped a library-visibility check that would have sent library tabs to Home, and moved invalidation to authState.didSet. From the attack: guarded against the Add Profile temporary context, captured the profile after a remote-playback identity ends, kept personal pages and library sections, and made Back path-aware. A high-level code review (three finders plus a validation check, claude-opus-5-5 and claude-sonnet-5-5) led to the second commit: drop the way back on leaving the app, restore focus after a failed reopen, ignore a second Switch Profile press, bind the switch to the captured profile, restore the page only for the same picker, and fall back to Home when a restored library tab can't load. A simplify pass replaced a nested conditional. The background adversarial review (gpt-6.1-sol, xhigh, reviewed 06e1db46) found two issues, both fixed in 120cad1b. Back waited on a player-settings request with the picker disabled; it now restores the page first. Leaving the app didn't stop a switch or Back already in flight; it now does. The same commit answers the Codex, Kody and CodeRabbit findings on those paths and adds a token-store fence so a late Back can't replace a profile chosen meanwhile.

🤖 Generated with Claude Code

Note

Return to previous screen on Back from tvOS Switch Profile

  • On tvOS, a successful Switch Profile now records the closed profile and the current shell location (root, personal page, pill selections) so Back can restore them.
  • Back on the root picker cancels the switch: it reopens the captured profile with its saved token, restores the prior shell location via TVMainTabView.swift, and resets to Home.
  • The saved return is invalidated when the app backgrounds (ContentView.swift), on auth-state changes, or when the foreground session changes, and reopening is refused if a temporary identity or another open profile blocks activation.
  • Picker content is disabled and cannot take focus while cancellation is in progress, and Back is ignored during PIN entry, Add Profile preparation, or management flows in ProfileSelectionView.swift.
  • TokenStore.activateProfile and AuthService.activateProfile gain a requiringNoOpenProfile option so reopening fails when a profile is already open.

Macroscope summarized 7ed2ea9.

Quick104 and others added 2 commits November 15, 2026 20:52
Back on the "Who's watching?" picker that Switch Profile opened exited the
app. The switch closes the profile and replaces the tab shell with the
picker, which had no Back handler, so Menu went to the system.

The switch now keeps the closed profile, its proof and the page it was on
in memory while that picker is up. Back reopens the same profile without
asking for its PIN and returns to the same tab, personal page, library
section or pushed screen (Settings). The picker opened at launch still
leaves Back to the system, and quitting on the picker still shows it at
the next launch.

From Settings the picker opened with nothing focused, so Back still
reached the system; the switch now swaps stacks without the crossfade.

Fixes #1164

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-ups for the Back-on-Switch-Profile fix:

- Leaving the app drops the saved return, so a picker resumed later
  needs a profile choice (and its PIN) again.
- A failed reopen keeps the picker, puts focus back on it and returns
  Back to the system.
- A second Switch Profile press while one runs is ignored.
- The switch closes only the profile it captured.
- The page is restored only if the picker is still the one Back was
  pressed on.
- A restored library tab falls back to Home if the libraries can't load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Nov 16, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T02:39:45.857951Z 7ed2ea9 New commits
🔒 Security Review ✅ Completed 2026-11-16T02:42:58.001782Z 7ed2ea9 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

On tvOS, switching profiles now records the closed profile and the current session and shell location. The profile picker can cancel the switch and reopen the profile, subject to activity checks. The app clears saved return state after route changes or when it enters the background.

Changes: Profile-switch return flow

Layer / File(s) Summary
Capture and reopen the switched profile
iosApp/iosApp/Screens/Auth/AuthService.swift, iosApp/iosApp/Navigation/AppRouter.swift
AuthService can capture and reopen the profile closed for a switch. Explicit selection can now check that the open profile matches an expected profile ID.
Route and restore the previous location
iosApp/iosApp/Navigation/AppRouter.swift, iosApp/iosApp/tvOS/Navigation/TVMainTabView.swift, iosApp/iosApp/ContentView.swift
AppRouter stores switch-return state and restores the session and shell location after reopening. TVMainTabView publishes and restores shell state. Route changes and backgrounding clear saved return state.
Guard picker cancellation
iosApp/iosApp/Screens/Profiles/ProfileSelectionView.swift
The picker allows cancellation only when profile selection, PIN verification, management preparation, and temporary management-context operations are inactive. The picker is disabled and focus is withheld during cancellation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant ProfileSelectionView
  participant AppRouter
  participant AuthService
  participant TVMainTabView
  ProfileSelectionView->>AppRouter: cancelSwitch when cancellation is allowed
  AppRouter->>AuthService: reopen saved profile
  AuthService-->>AppRouter: reopened profile
  AppRouter->>AppRouter: refresh authenticated content and player settings
  AppRouter->>TVMainTabView: provide saved shell location
  TVMainTabView->>AppRouter: publish restored shell location
Loading

Suggested reviewers: blurbery, rhainland, zzebrahz

Merge Risk: Low · up to 06e1d

On Apple TV, Back from Switch Profile now returns to the previous screen. In a rare timing case, backgrounding the app during the switch can leave a Back return that should have been discarded, so the picker lets Back reopen the previous profile instead of requiring a fresh choice. The impact is narrow and easy to fix with a small guard, so this is mergeable with that follow-up.

Security architecture risk: Moderate · up to 06e1d

A backgrounding race can leave the previous profile reopenable without its PIN after leaving the app, despite the intended foreground-only restriction. Exposure is limited to the same Apple TV and the previously open account and profile.

Retained concerns

  • Medium · security · inferred: Backgrounding does not revoke in-flight profile-switch authority. If the app backgrounds while switchProfile is awaiting profile deactivation, forgetProfileSwitchReturn clears only the current property. The switch can subsequently publish a new return containing the retained proof without checking whether background invalidation occurred. Returning to a picker does not reset that flow, so a subsequent viewer with control of the same TV can press Back and reopen the previous PIN-protected profile without entering its PIN, provided the captured proof remains valid. Before this PR, the picker had no equivalent no-PIN return path.
Security review details

Security Blast Radius

  • inferred — The identified path requires control of the same Apple TV after a profile switch overlaps backgrounding. Its authority is the captured profile’s existing proof under the captured account, not an arbitrary profile or another account. Effective server access remains bounded by acceptance of that proof.

Security Findings and Attack Paths

  • inferred — The introduced revocation failure is: switch awaits completion; background clears the return; switch completion republishes it; foreground handling leaves the picker unchanged; Back reactivates the captured proof without a PIN. Clearing a stored return is therefore insufficient to enforce its intended foreground-only lifetime.

Trust Boundaries and Controls

  • observed — At profile activation, temporary ownership is refused and the current account identity must equal the captured account. Saved navigation is restored only for the same server, account and profile. Route assignments clear published return state. These are meaningful containment controls, but they do not check the foreground lifetime of pending return publication.

Hardening Proposals

  • proposed — Represent the no-PIN return as revocable authority shared by the pending switch and cancellation operations. Invalidate it on background and ownership-changing routes, reject stale publication and activation, and retain selection-required when reopening is refused.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (Back on Switch Profile returns to the previous screen on tvOS), which matches the main change: the picker's Menu handling, the saved return state, and the reopen logic in AppR…
Linked Issues check Passed [#1164] The only directly linked issue asks that Back on the Apple TV Switch Profile picker return to the previous screen with focus on a usable element, and that exit remain the top-level Back behavi…
Out of Scope Changes check Passed Every listed change connects to the Switch Profile Back path. AuthService changes (openProfileForSwitch, reopenProfile, ClosedProfile, optional expectedProfileID in beginExplicitProfileSelection, and …
Description check Passed The description is specific and on-topic. It names the Apple TV Switch Profile bug (Menu on the picker closed the app), explains the approach (saved open profile, shell page, and session return point;…
Full details: Title check

Explanation

The title names the fix (Back on Switch Profile returns to the previous screen on tvOS), which matches the main change: the picker's Menu handling, the saved return state, and the reopen logic in AppRouter, AuthService, and ProfileSelectionView. It is specific and follows the conventional-commit style.

Full details: Linked Issues check

Explanation

[#1164] The only directly linked issue asks that Back on the Apple TV Switch Profile picker return to the previous screen with focus on a usable element, and that exit remain the top-level Back behavior. The reviewed changes implement this from the summary: AppRouter.switchProfile() captures the open profile (AuthService.openProfileForSwitch), the pushed screens (SessionReturnPoint), and the shell place (TVShellPlace). ProfileSelectionView handles Menu only while that return exists and nothing is pushed over the picker. AppRouter.cancelProfileSwitch() reopens the profile via AuthService.reopenProfile and calls resetToHome(), which restores pushed screens. TVMainTabView restores the saved shell place. The Settings-opened picker is made focusable by switching without the stack crossfade. The launch picker keeps Menu going to tvOS, which matches the issue's top-level exit rule. The PR description reports simulator validation of the Movies, Settings, and PIN-profile cases. Limits: the summary does not show test files, so the reported 127 SiloTVTests pass is taken from the PR description and was not verified in the diff. Watchlist, Favorites, and Requests restoration was checked in code only, per the PR description. These gaps do not affect the issue's stated behavior.

Full details: Out of Scope Changes check

Explanation

Every listed change connects to the Switch Profile Back path. AuthService changes (openProfileForSwitch, reopenProfile, ClosedProfile, optional expectedProfileID in beginExplicitProfileSelection, and the shared capability-refresh helper) support capturing and restoring the closed profile. The completeRequestedProfileSwitch return-type change and the tvOS retry after ending the remote identity support capturing the profile underneath a remote-playback identity. TVShellPlace and TVPersonalRootDestination visibility support restoring the shell page. The ContentView background call and the route-change clearing in the auth observer support the stated discard rules. The ProfileSelectionView changes gate Menu and block cancellation during PIN, management, and remember-offer states, which the issue's usable-focus and top-level exit expectations require. The Apple TV-only scope is stated in the PR description and is consistent with the tvOS-gated changes in the summary. No unrelated change appears in the summary.

Full details: Description check

Explanation

The description is specific and on-topic. It names the Apple TV Switch Profile bug (Menu on the picker closed the app), explains the approach (saved open profile, shell page, and session return point; reopen on cancel; picker focus from Settings), and lists validation steps and risks. It matches the changeset in AppRouter, AuthService, ProfileSelectionView, and TVMainTabView.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-triage silo-triage Bot added bug Something isn't working impact: usability Core flow broken or severely blocked needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. priority: P2 Limited scope, workaround exists, or polish labels Nov 16, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 06e1db4629

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review (gpt-6.1-sol, reviewed 06e1db4)

F1 below is verified from the source. Builds and simulator runs were unavailable for this review.

AI-assisted: posted by gpt-6.1-sol (Codex) as part of the maintainer's /silo run.

…eopen

Review follow-ups for Back on Switch Profile:

- Leaving the app now also stops a switch or a Back still in flight. A
  switch finishing afterwards keeps no way back, and a Back that already
  reopened the profile closes it again and stays on the picker.
- The reopen commits only while no profile is open, checked in the same
  token-store turn as the account, so a profile chosen meanwhile wins.
- Back restores the page before refreshing player settings, so a slow
  server can't leave the picker disabled with nothing focused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b88e70a7-4ab0-4e10-915e-d389a3ec81e9
Commits

Reviewing files that changed from the base of the PR and between d0e8775 and 06e1db4.

Files selected for processing: 5

  • iosApp/iosApp/ContentView.swift
  • iosApp/iosApp/Navigation/AppRouter.swift
  • iosApp/iosApp/Screens/Auth/AuthService.swift
  • iosApp/iosApp/Screens/Profiles/ProfileSelectionView.swift
  • iosApp/iosApp/tvOS/Navigation/TVMainTabView.swift

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

@silo-kody

silo-kody Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

When Back's reopen finishes after the picker it was pressed on was
replaced (a same-account rebuild that asks for a fresh choice), the
profile now closes again instead of staying open behind the new screen.
Home that something else already opened is left alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌
⚠️ 3 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Centralize server-relative authentication path validation
  • Enforce latest-link-wins centrally across deferred deep links
  • Rank subtitles using container capabilities and one stable cross-client policy

@Quick104
Quick104 merged commit 7bb8fe3 into main Nov 16, 2026
5 checks passed
@Quick104
Quick104 deleted the fix/silo-issue-1164 branch November 16, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working impact: usability Core flow broken or severely blocked needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Back on Switch Profile exits the app (Apple TV)

1 participant