Skip to content

Use the phone profile for remote TV playback - #82

Merged
Quick104 merged 1 commit into
mainfrom
codex/remote-playback-phone-identity
Jul 10, 2026
Merged

Quick104 merged 1 commit into
mainfrom
codex/remote-playback-phone-identity

Conversation

@Quick104

@Quick104 Quick104 commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • negotiate Silo Cast protocol v2 for phone-initiated launches
  • let tvOS acquire a process-only session for the phone's server and selected profile
  • keep ordinary control of existing TV playback under the TV's identity
  • restore the saved TV identity after the remotely launched player ends
  • show a six-second, non-focusable “Playing as …” notice with the phone and profile names
  • keep v1 receivers control-only for updated phones and document the lifecycle

User impact

Launching content from an iPhone now attributes permissions, resume state, progress, and preferences to the iPhone's active profile—even when the Apple TV is signed into another account or server. The temporary credentials never enter the TV keychain.

The identity notice makes the switch explicit without interrupting playback or taking Siri Remote focus.

Dependencies and parity

Validation

  • iOS Simulator build
  • tvOS Simulator build
  • SiloControlTests: 9 tests, 0 failures
  • git diff --check

Summary by CodeRabbit

  • New Features
    • Added cross-server remote playback handoff between iOS and tvOS with temporary profile authorization.
    • Added protocol negotiation for improved compatibility between app versions.
    • Added tvOS notices showing when playback uses a remotely authorized profile or server.
    • Added automatic cleanup and restoration when temporary authorization expires.
  • Improvements
    • Devices requiring an update are now clearly identified before remote playback.
    • Remote playback connections now provide more reliable authorization, launch, and teardown behavior.
  • Documentation
    • Updated cast remote architecture, security considerations, volume controls, lifecycle behavior, and testing guidance.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds SiloControl protocol v2 negotiation and remote identity handoff for cross-server tvOS playback. It introduces temporary authentication scopes, new device-login APIs, receiver lifecycle changes, expiry handling, identity UI, protocol tests, and updated casting documentation.

Changes

Remote playback handoff

