Repository navigation
Use the phone profile for remote TV playback - #82
Conversation
📝 WalkthroughWalkthroughThis 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. ChangesRemote playback handoff
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 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".
| guard let self, | ||
| self.activeConnectionId == connectionId, | ||
| self.remoteLaunchReady, | ||
| self.playerViewModel == nil else { return } |
There was a problem hiding this comment.
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 👍 / 👎.
| if negotiatedVersion == 2, | ||
| (!remoteLaunchReady || RemotePlaybackIdentityManager.shared.activeIdentity == nil) { |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@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
📒 Files selected for processing (18)
docs/tvos-player/cast-remote.mdiosApp/Tests/SiloControlTests.swiftiosApp/iosApp/ContentView.swiftiosApp/iosApp/Control/SiloControlProtocol.swiftiosApp/iosApp/Control/iOS/SiloControlBrowser.swiftiosApp/iosApp/Control/iOS/SiloControlClient.swiftiosApp/iosApp/Control/iOS/SiloControlTargetPickerView.swiftiosApp/iosApp/Control/tvOS/RemotePlaybackIdentityManager.swiftiosApp/iosApp/Control/tvOS/TVControlReceiver.swiftiosApp/iosApp/Navigation/AppRouter.swiftiosApp/iosApp/Networking/DeviceLoginModels.swiftiosApp/iosApp/Networking/HTTPClient.swiftiosApp/iosApp/Networking/TokenStore.swiftiosApp/iosApp/Pairing/PairingDeviceAPI.swiftiosApp/iosApp/Screens/Auth/AuthService.swiftiosApp/iosApp/Screens/Player/PlayerView.swiftiosApp/iosApp/Screens/Player/PlayerViewModel.swiftiosApp/iosApp/Screens/Player/RemotePlaybackIdentityNotice.swift
| Protocol negotiation, v2 message round-trips, and `RemotePlaybackClock` | ||
| interpolation/optimistic math live in `iosApp/Tests/SiloControlTests.swift` and | ||
| run through the `SiloTests` target. |
There was a problem hiding this comment.
📐 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.
| 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) | ||
| ) |
There was a problem hiding this comment.
🔒 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.
| private static func parseISO8601(_ value: String) -> Date? { | ||
| ISO8601DateFormatter().date(from: value) | ||
| } |
There was a problem hiding this comment.
🎯 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.swiftRepository: 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.swiftRepository: 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.
Summary
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
SiloControlTests: 9 tests, 0 failuresgit diff --checkSummary by CodeRabbit