Skip to content

fix(tv): hand control back to the TV when Back leaves a phone-controlled title - #907

Closed
Quick104 wants to merge 8 commits into
mainfrom
claude/tv-back-returns-control-4262d7
Closed

Quick104 wants to merge 8 commits into
mainfrom
claude/tv-back-returns-control-4262d7

Conversation

@Quick104

@Quick104 Quick104 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: changes #330 C3 and #331 C3 (both not yet run)

Other clients: Apple has the same bug on tvOS, and its parity issue is drafted but not filed yet; Roku N/A (no standby screen, and phones stay connected while the viewer browses, by design); Web N/A (no Remote Control surface)

Replaces #567, which could no longer be rebased.

When a phone controls playback on Android TV and the viewer presses Back on the TV remote, the player closes but the phone stays connected. The TV then covers the screen the viewer returned to with the black "Ready for " standby, and the only way out is its Disconnect Remote button. On the phone, a session the TV ends leaves the full remote open on a red "Not connected to a TV."

This change returns control to the TV when the viewer leaves the player with the TV remote, and the phone closes its remote with a short notice.

Approach

This re-implements #567 on the receiver that keeps several controllers (#653) and the phone's close policy (#652).

Android TV

  • Leaving the player with the TV's own remote (Back, the Stop key, Close, Exit, Stop Shuffling) closes the non-passive controllers with close tv_disconnected before the player exits, the way the standby screen's Disconnect Remote already does. The standby screen never appears and the TV returns to the screen under the player. Passive controllers (integrations, a silent auto-resume) stay connected.
  • Exits the viewer did not choose keep today's behavior: a Stop from the phone, a server stop, backgrounding the app, the end of a title, picking an on-deck title, and Watch Party exits. After a phone's Stop the standby still shows, because the phone is still in charge.
  • Back on the standby screen disconnects, like its button. Before, Back fell through to the screen underneath.
  • Disconnect also drops a launch on its way to the player, and turns away a phone that was still connecting. A connection accepted before the hand-back is closed at its hello unless it says it is passive. The accept loop snapshots the receiver's counters when it accepts a connection, not when the session coroutine starts.
  • A profile the phone lent is handed back once the exited player's final progress report and session stop have reached the server (bounded at 15 s), so the stop is not refused.

Android phone

  • SiloCastClosePolicy marks the closes that forget the TV as final: tv_disconnected, a close with no reason, and any close from a TV that keeps one controller. On those the remote closes, as silo-apple's does, and a toast reads "Disconnected from ." If the TV sent an error right before a goodbye other than tv_disconnected, the toast shows that error instead; a hand-back sends none, so an error just before one belongs to an earlier control. Other reasons (replaced, too_many_controllers, unauthorized, launch_timeout) keep the remote up to show the TV's reason, as before. A silent auto-resume the user never engaged with ends quietly, and a Roku's tv_disconnected keeps its "Open Silo on your Roku" message.
  • The notice waits until Silo is on screen, so a close that lands in the background is shown when the user returns. The remote is popped only while it is the top destination and no newer TV connection is up or on its way.

The wire protocol is unchanged. An iPhone controlling an Android TV gets the close it already handles by closing its remote.

Translations. The notice is a new catalog key, cast.remote.disconnectedFrom. The generated files here come from silo-translations main (d36b68d) plus that key, built locally, so check-translations fails until the key lands there (with its translation pass) and this branch is synced to the release. In CI that check runs inside ci / Select CI work, so that job fails, ci / Unit tests and ci / Lint are skipped, and ci / Android CI fails. CI has therefore not run the tests or lint on this branch yet. Until the key is translated, the seven other languages show the English text.

Review threads from #567. The exit-fade pop, the lender re-check, the stale launch and the handshake epoch are re-applied on the new code. The Codex finding that was never answered there ("Reject sessions accepted before control was returned") applied here too and is fixed by the accept-time snapshot.