Layer / File(s) Summary
Protocol contracts and target selection
iosApp/iosApp/Control/SiloControlProtocol.swift, iosApp/iosApp/Control/iOS/SiloControlBrowser.swift, iosApp/iosApp/Control/iOS/SiloControlTargetPickerView.swift, iosApp/Tests/SiloControlTests.swift, docs/tvos-player/cast-remote.md
Protocol v2 negotiation, handoff message encoding, target compatibility filtering, and corresponding round-trip tests and documentation are added.
Temporary authentication plumbing
iosApp/iosApp/Networking/DeviceLoginModels.swift, iosApp/iosApp/Networking/TokenStore.swift, iosApp/iosApp/Pairing/PairingDeviceAPI.swift, iosApp/iosApp/Screens/Auth/AuthService.swift
Device-login responses, remote playback endpoints, process-only token scopes, profile headers, and cache-reset handling support temporary remote identities.
iOS handoff orchestration
iosApp/iosApp/Control/iOS/SiloControlClient.swift
The client negotiates protocol versions, performs offer/challenge/approval/ready exchanges, adopts effective targets, and resets handoff state during teardown.
tvOS receiver lifecycle
iosApp/iosApp/Control/tvOS/RemotePlaybackIdentityManager.swift, iosApp/iosApp/Control/tvOS/TVControlReceiver.swift
tvOS manages temporary identities, effective server advertising, authorization, launch readiness, player generations, timeouts, and connection cleanup.
Expiry handling and playback presentation
iosApp/iosApp/Networking/HTTPClient.swift, iosApp/iosApp/Navigation/AppRouter.swift, iosApp/iosApp/ContentView.swift, iosApp/iosApp/Screens/Player/*
Temporary refresh failures use a dedicated notification and restoration path; tvOS displays remote identity information and awaits player cleanup before unregistering.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related issues

  • Silo-Server/silo-android#15 — The PR changes the shared SiloControl protocol and tvOS receiver behavior that an Android TV receiver port would implement.
  • Silo-Server/silo-android#16 — The protocol, client, receiver, discovery, and control changes overlap with the planned Android remote implementation.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: remote TV playback now uses the phone’s profile identity.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/remote-playback-phone-identity

Comment @coderabbitai help to get the list of available commands.

@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: 9d567f2e33

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +408 to +411
guard let self,
self.activeConnectionId == connectionId,
self.remoteLaunchReady,
self.playerViewModel == nil else { return }

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 Restore temporary identity after pre-launch disconnects

When the phone receives handoff_ready but then disconnects or crashes before sending launch, handleConnectionClosed clears activeConnectionId and remoteLaunchReady. This timeout then returns at this guard, so RemotePlaybackIdentityManager.end() is never called and the TV remains in the phone's temporary TokenStore scope/Bonjour server until process or server expiry, even though no player was launched. The ready-without-launch cleanup needs to run for this no-player case even after the socket is gone.

Useful? React with 👍 / 👎.

Comment on lines +319 to +320
if negotiatedVersion == 2,
(!remoteLaunchReady || RemotePlaybackIdentityManager.shared.activeIdentity == nil) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require handoff whenever a temporary identity exists

When a temporary identity from another controller is already active, a legacy v1 phone on the same advertised server is authorized by the hello server match, but this check only requires handoff for v2 clients. Its launch therefore proceeds with the previous phone's temporary credentials/profile instead of the TV-owned identity or the launching user's profile, which can write playback/progress under the wrong profile. Reject v1 launches while activeIdentity exists or restore before accepting them.

Useful? React with 👍 / 👎.

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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/tvos-player/cast-remote.md`:
- Around line 135-137: Correct the test-target claim in the documentation:
either configure and verify the SiloTests target so
iosApp/Tests/SiloControlTests.swift is compiled and executed, or revise the text
to state that the tests are currently not wired, compiled, or run.

In `@iosApp/iosApp/Control/iOS/SiloControlClient.swift`:
- Around line 262-276: Before approving the device handoff in the
challenge-processing flow, require that the receiver identity is
cryptographically authenticated and matches the pairing-established TV identity,
not merely that the response has a valid remote_playback code. Use the existing
SiloControl authentication/pairing state and identity fields alongside
ensureActiveIdentity, rejecting with SiloControlHandoffError.invalidResponse on
missing or mismatched identity, then call approve-handoff only after validation
succeeds.

In `@iosApp/iosApp/Control/tvOS/RemotePlaybackIdentityManager.swift`:
- Around line 199-201: Update parseISO8601 to configure ISO8601DateFormatter
with fractional-second support, while retaining internet-date-time/UTC parsing,
so values such as 2026-04-13T04:46:42.211273Z are parsed correctly and
poll.sessionExpiresAt.flatMap(Self.parseISO8601) does not fall back to +24h.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f67bb722-baeb-465b-9fc4-3968677e9087

📥 Commits

Reviewing files that changed from the base of the PR and between d857ee7 and 9d567f2.

📒 Files selected for processing (18)
  • docs/tvos-player/cast-remote.md
  • iosApp/Tests/SiloControlTests.swift
  • iosApp/iosApp/ContentView.swift
  • iosApp/iosApp/Control/SiloControlProtocol.swift
  • iosApp/iosApp/Control/iOS/SiloControlBrowser.swift
  • iosApp/iosApp/Control/iOS/SiloControlClient.swift
  • iosApp/iosApp/Control/iOS/SiloControlTargetPickerView.swift
  • iosApp/iosApp/Control/tvOS/RemotePlaybackIdentityManager.swift
  • iosApp/iosApp/Control/tvOS/TVControlReceiver.swift
  • iosApp/iosApp/Navigation/AppRouter.swift
  • iosApp/iosApp/Networking/DeviceLoginModels.swift
  • iosApp/iosApp/Networking/HTTPClient.swift
  • iosApp/iosApp/Networking/TokenStore.swift
  • iosApp/iosApp/Pairing/PairingDeviceAPI.swift
  • iosApp/iosApp/Screens/Auth/AuthService.swift
  • iosApp/iosApp/Screens/Player/PlayerView.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • iosApp/iosApp/Screens/Player/RemotePlaybackIdentityNotice.swift

Comment on lines +135 to +137
Protocol negotiation, v2 message round-trips, and `RemotePlaybackClock`
interpolation/optimistic math live in `iosApp/Tests/SiloControlTests.swift` and
run through the `SiloTests` target.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

Fix the test-target claim before merging.

Line [137] says these tests run through SiloTests, but iosApp/Tests/SiloControlTests.swift:4-7 states that no test target is wired and the tests are not compiled or executed. Either wire the target and verify the tests run, or document the current non-execution.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/tvos-player/cast-remote.md` around lines 135 - 137, Correct the
test-target claim in the documentation: either configure and verify the
SiloTests target so iosApp/Tests/SiloControlTests.swift is compiled and
executed, or revise the text to state that the tests are currently not wired,
compiled, or run.

Comment on lines +262 to +276
let lookup: DeviceLookupResponse = try await HTTPClient.shared.get(
"/api/v1/auth/device",
query: ["code": challenge.userCode]
)
guard lookup.matchCode == challenge.matchCode,
lookup.clientPurpose == "remote_playback",
lookup.temporary == true else {
throw SiloControlHandoffError.invalidResponse
}

try ensureActiveIdentity(serverId: server.id, profileId: profileId)
try await HTTPClient.shared.postVoid(
"/api/v1/auth/device/approve-handoff",
body: DeviceApproveRequest(code: challenge.userCode)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

Bind device approval to an authenticated TV identity.

This automatically approves any valid remote_playback code returned over the SiloControl connection. A LAN attacker can impersonate or race a discovered receiver, create its own temporary device-login request, return that challenge, and obtain the phone profile’s temporary session. Bind the challenge to a cryptographically authenticated/pairing-established receiver identity before approving it.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iosApp/iosApp/Control/iOS/SiloControlClient.swift` around lines 262 - 276,
Before approving the device handoff in the challenge-processing flow, require
that the receiver identity is cryptographically authenticated and matches the
pairing-established TV identity, not merely that the response has a valid
remote_playback code. Use the existing SiloControl authentication/pairing state
and identity fields alongside ensureActiveIdentity, rejecting with
SiloControlHandoffError.invalidResponse on missing or mismatched identity, then
call approve-handoff only after validation succeeds.

Comment on lines +199 to +201
private static func parseISO8601(_ value: String) -> Date? {
ISO8601DateFormatter().date(from: value)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -nP -C3 'sessionExpiresAt|expiresAt' iosApp/iosApp/Networking/DeviceLoginModels.swift
rg -nP -C5 'dateDecodingStrategy|ISO8601|withFractionalSeconds' iosApp/iosApp/Pairing/PairingDeviceAPI.swift

Repository: Silo-Server/silo-apple

Length of output: 1988


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '110,220p' iosApp/iosApp/Control/tvOS/RemotePlaybackIdentityManager.swift
printf '\n--- HTTPClient.swift excerpt ---\n'
sed -n '80,105p' iosApp/iosApp/Networking/HTTPClient.swift

Repository: Silo-Server/silo-apple

Length of output: 5183


parseISO8601 needs to accept fractional seconds

poll.sessionExpiresAt is a string, and this helper currently uses the default ISO8601DateFormatter, which misses the server’s fractional-second form (for example 2026-04-13T04:46:42.211273Z). That makes poll.sessionExpiresAt.flatMap(Self.parseISO8601) fall back to +24h, so the stored session expiry can be wrong.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iosApp/iosApp/Control/tvOS/RemotePlaybackIdentityManager.swift` around lines
199 - 201, Update parseISO8601 to configure ISO8601DateFormatter with
fractional-second support, while retaining internet-date-time/UTC parsing, so
values such as 2026-04-13T04:46:42.211273Z are parsed correctly and
poll.sessionExpiresAt.flatMap(Self.parseISO8601) does not fall back to +24h.

@Quick104
Quick104 merged commit 79ea7af into main Jul 10, 2026
1 check passed
@Quick104
Quick104 deleted the codex/remote-playback-phone-identity branch July 10, 2026 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant