Repository navigation
feat(auth): run tvOS QR sign-in on v2 - #360
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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
62dfb06 to
ca3214f
Compare
The tvOS QR sign-in still opened and polled its pairing request through /api/v1/auth/device/start and /api/v1/auth/device/poll. A 1.0 server answers those with 410. The v1 poll answer also carried no verified account id, so a QR sign-in installed an unverified account binding. On a v1-only server the screen showed "Couldn't start sign-in" followed by the raw error instead of the server-update message. QRLoginViewModel now goes through AuthService to the shared APIv2Client: POST /api/v2/auth/device/start (expects 201) and POST /api/v2/auth/device/poll. Both are public and non_retryable, so each call is dispatched once with no bearer. An approved poll installs the nested TokenPair and binds TokenPair.user.id as the verified account. installSession now requires an account id because every caller has one. The poll loop follows the server's poll_after. A failed poll is classified in one place. A v1-only server (legacy 404) or a 410 client_upgrade_required answer shows the existing update message. A 404 problem means the request expired. An incomplete approval, a failed session install or an account change ends the attempt, because the tokens are issued only once. Network errors and other server errors keep polling until the code expires. A start failure caused by an update requirement shows only the update message. Stack-PR: W5-B Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The approved-poll test called AuthService.installSession itself, copying the view model's step instead of running it. A change that bound the wrong account, accepted a temporary session or ignored poll_after would not have failed any test. QRLoginViewModel used the shared AuthService and TokenStore, so tests could not run it. QRLoginViewModel now takes its AuthService and TokenStore through init, defaulting to the shared instances, so TVLoginView is unchanged. The new tests drive begin() against the stubbed server: start, a pending poll and an approved poll bind TokenPair.user.id, and settling in time shows the loop followed poll_after. An approved temporary answer ends in an error and installs no tokens. Stack-PR: W5-B Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
c1182a6 to
4e75806
Compare
The tvOS QR sign-in now starts and polls through
/api/v2/auth/device/*, binds the verified account id from the approved poll, and shows the existing update messages when the server or app needs an update.Problem
The tvOS QR sign-in still called
POST /api/v1/auth/device/startandPOST /api/v1/auth/device/poll(inventory rows 11 and 12). A 1.0 server answers those with 410. The v1 poll answer also had no verified account id, so a QR sign-in installed an unverified account binding. On a v1-only server, the screen showed "Couldn't start sign-in." followed by the raw error instead of the existing server-update message.Solution
QRLoginViewModelgoes throughAuthServiceto the sharedSiloAPI.shared.apiV2Client:startDeviceLogincallsPOST /api/v2/auth/device/startand expects 201.pollDeviceLogincallsPOST /api/v2/auth/device/poll, expects 200, and returns the validatedAPIv2DevicePoll.publicandnon_retryable. Each call is dispatched once, with no bearer and no refresh replay.APIv2Clientalready enforces this, andAuthDeviceV2Testscovers it.TokenPairand bindstokens.user.idas the verified account id.AuthService.installSession(accountID:)is now non-optional, because both callers (password and QR) have a verified id. The QR flow refuses an approved poll markedtemporary, since that flag belongs to a SiloRemote handoff.interval, then waits for each poll'spoll_after, as Android'sDeviceLoginRepositorydoes.QRLoginViewModel.pollFailure(for:)classifies every failed poll (F5 / D7):/api/v2route, or the recordedserverUpdateRequiredverdict) shows "This server needs to be updated before this version of Silo can use it." The flow stops.client_upgrade_requiredshows "Update Silo to keep using this server." The flow stops, and no tokens are touched.QRLoginViewModelnow takes itsAuthServiceandTokenStorethroughinit, defaulting to the shared instances, so tests can drive it.TVLoginViewis unchanged.AuthServicestart and poll methods are removed.DeviceLoginPollResponse,DeviceLoginPollRequestand the v1 paths inPairingDeviceAPIstay because pairing still uses them; W5-C removes them.Failure outcomes
Both operations are
non_retryable.pending: wait forpoll_after.approved: install the tokens and bind the account.denied/expired/consumed: show the terminal messageapproved, the next poll returnsconsumedand the screen says the code was already usedValidation
SiloTests/AuthDeviceV2Tests SiloTests/AccountSessionPersistenceTests) passed (48 tests, 0 failures). The same classes underSiloTVTestspassed (48 tests, 0 failures).scripts/ci/check-no-api-v1.shpassed.AuthDeviceV2Testsrun onStubURLProtocol:client_upgrade_requiredshows the app-update message. A 503 problem and a timeout keep polling.QRLoginViewModelruns against a stubbed server: start, a pending poll withpoll_after: 1and an approved poll end in.approved, andTokenPair.user.idbecomes the durable account id. The startintervalis 30 s and the test settles within 10 s, so it passes only when the loop followspoll_after. Each poll sends{"device_code": …}.temporarypasses wire validation, but the view model still ends in.errorand installs no tokens.poll_after, makes these two tests fail.Risks and follow-ups
non_retryable) causes this, so this PR does not change it.PairingDeviceAPI,SiloControlClientand the pairing-only models inDeviceLoginModels.swiftstill use v1 device paths. W5-C and W5-D move them.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 12 of 50 in the Apple API v2 stack. Base:
apiv2-stack/11-sign-in-through-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code