Validation

  • At 60b48fb (main merged in, the first review fix on top): :androidApp, :androidTvApp and :android-shared debug unit tests pass (979, 1,399 and 2,280 tests, 0 failures); :androidApp:assembleDebug and :androidTvApp:assembleDebug pass; :androidApp:lintDebug passes with no findings outside the baseline. b832248 adds a three-line guard to the notice; at that head :androidApp compiles and its Remote Control tests pass. The review fixes were not run on an emulator. The new policy tests call functions this PR adds, so they don't compile on main and don't show the fix on their own.

  • :androidApp, :androidTvApp and :android-shared debug unit tests: pass (976, 1,399 and 2,272 tests, 0 failures), including the new close-policy and receiver-policy cases.

  • :androidApp:assembleDebug and :androidTvApp:assembleDebug: pass.

  • scripts/check-translations --local <catalog checkout>: matches. The CI form fails until the catalog commit is public, and takes the CI unit tests and lint with it (see Approach).

  • :android-shared:lintDebug, :androidApp:lintDebug and :androidTvApp:lintDebug, run locally because CI skipped them: pass, no findings outside the baselines.

  • Two emulators (Android TV and a phone, both API 36) against a disposable Silo server, the phone controlling the TV, main at a09cd3e against this branch at its first commit. The run was not repeated after the rebase onto 4686d6d (one unrelated icon change) or after the review fixes that followed (be51c9c: two receiver races; f780700: the phone keeps a close for its collector):

    • Back during playback. main: the standby covers Home and the phone stays on "Connected to ". Branch: the TV returns to Home, and the phone's remote closes with "Disconnected from ."
    • Back on the standby screen. main: falls through and leaves Silo for the Android TV launcher. Branch: the standby closes, Silo stays on Home, and the phone closes its remote with the notice.
    • Back from the player's error screen: same as Back during playback.
    • Stop Playback from the phone: the phone stays connected and the TV shows standby, as before.

Not run on a device; source reading and the policy tests cover these:

  • A cross-server phone that lent its profile: the hand-back of the borrowed identity and its wait for the player's session stop.
  • A phone still in its TLS handshake or hello at the moment of Back.
  • A launch sent just before Back.
  • Two or more phones connected at once.
  • The Stop key, Close, Exit and Stop Shuffling exits on the TV (the same call as Back).
  • A physical TV or phone, a tablet, a foldable.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-android/pr-907/

Surface and build: Android TV emulator (1920x1080) and Android phone emulator (1080x2400), debug builds, main at a09cd3e for the before captures and this branch for the after captures. Recordings of both screens cover the Back press. Tablet and foldable were not captured: the only phone change is a system toast and closing the remote screen, which have no layout of their own.

Risks

  • The TV now drops the phone on any viewer-chosen exit, including when the TV started the title itself and a phone attached later. A phone that wants to keep control has to reconnect.
  • With several phones connected, one viewer's Back disconnects all of the non-passive ones, as Disconnect Remote does.
  • A phone whose connection was accepted just before a Back on the TV is turned away even if that Back had nothing to do with it. The window is the TLS handshake plus the hello.
  • The turn-away is best effort at its edge. A connection still in the TCP backlog at the moment of Back, or one accept() had just returned and the loop had not yet stamped, counts as new and is admitted.
  • Ending a borrowed identity now waits for a pending playback stop (at most 15 s) before logging the temporary session out.
  • Returning control also drops a launch the phone sent just before Back; if its player was already opening, it closes.

Follow-ups:

  • tvOS has the same bug; its parity issue is drafted and not filed yet.
  • The catalog key needs its silo-translations change before this can merge.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code, running in the Claude desktop app
  • Tool(s): Claude Code with Explore subagents, GitHub CLI
  • Model(s): claude-fable-5-2
  • Involvement: Fully AI-generated at the developer's direction; verified on emulators by the agent, human verification pending
  • Adversarial review: gpt-6.1-sol (Codex) and a Claude Code multi-agent review (claude-opus-5-5, claude-sonnet-5-5) at f780700. Three findings in the phone's notice were fixed in 60b48fb and b832248. fix(tv): hand control back to the TV when Back leaves a phone-controlled title #567's review threads were re-applied as listed under Approach.

🤖 Generated with Claude Code

Note

