Skip to content

feat(remote): approve and deny SiloRemote handoffs through v2 - #362

Merged
Quick104 merged 1 commit into
mainfrom
apiv2-stack/14-siloremote-handoffs-v2
Sep 23, 2026
Merged

Quick104 merged 1 commit into
mainfrom
apiv2-stack/14-siloremote-handoffs-v2

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

The iPhone now looks up, approves and denies a TV's SiloRemote handoff through /api/v2/auth/device*, under the owner it captured when it offered the profile. A profile re-verified mid-handoff can no longer approve under the old owner.

Problem

When the iPhone sends a title to a TV over SiloRemote, it approves the TV's temporary remote-playback sign-in on the server. That approval still used /api/v1/auth/device (lookup), /api/v1/auth/device/approve-handoff and /api/v1/auth/device/deny (inventory rows 19, 20 and 21). Its only ownership check was that some access token existed.

Solution

  • SiloControlClient.prepareRemoteIdentity captures the request owner (CapturedOrdinaryRequestAuth: account, credential owner, profile, profile proof) before sending the offer. It refuses to start if that owner does not match the target server and profile.
  • The lookup, approval and deny go through SiloAPI.shared.apiV2Client: deviceLookup calls GET /api/v2/auth/device, then decideDeviceLogin(approveHandoff: true) calls POST /api/v2/auth/device/approve-handoff (with the required X-Profile-Id). A failed handoff calls decideDeviceLogin(approveHandoff: false), which sends POST /api/v2/auth/device/deny on a best-effort basis.
  • Both APIv2Client methods take an optional expectedAuth. HTTPClient.requestData compares it with sameCredentialIdentity, so a changed credential or profile proof stops the lookup, approval or deny before it is sent. The TV's handoff_ready is accepted only while currentOrdinaryRequestAuth(matchingIdentityOf:) still matches.
  • decideDeviceLogin now requires 200 before it decodes the body (I2).
  • The match check (same match code, client_purpose == "remote_playback", temporary == true) is now the testable SiloControlClient.isRemotePlaybackHandoff.
  • Removed the v1-only DeviceApproveRequest. DeviceLookupResponse is no longer Codable, because nothing decodes it from the wire; pairing and the handoff build it from APIv2DeviceLookup.presentation.

Contract (server 84ed9e596): approveDeviceHandoff is profile_scoped, requires X-Profile-Id, and has x-silo-retry-safety: domain_identity. denyDeviceLogin is authenticated and domain_identity. Both return 200 {status}. A domain-identity retry is safe, so the normal 401 refresh-and-resend stays. getDeviceLogin is public; the phone still sends its bearer and profile there, which the server accepts.

Failure outcomes

Outcome Behavior
Definite success (200 with the matching status) Wait for the TV's handoff_ready, re-check the owner, then launch playback.
Definite failure under an unchanged owner (non-2xx, problem+json such as 409 or 410, status mismatch) Send a best-effort deny, clear the pending handoff, and show the error once (fail(...)). A 410 does not touch the tokens.
Changed owner (profile or profile proof replaced mid-handoff) The deny is refused before dispatch, so the TV's request expires on the server. The phone clears the pending handoff and fail(...) drops the control session. The TV sees the connection close and cancels its handoff (handleConnectionClosed → cancelPendingHandoff), so it does not wait for the server-side expiry.
Uncertain (sent, no response) Treated as a failure: best-effort deny (refused if the owner changed, as above), and the user retries the play action. The request code is single-use and expires on the server. The client never replays the approval on its own.

