Repository navigation
feat(settings): store subtitle and audio track preferences through v2 - #367
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 ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b0f05493cd
ℹ️ 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".
| writeOrder.enqueue("\(kind.rawValue)/\(prefKey)") { previous in | ||
| let auth = await tokenStore.captureOrdinaryRequestAuth() | ||
| await previous?.value |
There was a problem hiding this comment.
Capture the owner before scheduling the write
If a profile switch occurs after saveAudio/saveSubtitle returns but before this new task gets time on TokenStore, the capture observes the replacement profile rather than the profile that made the selection. Every subsequent fence then succeeds for that replacement owner, so the old profile’s track choice can be stored under the new profile—the exact cross-profile write this change is intended to prevent. Capture or pass the originating authority before enqueueing the fire-and-forget work.
Useful? React with 👍 / 👎.
bfb4131 to
b46bf1c
Compare
b0f0549 to
a678385
Compare
b46bf1c to
ffba129
Compare
The detail pages and the player remembered explicit audio and subtitle
picks by writing /api/v1/audio-prefs and /api/v1/subtitle-prefs with
whatever session was current when the request left, so a pick could land
on a profile other than the one that made it.
TrackSelectionPersistence now captures the signed-in owner when a write
is dispatched and sends it through the shared APIv2Client to
PUT/DELETE /api/v2/{audio,subtitle}-prefs/{series_id}. The client sends
only while that owner is current, percent-encodes the key, requires 204
and maps problem responses to typed errors. The preference kind is a
typed enum instead of a free string. The v2 delete answers 204 for an
absent preference, so the old 404 swallow goes away. The four v1
SiloAPI methods are deleted.
The writes are natural_idempotent, but they stay best-effort: a failed
or unanswered write is logged and dropped, and the next explicit pick
sends a fresh one.
Stack-PR: W4-C
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Each audio or subtitle preference write ran as an independent task, so a pick followed quickly by "Auto" could reach the server out of order and leave a stale override. The v2 path adds actor hops before dispatch, which widens that window. Writes for the same kind and key now chain: each starts only after the one dispatched before it has finished, whatever its outcome. The owner is still captured at dispatch, so a profile switch while a write waits drops it instead of sending it for the new profile. Writes for other keys or the other kind are not blocked. Failures stay best-effort (logged, not held), which the PR body records as a deliberate deviation from the plan's failure model. Stack-PR: W4-C Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
a678385 to
a4c472a
Compare
Audio and subtitle picks are now saved through
/api/v2/{audio,subtitle}-prefs/{series_id}for the owner captured when the write is dispatched. Writes for the same track kind and key go out in the order the user picked them.Problem
The detail pages (iOS and tvOS) and the player save explicit audio and subtitle picks so they stay selected the next time the item plays. They wrote them to
/api/v1/audio-prefs/{series_id}and/api/v1/subtitle-prefs/{series_id}through the v1 transport, which used whatever session was current when the request left. If the profile changed in between, the pick could be saved to the wrong profile. These were the last v1 calls for track preferences (inventory rows 38-41).Solution
TrackSelectionPersistencecaptures the signed-in owner (captureOrdinaryRequestAuth) when a write is dispatched and sends it through the sharedSiloAPI.shared.apiV2ClienttoPUT/DELETE /api/v2/{audio,subtitle}-prefs/{series_id}(contract operationsupdateAudioPreference,deleteAudioPreference,updateSubtitlePreferenceanddeleteSubtitlePreference). Call sites inItemDetailView,TVItemDetailViewandPlayerViewModelare unchanged.APIv2Client.writeTrackPreference/deleteTrackPreferencealready existed and had no callers. They now take a typedTrackPreferenceKindinstead of a free string. They send only while the captured owner is current (currentOrdinaryRequestAuth(matchingIdentityOf:)pluswithOwnerFence), sendX-Profile-Id, percent-encode the key, require exactly 204 and map problem+json responses toAPIv2Error.problem.AudioPreferenceUpdate/SubtitlePreferenceUpdateschemas: snake_case, nil members omitted, so an unsetshow_forced_subtitleskeeps the stored override. The audio signature still sendsdefaultandembedded_title.SiloAPI.setSubtitlePref,deleteSubtitlePref,setAudioPrefanddeleteAudioPref.Failure outcomes
All four operations are
natural_idempotent. The definite-failure and uncertain rows deliberately deviate from the plan §9 failure model; see Risks.TrackPrefswith the real error and dropped. Not shown to the user. Playback is not affected.Validation
SiloTests/TrackPreferencesV2Tests SiloTests/TrackSelectionPersistenceTests) passed (17 tests). The same classes underSiloTVTestspassed (17 tests).scripts/ci/check-no-api-v1.shpassed.TrackPreferencesV2Tests(onStubURLProtocol) check the exact PUT body members for audio and subtitle, the-1/offsubtitle-off body with no signature and no forced override,DELETEpaths with a percent-encoded key, that nothing is sent when the owner changed after capture, and that a 200 or a 422 problem is a failure with no retry. Two more tests hold an unanswered subtitle pick and check that the "Auto" DELETE for that key waits for it while an audio write for the same key goes out, and that a write lost to a transport error does not block the next write for its key. The ordering test fails when the chaining is removed.Risks and follow-ups
ItemDetailViewModelandPlayerViewModelis a possible follow-up.show_forced_subtitleskeeps the stored value, so a skipped earlier PUT could drop a forced-subtitle change.DiagnosticsPathTemplateTestsstill uses/api/v1/subtitle-prefsas a path-template vector. Z1 owns that allowlist entry.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 19 of 50 in the Apple API v2 stack. Base:
apiv2-stack/18-settings-writes-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code