Fix TV cast: hand control back to the TV when Back exits a phone-controlled title

  • TV player exit paths (Back, media-stop key, onClose, shuffle stop, onExitPlayback) now call disconnectRemoteControl before stopping playback, so control returns to the TV instead of the phone (TvPlayerScreen.kt).
  • The TV receiver tracks a hand-back counter. disconnectRemoteControl closes non-passive controllers that sent hello with a tv_disconnected goodbye, and turns away non-passive connections accepted before the hand-back when they later send hello (TvSiloCastReceiver.kt).
  • On the phone, SiloCastController exposes an endedByTv flow. A new SiloCastEndedByTvNotice composable collects it while STARTED, closes the remote when no target remains, and shows the error or a localized disconnected message as a Toast (SiloCastEndedByTvNotice.kt).
  • SiloCastClosePolicy now marks target-forgetting closes as final (closing the remote); non-final multi-controller closes keep the remote open. Older TVs always use the final close response.
  • scheduleIdentityEnd now waits up to PLAYBACK_TEARDOWN_TIMEOUT_MS for playback teardown before the lender check.
  • Behavioral Change: Back on the TV standby view now invokes the disconnect callback (TvSiloCastStandbyView.kt); phone sessions silently auto-resumed do not show the ended-by-TV Toast.

Macroscope summarized b832248.

Quick104 and others added 2 commits November 13, 2026 14:57
Generated from silo-translations 543b25713907, which adds
cast.remote.disconnectedFrom on top of the previously recorded bb5a6783406c.
That catalog commit is local only; it has to land in silo-translations and be
translated before check-translations can pass in CI.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…led title

When a phone controlled playback and the viewer left the player with the TV
remote, the phone stayed attached and the TV covered the screen they returned
to with the "Ready for <phone>" standby. On the phone, a session the TV ended
left the remote open on "Not connected to a TV."

TV:
- Back, Stop, Close, Exit and Stop Shuffling in the player now disconnect the
  non-passive controllers with tv_disconnected before the player exits, the
  way the standby screen's Disconnect does. A phone's Stop, a server stop,
  backgrounding, the end of a title and Watch Party exits keep the phone.
- Back on the standby screen disconnects, like its button.
- Disconnect also drops a launch on its way to the player and turns away a
  phone that was still connecting: one accepted before the hand-back is closed
  at its hello unless it is passive. The accept loop now snapshots the
  receiver's counters when it accepts, not when the session coroutine starts.
- Ending a borrowed identity waits (bounded) for the exited player's session
  stop, before the lender check.

Phone:
- SiloCastClosePolicy marks the closes that forget the TV as final. On those
  the remote closes and a toast says "Disconnected from <TV>", or the error
  the TV sent just before. Other reasons keep the remote up, as before.