Validation

  • iOS, tvOS and macOS builds passed.
  • iOS tests (SiloTests/AuthDeviceV2Tests SiloTests/SiloControlTests SiloTests/PairingDeviceAPITests SiloTests/PairingCoordinatorTests) passed (45 tests, 0 failures).
  • tvOS tests (SiloTVTests/AuthDeviceV2Tests SiloTVTests/PairingDeviceAPITests) passed (28 tests, 0 failures).
  • scripts/ci/check-no-api-v1.sh passed. SiloControlClient.swift no longer contains a /api/v1 path.
  • New tests:
    • testHandoffLookupApproveAndDenyUseTheV2Wire checks paths, methods, the code query, the bearer, X-Profile-Id and the {"code"} body.
    • testHandoffDecisionFailuresAreTyped: a deny answered as approved is refused, and a 410 problem is typed and leaves the tokens in place.
    • testHandoffApprovalRefusesAChangedProfileProofBeforeDispatch: nothing is sent after the profile proof changes.
    • testHandoffApprovesOnlyATemporaryRemotePlaybackRequest (iOS only).
  • The completed stack passed the full iOS suite (1981 tests) and tvOS suite (1792 tests) with 0 failures, built for macOS and passed the v1 path guard. Every branch in the stack builds on its own.
  • Not run: a manual phone-to-TV handoff against a live v2 server.

Risks and follow-ups

  • The full handoff has no end-to-end test. SiloControlClient depends on ServerRegistry and the singleton TokenStore, so only the wire calls and the match predicate are covered.
  • Fencing the deny on the full owner means a profile switch mid-handoff leaves the TV's request pending on the server until it expires. An account-only fence would let that deny go out. The TV already abandons its side when the phone drops the session, so the only leftover is the unused server-side request.
  • Errors reach the user through APIv2Error.localizedDescription, so a 409 or 410 shows the server's problem detail. There is no handoff-specific copy.
  • deviceLookup and decideDeviceLogin stay in APIv2Client.swift because they already existed there. This PR adds no new client methods.

AI disclosure

Code and description written by Claude Opus 5.5 (claude-opus-5-5) agents in Claude Code (T3 Code), orchestrated by a Claude Code workflow.


Part 14 of 50 in the Apple API v2 stack. Base: apiv2-stack/13-pair-devices-through-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: c8eef77b-d0c8-4f17-989d-cfe5de0c4ce6

📥 Commits

Reviewing files that changed from the base of the PR and between 311dca6 and 8d5ea7e.

📒 Files selected for processing (5)
  • iosApp/Tests/AuthDeviceV2Tests.swift
  • iosApp/Tests/SiloControlTests.swift
  • iosApp/iosApp/Control/iOS/SiloControlClient.swift
  • iosApp/iosApp/Networking/APIv2/APIv2Client.swift
  • iosApp/iosApp/Networking/DeviceLoginModels.swift

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T13:38:26.378591Z 8d5ea7e 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.

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

ℹ️ 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 +369 to +371
guard await TokenStore.shared.currentOrdinaryRequestAuth(matchingIdentityOf: auth) != nil else {
throw SiloControlHandoffError.identityChanged
}

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 Tear down the TV identity after a late owner change

When the owner changes after approval is dispatched but before handoff_ready arrives, this guard throws only after the TV has installed the temporary credentials. The catch then cannot send its fenced deny, and closing the control connection does not clean up the installed scope: handleConnectionClosed only calls cancelPendingHandoff, while the TV has already cleared its pending task, and its ready timeout exits once the connection ID changes. The stale identity can therefore survive and be reused by a later handoff from the same controller; explicitly tell the TV to end the activated identity or make disconnect tear it down.

Useful? React with 👍 / 👎.

