Repository navigation
feat(pairing): pair devices through v2 - #361
Conversation
|
Warning Review limit reachedNext included review available in 8 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (12)
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. Comment |
There was a problem hiding this comment.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code review summaryReviewed head: 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:
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 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 ( |
17e6bdf to
c1182a6
Compare
05bbc97 to
8fda12a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8fda12aabb
ℹ️ 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".
| let value: APIv2DeviceStart = try await post( | ||
| serverURL, | ||
| "/api/v1/auth/device/start", | ||
| "/api/v2/auth/device/start", |
There was a problem hiding this comment.
Migrate the handoff controller before switching the receiver
When a handoff is not reused, this now creates and polls a v2 request, but SiloControlClient.sendHandoff still looks up, approves, and denies that challenge through the v1 routes at SiloControlClient.swift:351-374. On servers that retire v1 with HTTP 410—the target of this migration—the phone therefore cannot approve the v2 challenge, so every fresh SiloRemote handoff fails after displaying its challenge. Move the controller lookup/approve/deny calls to v2 in the same rollout, or defer this receiver switch.
Useful? React with 👍 / 👎.
c1182a6 to
4e75806
Compare
Phone-to-TV pairing and the SiloRemote handoff still opened, polled, looked up and approved device logins through /api/v1/auth/device/*. A 1.0 server answers those with 410. These calls target an explicit server URL rather than the active server, so they bypass APIv2Client and its recorded probe verdict. A v1-only server's plain 404 therefore ended as a generic "Something went wrong signing in". The paired session was also installed with no verified account id. PairingDeviceAPI now calls /api/v2/auth/device/start (expects 201), /poll, /capability, GET /api/v2/auth/device and /approve. It classifies failures the way APIv2Client.mapErrors does: a problem document becomes APIv2Error.problem, Go's plain 404 becomes serverUpdateRequired, any other status becomes httpStatus, and transport failures stay URLError. Each request is dispatched once; approve is never re-sent, even after a lost answer. The TV receiver reads the nested TokenPair, binds TokenPair.user.id as the verified account at install, and follows poll_after. An update requirement ends the attempt with the existing update copy and a new update_required failure code, which older phones read as auth_failed. The phone summarises that code, and an approval that fails with 409 or 410 says the request was already decided or expired instead of blaming the connection. The SiloRemote handoff gates on an available capability document and takes the session expiry from the validated poll. The v1 poll request and response and the capability presentation model are deleted. Stack-PR: W5-C Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Pairing now installs the paired session through installAccountSession instead of saveTokens. Only saveTokens recorded the essential "session credential event" breadcrumb when the session could not be written, so a diagnostics report for a pairing that failed at the Keychain write had nothing explaining the failure. installAccountSession now records the sessionInstall/failed breadcrumb with the fixed persistence-failure reason for every installer (pairing, login and saveTokens), and saveTokens drops its duplicate. A test fails the session write through the injected persistence and reads the breadcrumb back. Stack-PR: W5-C Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
8fda12a to
a45cbbe
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a45cbbe335
ℹ️ 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".
| private static func isMissingRequest(_ error: Error) -> Bool { | ||
| switch error { | ||
| case APIv2Error.problem(let problem): return problem.status == 404 | ||
| case APIv2Error.httpStatus(404): return true |
There was a problem hiding this comment.
Retry non-problem 404 poll responses
When a reverse proxy returns its own HTML 404 while the device request is still live, PairingDeviceAPI deliberately classifies it as APIv2Error.httpStatus(404) (as covered by PairingDeviceAPITests.swift:91-95), but this branch treats it as definitive expiry. That bypasses the transient proxy-error retry immediately below, ends pairing, and incorrectly tells the user the code expired. Only a typed v2 problem 404 proves the request is missing; a bare 404 should remain retryable.
Useful? React with 👍 / 👎.
Phone-to-TV pairing and the tvOS SiloRemote handoff now start, poll, check capability, look up and approve through
/api/v2/auth/device/*. A v1-only server reads as "needs an update" on both screens, and the TV binds the paired session to the verified account id.Problem
Pairing and the handoff still used
/api/v1/auth/device/*for start, poll, capability, lookup and approve (inventory rows 13-18). A 1.0 server answers every one of those with 410.These calls target an explicit server URL (the pushed or chosen server), not the active one. They go through
PairingDeviceAPI's own URLSession and skipAPIv2Client.gate()and its recorded probe verdict. After a plain path switch, a v1-only server's404 page not foundwould read as "request expired" on the TV and as "Couldn't reach … to approve" on the phone, not as "server needs an update". The TV also installed the paired session with no verified account id.Solution
PairingDeviceAPIcallsPOST /api/v2/auth/device/start(expects 201),POST /api/v2/auth/device/poll,GET /api/v2/auth/device/capability,GET /api/v2/auth/device?code=andPOST /api/v2/auth/device/approve(all expect 200). It decodes the existingAPIv2DeviceStart,APIv2DevicePoll(withvalidated()),APIv2DeviceLookup,APIv2DeviceCapabilityandAPIv2DeviceDecisionmodels withHTTPClient.makeJSONDecoder().APIv2Client.mapErrors: a problem document becomesAPIv2Error.problem, Go's plain 404 (APIv2Probe.isLegacyNotFound) becomesAPIv2Error.serverUpdateRequired, any other status becomesAPIv2Error.httpStatus, and transport failures stayURLError. A 2xx other than the expected status becomesincompleteAuthResponse.UpdateRequirement(error)therefore recognizes both the legacy 404 and a 410client_upgrade_required.non_retryable. Approve isdomain_identity, but it is also never re-sent: this path has no refresh, and a lost answer is reported rather than approved again. This is the single-dispatch exemption the plan asks for. The request never entersHTTPClient, soshouldAttemptRefreshneeds no change.ReceiverPairingCoordinator): reads the nestedTokenPair, bindsTokenPair.user.idthroughinstallAccountSession(accountID:clearProfile: false)(previouslysaveTokenswith no account), and followspoll_after. An update requirement on start or poll ends the attempt with the existing update copy (UpdateRequirement.message) and sends a newupdate_requiredfailure code to the phone. Under the existingPairingFailureCode(wire:)rule, older phones read that code asauth_failed. A 404 problem still means "expired". An incomplete approval ends the attempt, because the tokens are issued once. Other errors keep polling, as before.TokenStore.installAccountSessionnow writes the essential "session credential event" breadcrumb (phase: sessionInstall,outcome: failed, fixed reason) when it cannot install the session.saveTokensused to write it. Pairing no longer callssaveTokens, so without this move a hosted diagnostics report for a pairing that failed at the Keychain write would have no line explaining it.saveTokensdrops its own copy so the line is not written twice. Login also callsinstallAccountSession, so a failed login install now records the same breadcrumb.CompanionPairingCoordinator): a lookup that fails with an update requirement is summarised asupdate_required. A failed approval now names the cause: the update message, "already approved or declined" (409), "code expired" (410 or 404 problem), the old connection message for a transport failure, or "couldn't approve the sign-in" for anything else.RemotePlaybackIdentityManager): the capability check now requiresstate == "available",allowed != false,remote_playback_handoffand the protocol version. The session expiry comes from the validated poll; the 24-hour fallback is gone. A 404 problem on poll maps toexpired, and an incomplete approval maps toinvalidResponse. An update requirement surfaces through the error'slocalizedDescription.DeviceLoginPollRequest,DeviceLoginPollResponse,DeviceLoginCapabilityResponse,APIv2DeviceCapability.presentation,PairingDeviceAPI.APIError.http/decodeand the custom date formatters.DeviceLoginStartRequest/DeviceLoginStartResponsestay as the v2 request body and the start presentation shared with QR sign-in.DeviceLookupResponseandDeviceApproveRequeststay becauseSiloControlClient(W5-D) still uses them.Failure outcomes
non_retryable)auth_failedotherwiseURLError, so the attempt shows "unreachable". Not re-sentnon_retryable)domain_identity, sent once)cancel(approve_failed)Validation
PairingDeviceAPITests(new),CompanionPairingCoordinatorTests,ReceiverPairingCoordinatorTests,ServerSessionPersistenceTests,PairingProtocolTests,RemotePlaybackRoutingTestsandAuthDeviceV2Testspassed: 70 tests, 0 failures. tvOS tests for the same classes (the companion class is iOS-only) passed: 30 tests, 0 failures.AccountSessionPersistenceTests,PairingCoordinatorTestsandPairingDeviceAPITestspassed (40 tests, 0 failures), and tvOS tests forAccountSessionPersistenceTestsandPairingDeviceAPITestspassed (40 tests, 0 failures).scripts/ci/check-no-api-v1.shpassed.PairingDeviceAPI.swiftandDeviceLoginModels.swiftno longer contain/api/v1.PairingDeviceAPITestsuseStubURLProtocolto check:httpStatusclient_upgrade_requiredas an app updatestateAccountSessionPersistenceTests.testFailedVerifiedInstallRecordsSessionInstallBreadcrumbfails the session write through the injected persistence and reads thesessionInstall/failed/persistenceUnavailablebreadcrumb back from the early-boot buffer. It fails without theTokenStorechange.persistServer's switch fromsaveTokenstoinstallAccountSessionhas no direct test, because it runs against the sharedTokenStore,HTTPClientandServerRegistrysingletons.Risks and follow-ups
persistServernow fails, and rolls back, if a SiloRemote temporary scope is active during setup pairing.installAccountSessionrefuses that case, whereassaveTokenssilently wrote the tokens into the temporary scope. Pairing runs from the TV setup screen, so this should not happen in practice.update_requiredfailure code. A phone from before this change shows it as the generic "couldn't finish signing in".DeviceLookupResponseandDeviceApproveRequestfromSiloControlClientand should delete them once it moves to v2.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 13 of 50 in the Apple API v2 stack. Base:
apiv2-stack/12-tvos-qr-sign-in-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code