Re-implements #567 on the multi-controller receiver (#653) and the phone's
close policy (#652).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Nov 13, 2026
@silo-kody

silo-kody Bot commented Nov 13, 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 ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 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-14T19:16:09.179140Z b832248 New commits
🔒 Security Review ✅ Completed 2026-11-14T19:17:58.720927Z b832248 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 13, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The TV now tracks remote-control hand-backs and disconnects or turns away eligible phone controllers. The phone distinguishes final closes from closes that keep the remote open, and displays notices for qualifying TV-ended sessions. TV player and standby exit actions use the disconnect path.

Changes: Remote hand-back

Layer / File(s) Summary
TV hand-back and exit paths
androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiverPolicy.kt, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiver.kt, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/cast/TvSiloCastStandbyView.kt, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerScreen.kt, androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiverPolicyTest.kt
The receiver tracks hand-backs, closes eligible controllers, and turns away non-passive connections accepted before the latest hand-back. Standby and player exit paths disconnect remote control. Identity teardown waits for playback teardown, and policy tests cover hand-back selection.
Phone close policy and notice creation
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/cast/SiloCastPhonePolicy.kt, androidApp/src/androidMain/kotlin/org/siloserver/silo/android/cast/SiloCastController.kt, androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/cast/SiloCastPhonePolicyTest.kt, android-shared/src/androidMain/res/values/strings_catalog.xml
The phone policy distinguishes final closes from closes that keep the remote open. The controller emits a notice for qualifying TV-ended sessions, using the preceding TV error when available. Tests cover close responses. The default catalog adds a TV-named disconnect notice.
Phone notice display and navigation
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/cast/SiloCastEndedByTvNotice.kt, androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/navigation/AppNavigation.kt, .silo-translations, android-shared/silo-locales.properties, android-shared/src/androidMain/res/values-*/strings_catalog.xml
The notice composable collects TV-ended notices while the lifecycle is STARTED, invokes the current close callback when applicable, and displays a toast. Navigation pops the remote screen only when it is the current destination. Translation metadata and generated-file revision comments are updated.

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

Change: Bug fix

Suggested reviewers: rxwatcher

Sequence Diagram(s)

sequenceDiagram
  participant TvExit as TV exit action
  participant Receiver as TvSiloCastReceiver
  participant Controller as SiloCastController
  participant Notice as SiloCastEndedByTvNotice
  participant Navigation as AppNavigation
  TvExit->>Receiver: disconnect remote control
  Receiver->>Controller: close controller session
  Controller->>Notice: emit endedByTv notice
  Notice->>Navigation: invoke closeRemote callback
  Notice->>Notice: show notice toast while lifecycle is STARTED
Loading
Merge Risk: Low · up to b8322

Pressing Back or Stop on the TV now hands control back from phone remotes, and the phone shows a notice when the TV ends the session. The remaining issues are narrow timing edge cases: a borrowed profile may stay active longer than intended after a hand-back, and a spurious notice may appear on some auto-resumed sessions. CI is also red until the translation catalog change is published. Resolve these before merging, or accept them explicitly.

Security architecture risk: Minimal · up to b8322

The inspected changes return control to the TV and reject stale connections without establishing a material expansion of remote-control authority. No introduced architecture-level security concern was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected authority-sensitive effects concern one TV receiver's controller set, its active or pending playback, and a phone-lent profile generation. A hand-back may disconnect multiple eligible phones on that receiver, rather than only the phone associated with the current title.

Trust Boundaries and Controls

  • observed — A non-passive connection whose snapshot predates hand-back is rejected at hello before connection replacement. This does not revoke the device permanently: passive connections are exempt, and connections whose snapshot is taken after hand-back use the new generation. The code explicitly treats the interval between accept returning and snapshot acquisition as part of this boundary.

Resilience and Maintainability Implications

  • observed — Controller removal is identity-checked, cancels its recorded pending handoff, and detaches its issued identity from the connection. Launch admission rechecks registration, while launch confirmation rejects invalidated pending launches. Scheduled profile cleanup now waits at most fifteen seconds for queued playback teardown before proceeding to the existing idle and generation-specific cleanup decisions.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main behavior change: when Back on the Android TV remote exits a phone-controlled title, control is handed back to the TV. The changeset disconnects non-passive phone controllers o…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is specific and on-topic. It names the Android TV Back-exit bug, the phone's red "Not connected to a TV." state, the hand-back and close-policy changes, the translation catalog key, va…
Full details: Title check

Explanation

The title names the main behavior change: when Back on the Android TV remote exits a phone-controlled title, control is handed back to the TV. The changeset disconnects non-passive phone controllers on TV-side exits (TvSiloCastReceiver, TvPlayerScreen, TvSiloCastStandbyView) and the phone shows a disconnect notice and closes its remote (SiloCastController, SiloCastPhonePolicy, SiloCastEndedByTvNotice). The title is specific and scoped to the primary change, and it uses the conventional fix(tv): prefix.

Full details: Description check

Explanation

The description is specific and on-topic. It names the Android TV Back-exit bug, the phone's red "Not connected to a TV." state, the hand-back and close-policy changes, the translation catalog key, validation runs, and an evidence link. It matches the changeset, including the SiloCastClosePolicy, TvSiloCastReceiver, and SiloCastEndedByTvNotice files.

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

@macroscopeapp

macroscopeapp Bot commented Nov 13, 2026

Copy link
Copy Markdown

Evidence is incomplete. The Evidence section describes recordings but only says the link is being published; no recording or published evidence URL is present yet.

  • Phone remote close and “Disconnected from …” notice (androidApp/.../SiloCastEndedByTvNotice.kt, AppNavigation.kt): reaches Android phones, tablets, and foldables folded/open. A before/after recording is missing for the phone; please attach or publish one showing the remote closing and notice. The stated reason for omitting tablet and foldable captures (generic navigation/toast, no layout of their own) agrees with the code, so separate captures for those form factors are not needed.
  • Leaving playback on the TV (androidTvApp/.../TvPlayerScreen.kt): reaches Android TV. A before/after recording is missing; show the TV returning to the underlying screen without standby after a viewer-initiated exit.
  • Back on the TV standby screen (androidTvApp/.../TvSiloCastStandbyView.kt): reaches Android TV. A before/after recording is missing; show Back disconnecting and returning to the underlying screen.

The PR describes the device and build context, but the recordings themselves are not available for review.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@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 13, 2026
Two races from review of the TV hand-back:

- A connection closed by a hand-back while its hello was being read went on
  to replace the same device's newer connection. The hello's checks and the
  replacement now run as one step under the receiver lock, and a connection
  that is no longer registered stops there.
- The accept loop read the receiver's counters after its coroutine resumed
  from accept(). They are now read in the same block, right after accept()
  returns. A connection still in the TCP backlog at the moment of Back is
  still indistinguishable from a new one.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@silo-kody

silo-kody Bot commented Nov 13, 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 ❌

@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: 2

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: 976818d7-a43a-4402-acb1-3c66e22fd895
Commits

Reviewing files that changed from the base of the PR and between 4686d6d and 231ce19.

Files selected for processing: 20

  • .silo-translations
  • android-shared/silo-locales.properties
  • android-shared/src/androidMain/res/values-ar/strings_catalog.xml
  • android-shared/src/androidMain/res/values-b+zh+Hans/strings_catalog.xml
  • android-shared/src/androidMain/res/values-de/strings_catalog.xml
  • android-shared/src/androidMain/res/values-es/strings_catalog.xml
  • android-shared/src/androidMain/res/values-fr/strings_catalog.xml
  • android-shared/src/androidMain/res/values-ja/strings_catalog.xml
  • android-shared/src/androidMain/res/values-pt-rBR/strings_catalog.xml
  • android-shared/src/androidMain/res/values/strings_catalog.xml
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/cast/SiloCastController.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/cast/SiloCastPhonePolicy.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/navigation/AppNavigation.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/cast/SiloCastEndedByTvNotice.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/cast/SiloCastPhonePolicyTest.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiver.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiverPolicy.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/cast/TvSiloCastStandbyView.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerScreen.kt
  • androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiverPolicyTest.kt

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.

// the "Ready for <phone>" standby. A phone's Stop exits without this, and
// a Back during that exit's fade must not drop the phone either.
val leavePlayerOnTv = {
if (!exitRequested) siloCastReceiver.disconnectRemoteControl()

@coderabbitai coderabbitai Bot Nov 13, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Stability & Availability · Quick win

Check controller membership again before a late approval changes the TV's identity.

The challenge callback checks isCurrentHandoff only before the challenge is sent. If the controller is removed after that point, the approval poll can still succeed. beforeActivation then runs, which can stop the TV player and end the current identity. The new identity is installed before the stale handoff is rejected and ended. Add the same membership check to beforeActivation, before the consent check and the player stop:

Suggested fix

                     beforeActivation = {
+                        if (!isCurrentHandoff(pending)) throw CancellationException("The handoff was superseded.")
                         // Another controller may have started a title while the
                         // server approved this one.
                         titleNeedingConsent(session, offer)?.let { throw ReplaceConfirmationRequired(it) }
                         stopPlayerBeforeIdentitySwap()
                     },

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.

Not changed here. This is the handoff flow in TvSiloCastReceiver, which this PR does not touch, and after approval it completes on purpose: when the controller has left, the fresh identity is installed and then handed back with a proper logout (finishPendingHandoff returning false). Throwing in beforeActivation instead would abandon the approved temporary session without revoking it, which is the open follow-up from #653. On the path this PR adds, the player is already exiting or absent when the controller is removed, so there is nothing for the stale handoff to stop. Leaving the thread open for the maintainer.

🤖 Addressed by Claude Code

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Analysis chain

Script executed:

#!/bin/bash
set -u
file="androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiver.kt"
ast-grep outline "$file" --items all --match 'handoff|Handoff|disconnectRemoteControl|IdentitySwap' --view expanded
rg -n -C 12 'beforeActivation|finishPendingHandoff|isCurrentHandoff|disconnectRemoteControl|stopPlayerBeforeIdentitySwap' "$file"
rg -n -C 5 --type kt 'beforeActivation\s*[:=]|beforeActivation\s*\(' .

Length of output: 12552


Script executed:

#!/bin/bash
set -u
file="androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiver.kt"
echo '=== Controller removal and handoff ==='
rg -n -C 12 'fun removeControllerLocked|pendingHandoff|fun disconnectRemoteControl|finishPendingHandoff|beforeActivation' "$file"
echo '=== Identity activation implementations ==='
rg -n -C 15 -g '*.kt' 'beforeActivation\s*[:=]|beforeActivation\s*\(' .
echo '=== Identity manager candidates ==='
fd -t f -g '*IdentityManager*.kt' --exec ast-grep outline {} --items all --match 'prepare|end|activate|logout' --view expanded

Length of output: 37325


Script executed:

#!/bin/bash
file="androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/cast/RemotePlaybackIdentityManager.kt"
ast-grep outline "$file" --items all --view expanded
cat -n "$file" | sed -n '70,240p'
rg -n -C 15 'endLocked|logout|endSession|fun end\(' "$file"

Length of output: 22152


@Quick104 Thanks for the explanation. I withdraw my recommendation to add the beforeActivation check: it could bypass cleanup of an approved temporary session.

If prepare returns a fresh identity after the handoff becomes stale, the receiver calls identityManager.end; server logout is best effort. Controller removal also cancels the pending job, so that cleanup path is not guaranteed to run.

I’ll leave the disposition to the maintainer.


Learnings used

Learnt from: amokster88
Repo: Silo-Server/silo-android PR: 488
File: androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerScreen.kt:2699-2703
Timestamp: 2026-10-08T14:28:08.209Z
Learning: In Silo-Server/silo-android, Android TV cast identity swaps use TvSiloCastReceiver.stopPlayerBeforeIdentitySwap() in androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiver.kt. Before activating a handoff identity, this function stops the registered player, waits for player unregister and queued playback teardown, and rejects the swap if teardown times out or another player is active. TvSiloCastReceiver.stop() separately waits for queued playback teardown with a bounded timeout before ending the stopped receiver run's identity; it does not rely on composition disposal to unregister the player.
Learnt from: Quick104
Repo: Silo-Server/silo-android PR: 652
File: :0-0
Timestamp: 2026-10-21T00:43:44.271Z
Learning: In Silo Cast, preparing a handoff offer intentionally supports phones signed in to a different server or without authorization on the TV. Do not require existing TV authorization or a verified deployment-identity match before preparing the offer. The offer's serverIdentity helps the TV reach the server and does not grant access. A borrowed profile requires approval by the phone's signed-in account of the TV's device-login challenge with remote_playback purpose and a temporary session. Before activating the profile, the TV checks that the approval matches the offer's server and profile. The multi-controller receiver in Silo-Server/silo-android PR #653 restricts borrowed-profile reuse to the connection that completed the handoff or a holder of its issued resume token.

You are interacting with an AI system.

A connection counts as accepted before a hand-back when its counters were
read before it, not when accept() returned. Comments only.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@silo-kody

silo-kody Bot commented Nov 13, 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 ❌

@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: 710ca2432b

ℹ️ 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".

Comment on lines +622 to +624
if (!exitRequested) siloCastReceiver.disconnectRemoteControl()
stopPlaybackAndExit()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge File the required Apple parity follow-up

The commit description states that tvOS has the same bug but its parity issue is only drafted, not filed. That leaves the acknowledged Apple regression without the cross-client follow-up required by the repository's AGENTS.md. Search for an existing Apple issue and link it, or file the parity issue and replace the pending statement on the Other clients: line with its reference. No additional pull request is needed.

AGENTS.md reference: AGENTS.md:L50-L55

Useful? React with 👍 / 👎.

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.

Checked silo-apple main: tvOS has the same bug. TVControlReceiver.disconnectRemoteControl() is called only from TVControlStandbyView, so leaving the player never reaches it. The iPhone remote already closes on tv_disconnected (SiloControlClient, the .letGo(forgetTarget: true) path), so only tvOS needs the change. The parity issue is drafted, and the maintainer will decide when it is filed. The Other clients: line will link it then.

🤖 Claude Code (claude-opus-5-5)

The ended-by-TV event was a shared flow with no replay, so a close that
arrived while the activity was being recreated had no collector and was
dropped: the remote stayed open with no notice. It is now a conflated
channel read as a flow, which keeps the latest close for the app's one
collector and delivers it once.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@silo-kody

silo-kody Bot commented Nov 13, 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 ❌

Quick104 and others added 3 commits November 14, 2026 18:58
Regenerates the translation catalog from silo-translations main (d36b68d)
plus the cast.remote.disconnectedFrom key, which replaces the earlier
local catalog build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ce Silo is on screen

The notice reused whatever error the TV sent last, so a reply to an
earlier control, or the previous session's last error, could stand in
for "Disconnected from <TV>." A tv_disconnected close now always shows
that text, and each session starts with no remembered error.

A close that landed while the app was in the background popped the
remote but skipped the toast, so the user came back to a remote that
had vanished. The notice now waits until Silo is started.

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

The ended-by-TV notice popped the remote whenever it ran. A close the UI
collects after the user picked another TV would close that TV's remote
instead. The notice still shows; the remote closes only when no
connection is up or on its way.

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

@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.

Review of f780700. The approach holds: handing control back at the receiver when the viewer leaves the title with the TV remote matches what the standby screen's Disconnect Remote already does, and the phone side now matches the iPhone, which closes its remote when the TV forgets it. Three findings below, all in the phone's new notice, each small. I'm fixing all three on this branch, along with a merge of main (the conflict was only in the generated translation files).

🤖 Claude Code (claude-opus-5-5)

@silo-kody

silo-kody Bot commented Nov 14, 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 ❌

@Quick104

Copy link
Copy Markdown
Contributor Author

Review summary

Reviewed f780700, then pushed fixes. The head is now b832248.

Fixed on this branch

  • Merged main (5d2171e). The conflict was only in generated translation files. They are now generated from silo-translations main (d36b68d) plus cast.remote.disconnectedFrom, so the only translation change against main is that key.
  • 60b48fb: the notice no longer shows an unrelated error. A tv_disconnected close always reads "Disconnected from .", and each session starts with no remembered error.
  • 60b48fb: a close that lands while Silo is in the background is shown when the user returns, instead of the remote vanishing without a word.
  • b832248: a late close from one TV no longer closes the remote of a TV the user just picked.

Left for the maintainers

  • Translations (blocks merge). cast.remote.disconnectedFrom needs a silo-translations pull request with its make translate pass. Then this branch syncs to that release with scripts/sync-translations --version <v>. Until then ci / Select CI work fails, and CI skips the unit tests and lint.
  • tvOS parity. silo-apple main has the same bug: TVControlReceiver.disconnectRemoteControl() is called only from the standby screen. The parity issue is drafted but not filed.
  • Live check on the current head. The emulator run covered the first commit only. The receiver race fixes (be51c9c) and the phone fixes above have unit tests and builds, but nothing has run them on a device.
  • Reconnect after a dropped goodbye (maintainer decision). Suppose a phone's link drops just before Back on the TV. The goodbye never reaches it, and it reconnects after the hand-back, so the hand-back counter admits it and the standby returns. This is a gap in the fix, not a regression: main shows the standby in this case too. A short per-device memory of who was handed back would close the gap, but it would also refuse a user who deliberately reconnects right away. I'd leave it as is.

Other feedback: the Kody and CodeRabbit threads are answered. CodeRabbit's beforeActivation thread concerns handoff code this PR doesn't change, and CodeRabbit withdrew the suggestion.

Tests: at 60b48fb, the :androidApp, :androidTvApp and :android-shared debug unit tests pass (979, 1,399 and 2,280, 0 failures), both debug builds pass, and phone lint has no findings outside the baseline. At b832248, :androidApp compiles and its Remote Control tests pass. The new policy tests call functions this PR adds, so they don't compile on main and can't show the fix by failing there.

Validated features: unavailable. The board query failed for lack of access, so the PR's Validation tasks: line (#330 C3 and #331 C3, both not yet run) is unconfirmed. Those cases cover visible disconnect and recovery, which this PR changes.

User manual: the Remote Control page (docs/tv-remote) doesn't say what happens when someone at the TV leaves the title. This PR changes that behavior, so a siloserver.org issue should add a line saying the phone disconnects and shows a notice when the viewer leaves the title or chooses Disconnect Remote on the TV.

Review method: a Claude Code multi-agent review (three finders and a validation check) and a gpt-6.1-sol (Codex) round at f780700. Their verified findings are the three fixed above.

Fit: 8/10 · Readiness: 5/10 — not ready

Fit: the TV takes control back where its Disconnect Remote already does, and the phone now closes its remote the way the iPhone does. The score stays at 8 until the tvOS parity issue is linked. Readiness: the code is sound after the fixes, but the PR can't merge until the translation key is released and CI runs, and the later fixes haven't been run on a device.

🤖 Claude Code (claude-opus-5-5)

Comment on lines +32 to +35
val current = controller.state.value
if (current.connectedTarget == null && !current.isConnecting && !current.isReconnecting) {
latestCloseRemote()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

A failed replacement connection leaves the disconnected remote open

A failed replacement connection can leave the disconnected remote on screen because the queued close was consumed. Preserve or reevaluate the pending close after the connection attempt finishes.

Prompt for LLM
File androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/cast/SiloCastEndedByTvNotice.kt, lines 32-35:

A failed replacement connection leaves the disconnected remote open

A queued TV close is consumed without closing the remote when a replacement connection is in progress, even if that connection subsequently fails. Preserve or reevaluate the pending close after the connection attempt finishes so a failed attempt does not leave the disconnected remote on screen.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

@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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Check controller membership before a completed handoff grants… · TvSiloCastReceiver.kt:1045

androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiver.kt:1045
Minor · Data Integrity & Integration · Quick win

Check controller membership before a completed handoff grants readiness.

After finishPendingHandoff clears pendingHandoff, a viewer's hand-back can remove the controller while completeHandoff waits on identityManager.whileActive. removeControllerLocked cannot cancel that job. grantReadiness then runs for the removed session and can set its readiness, authorization, and issuedIdentity state. If the player exit has already scheduled the short identity end, line 1058 can replace it with the ten-minute IDENTITY_IDLE_MS timer. The disconnected phone's lent profile can then remain active for up to ten minutes after the viewer exits.

Add a membership check under the receiver monitor, inside the whileActive block and before grantReadiness. If the controller is no longer registered, take the same cleanup path used when finishPendingHandoff returns false, at lines 958-962. Do not return the error path alone, because it skips cleanup of a fresh identity.

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: 2051176d-c09b-48e4-b19a-8fabb1d45b70
Commits

Reviewing files that changed from the base of the PR and between 231ce19 and b832248.

Files selected for processing: 13

  • .silo-translations
  • android-shared/silo-locales.properties
  • android-shared/src/androidMain/res/values-ar/strings_catalog.xml
  • android-shared/src/androidMain/res/values-b+zh+Hans/strings_catalog.xml
  • android-shared/src/androidMain/res/values-de/strings_catalog.xml
  • android-shared/src/androidMain/res/values-es/strings_catalog.xml
  • android-shared/src/androidMain/res/values-fr/strings_catalog.xml
  • android-shared/src/androidMain/res/values-ja/strings_catalog.xml
  • android-shared/src/androidMain/res/values-pt-rBR/strings_catalog.xml
  • android-shared/src/androidMain/res/values/strings_catalog.xml
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/cast/SiloCastController.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/cast/SiloCastEndedByTvNotice.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/cast/TvSiloCastReceiver.kt
Files skipped from review as they are similar to previous changes: 8

  • android-shared/silo-locales.properties
  • android-shared/src/androidMain/res/values-ar/strings_catalog.xml
  • android-shared/src/androidMain/res/values-b+zh+Hans/strings_catalog.xml
  • android-shared/src/androidMain/res/values-de/strings_catalog.xml
  • android-shared/src/androidMain/res/values-es/strings_catalog.xml
  • android-shared/src/androidMain/res/values-fr/strings_catalog.xml
  • android-shared/src/androidMain/res/values-ja/strings_catalog.xml
  • android-shared/src/androidMain/res/values-pt-rBR/strings_catalog.xml

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.

// A silent auto-resume the user never engaged with
// never surfaced, so it ends quietly.
val ended = _state.value.connectedTarget
?.takeIf { response.closesRemote && !sessionIsAutoResumed }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Preserve the silent-session marker until teardown completes.

If an unengaged auto-resumed connection receives Error followed by a final Close, Error calls quietDisconnect(). That function immediately sets sessionIsAutoResumed=false, but schedules teardown asynchronously. If Close arrives before that teardown runs, this guard treats the session as engaged and emits a notice. The collector then shows a toast and can close the remote.

Keep the engagement state valid until teardown, or capture session-scoped engagement separately from the disconnect state.

@Quick104 Quick104 closed this Nov 14, 2026
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.

1 participant