Comment on lines +311 to 314
guard let auth = await TokenStore.shared.captureOrdinaryRequestAuth(), auth.accessToken != nil,
ServerRegistry.serverIdsMatch(auth.account.serverId, server.id),
auth.profileId == profileId else {
throw SiloControlHandoffError.identityChanged

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 Recheck the owner before accepting a reused ready

The captured owner is checked again only on the challenge/approval path. If the TV already holds an identity, .ready returns directly, so a credential generation or profile proof can change during offeredEndpoints, offer delivery, or the wait while the active server and profile IDs remain unchanged; the phone then launches through the TV's identity from the old owner. Apply currentOrdinaryRequestAuth(matchingIdentityOf:) before returning from the reused-ready branch as well.

Useful? React with 👍 / 👎.

@Quick104

Copy link
Copy Markdown
Contributor Author

Code review summary

Reviewed head: f3adc9ff (apiv2-stack/14-siloremote-handoffs-v2).

Process: an adversarial review of this PR's diff with each candidate finding independently verified before any fix, a simplify pass for medium and larger PRs, and a whole-stack review across contract conformance, authority and failure handling, data integrity, user-visible behavior and cross-PR integration.

Verified findings, all fixed on this branch:

  • minor: The PR body's failure table says a changed owner gets a best-effort deny, but the code never sends that deny
    Refuted or unconfirmed after verification: 1 (not acted on).

Validation: this branch builds on its own for iOS, tvOS and macOS, and its focused tests passed. The completed stack passed the full iOS suite (1981 tests) and tvOS suite (1792 tests) with 0 failures, the macOS build and the v1 path guard. The final stack was also exercised on iOS and tvOS simulators against a v1/v2 bridge server: sign-in (password and QR), restore, browse, search, detail, favorites and watchlist, playback (direct play, transcode, subtitles, stop), audiobooks, downloads with offline playback, settings, requests, profiles, push registration and diagnostics. Server logs showed no /api/v1 request from the new builds except the retained health probe.

Remaining: no open verified findings. Merge in stack order.

Mergeability: 8/10 — conditional. The approach holds up and every verified finding is fixed. Conditions: this PR's CI must pass (it was pending at review time), and the owner still plans a physical-device check of the completed stack.

Review by Claude Opus 5.5 (claude-opus-5-5) agents in Claude Code (T3 Code).

@Quick104
Quick104 force-pushed the apiv2-stack/13-pair-devices-through-v2 branch from 05bbc97 to 8fda12a Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/14-siloremote-handoffs-v2 branch from f3adc9f to 711abc6 Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/13-pair-devices-through-v2 branch from 8fda12a to a45cbbe Compare September 23, 2026 13:33
Base automatically changed from apiv2-stack/13-pair-devices-through-v2 to main September 23, 2026 13:33
Sending a title to a TV still looked up, approved and denied the TV's
remote-playback request through /api/v1/auth/device, with only a check
that some access token existed.

The handoff now captures the request owner (account, credential, profile
and profile proof) before offering the profile, and reads, approves and
denies the request through the shared APIv2Client's GET
/api/v2/auth/device, POST /api/v2/auth/device/approve-handoff and POST
/api/v2/auth/device/deny. Both calls take the captured owner, so a
changed profile proof refuses the approval before it is sent, and the
ready frame is accepted only while that owner still holds. The v1-only
DeviceApproveRequest body is gone and DeviceLookupResponse is no longer
decoded from the wire.

Stack-PR: W5-D
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the apiv2-stack/14-siloremote-handoffs-v2 branch from 711abc6 to 8d5ea7e Compare September 23, 2026 13:33
@Quick104
Quick104 merged commit 10cea14 into main Sep 23, 2026
4 of 7 checks passed
@Quick104
Quick104 deleted the apiv2-stack/14-siloremote-handoffs-v2 branch September 23, 2026 13:35
Quick104 added a commit that referenced this pull request Oct 11, 2026
…734)

After a seek or a resume into densely typeset ASS, AetherEngine's embedded
subtitle drain fell behind the playhead, so signs stayed missing until the
passage ended, and at the start of a file they arrived about 1.5 s late.
Pin the fork to 87f85740 (Silo-Server/AetherEngine#20), which lets a text
drain catch up in one tick and stops the #362 hole hold from firing on
re-harvest seams the forward prefetch has read. The pin also brings in
AetherEngine#18: a paused seek on the software path shows the target frame.

The notices list AetherEngine#18 and #20, and the CI selector's
build-input snapshot and seal are refreshed for the revision line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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