Repository navigation
feat(library): read and toggle favorite, watchlist and watched through v2 - #387
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: 12e16ce670
ℹ️ 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".
| if error is APIv2Error { return .definite } | ||
| // Cancellation and anything unrecognized may have left the device. | ||
| return .unconfirmed |
There was a problem hiding this comment.
Classify preflight update requirements as definite
When an expired or near-expiry bearer triggers scopedAuthRefreshedBeforeDispatch, the refresh helper can throw UpdateRequirement before the favorite/watchlist/watched request is sent. Because that error is neither HTTPError nor APIv2Error, this fallback classifies it as unconfirmed, records a hold, and shows “Change Not Confirmed” instead of “Update Required”; subsequent taps are then blocked until the user discards the nonexistent mutation. Treat UpdateRequirement as a definite pre-dispatch failure.
Useful? React with 👍 / 👎.
12e16ce to
a6d7304
Compare
f6c22f8 to
83b1a84
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a6d73046ce
ℹ️ 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".
| isFavorite = userState.isFavorite | ||
| inWatchlist = userState.inWatchlist |
There was a problem hiding this comment.
Apply played from the v2 user-state payload
When a detail response contains user_state.played but omits user_data—a payload shape this commit's testDetailProjectionCarriesTheViewersFlags explicitly accepts—this block copies only favorite and watchlist. The later isWatched = enriched.userData?.played ?? false therefore renders a watched item as unwatched and makes the next toggle request the wrong state. Apply userState.played as well and preserve it through playback-metadata enrichment.
Useful? React with 👍 / 👎.
| // Every APIv2Error is either a refusal before dispatch (`gate()`) or a | ||
| // decoded server answer. | ||
| if error is APIv2Error { return .definite } |
There was a problem hiding this comment.
Hold mutations after unexpected successful statuses
If a mutation is applied but the server or an intermediary returns an unexpected 2xx status such as 200 instead of 204, the API methods throw APIv2Error.httpStatus, and this blanket branch classifies it as definite. The caller then releases the mutation and permits another send even though the server may already have acted; the repository's shared APIv2MutationOutcome correctly treats unexpected 2xx statuses as uncertain for this reason. Classify those statuses as unconfirmed rather than definite.
Useful? React with 👍 / 👎.
83b1a84 to
08038f1
Compare
…h v2 Favorite, watchlist and watched still went through /api/v1. The card dispatchers from c23903c (PersonalListSync, MediaCardWatchedSync), item detail, Home and SectionRow each called SiloAPI with no captured owner, and every failure was treated the same way: revert and, in most places, say nothing. Item detail also made two extra existence GETs on every load even though the v2 detail read already returns user_state (F28). All six writes now go through one dispatcher, PersonalStateSync, which calls the existing APIv2Client membership and watched methods under a captured owner. Every v2 write here is non_retryable, so the dispatcher sorts each result into the plan's failure model: - a 204 under the same owner is applied, and callers invalidate their caches (including in-flight Home reads); - a server answer or a request that never connected is a definite failure: revert, report once, log the cause; - a request that was sent but got no answer is held for its owner, item and flag. It is never re-sent, later taps report the hold, and "Discard Held Change" releases it and drops the item's cached state; - an owner change or a second in-flight change to the same flag is skipped and applies nothing locally. Holds are cleared on profile switch and sign-out. Item detail reads favorite and watchlist from the v2 detail's user_state. The episode and tvOS series checks, which have no user_state, use the v2 membership GET under the page's owner. The v1 SiloAPI methods and the now-unused HTTPClient.exists helper are deleted. Stack-PR: W5-M Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A favorite, watchlist or watched write refused because the server is v1-only (gate() reports serverUpdateRequired) or because the server no longer accepts this app (HTTP 410 client_upgrade_required) showed "Your change wasn't saved. Please try again." Retrying can never succeed there, and the detail-page toggles and season watched alerts now surface that failure. PersonalStateOutcome.failed and PersonalStateNotice.failed now carry the UpdateRequirement classified from the error. The notice shows "Update Required" with the server-update or app-update message, and the series watched alerts on iOS and tvOS route an update-required failure to that notice instead of "Please check your connection and try again." Stack-PR: W5-M Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Favorite, watchlist and watched toggles (and the other single-dispatch writes on the refresh exclusion list) never refresh on a 401. Once the access token expired, the first such toggle got a 401, reverted, and failed the same way on every retry until some unrelated read happened to refresh the token. On main these toggles used v1 routes that refreshed and retried. HTTPClient now checks the captured bearer before dispatch on both the scoped and the ordinary path. When it has expired or expires within the margin MediaAccessTokenExpiry uses (at most 60 s), it joins the shared refresh flight and recaptures credentials under the same identity, account and expected-auth checks the 401 path uses, then sends once. Nothing has been sent at that point, so this is safe for non_retryable operations. When no fresh bearer comes back and the old one has expired, the request is not sent and fails with a 401 as the 401 path would. Stack-PR: W5-M Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
a6d7304 to
5453ca8
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Problem
Favorite, watchlist and watched still used
/api/v1(inventory rows 64-68):SiloAPI.isFavorite/isInWatchlist(v1http.exists),toggleFavorite,toggleWatchlistandsetWatched.PersonalListSyncinPersonalListActions.swiftandMediaCardWatchedSync, used by MediaCard, TVMediaCard, EpisodeThumbCard and the Home feed cards), seven mutation sites inItemDetailViewModel,HomeViewModel.setWatched, and theSectionRowfallback used by Browse and Recommendations.None of these calls captured an owner, so a tap that finished after a profile or server switch could write that item's state into the new owner's caches. Every failure looked the same: the UI reverted, and detail pages and the SectionRow fallback reported nothing. The v2 writes are all
x-silo-retry-safety: non_retryable, so "sent but no answer" needs its own handling. Item detail also sent two existence GETs on every load, even though the v2 detail it already reads returnsuser_state(audit F28).Solution
One dispatcher. The new
PersonalStateSync(Components/PersonalStateSync.swift) sends each favorite, watchlist or watched change once, under a captured owner, through the existingAPIv2Client.setFavoriteMembership/setWatchlistMembership/setWatchedState. Those methods are unchanged: they already assert 204, sendX-Profile-Id, fence withwithOwnerFence, and are excluded from refresh-and-resend inHTTPClient.shouldAttemptRefresh. After a 204, the dispatcher checks the owner again before any caller writes local state. It returns aPersonalStateOutcome:.applied)gate()update-required, no server URL), or a transport failure that never reached the server (no connection, DNS, cannot connect, TLS handshake).failed)UpdateRequirementclassifies the error (agate()refusal on a v1-only server, or HTTP 410client_upgrade_required), every surface instead shows "Update Required" with the server-update or app-update message and no "try again". Log the real cause. Nothing is held, so the next tap sends normally..held).skipped)Holds live in memory (
PersonalStateHolds). They are keyed withsameCredentialIdentityand cleared on profile switch and sign-out (AuthService.clearPerProfileCaches/clearAllCaches). After a relaunch, the item's state is re-read from the server, which decides what actually landed.Callers.
PersonalListSyncandMediaCardWatchedSyncnow return outcomes.MediaActionFeedbackpresents both notices for every card and episode rail.ItemDetailViewModelcaptures the owner when a detail load starts and uses it for every read and write on the page. The favorite, watchlist and watched toggles on the detail page now report failures instead of reverting silently.SeriesDetailContent,TVSeriesDetailView, the phone episode rail/carousel andTVEpisodeRailcarry outcomes. Their existing "Couldn't Update Watched Status" copy is kept for ordinary failures; a held change adds the discard notice, and an update-required failure uses the shared "Update Required" notice.HomeViewModel.setWatcheddispatches through the same path. A held change shows the discard notice instead ofactionError.SectionRowfallback reports through its ownMediaActionFeedback.Reads (F28).
ItemDetailgainsuserState, projected from the v2 detail'suser_state.loadDetailsets favorite and watchlist from it and drops the two per-load GETs. An absentuser_statekeeps the cached value and is not read as all-false.user_state, so the per-episode fan-out and the tvOS series card check useAPIv2Client.personalMembershipunder the page owner.Expired bearers are renewed before sending. The single-dispatch writes on
HTTPClient's refresh exclusion list, these toggles included, never refresh on a 401. On main the toggles used v1 routes that refreshed and retried; on v2, once the access token expired, the first toggle got a 401, reverted, and failed the same way on every retry until an unrelated read refreshed the token.HTTPClientnow checks the captured bearer before dispatch on both the scoped and the ordinary path. When it has expired, or expires within theMediaAccessTokenExpirymargin (at most 60 s), the request joins the shared refresh flight and recaptures credentials under the same identity, account and expected-auth checks the 401 path uses, then sends once. Nothing has been sent at that point, so this is safe fornon_retryableoperations. If no fresh bearer comes back and the old one has expired, the request is not sent and fails with a 401, as the 401 path would. Public auth paths are exempt. This applies to every request throughHTTPClient, not just the personal-state writes.Deleted:
SiloAPI.isFavorite,isInWatchlist,toggleFavorite,toggleWatchlist,setWatched(8 v1 path lines out ofSiloAPI.swift), andHTTPClient.exists, which only served the v1 existence checks.Validation
PersonalStateSyncTests,CatalogV2Tests,HomeSectionsMutationTestsandUpdateRequirementTests.DetailDismissalNavigationTests,HorizontalMediaRailTests,LibraryDetailScopeTests,SeriesSeasonSelectionTests,SeriesHierarchyLoadingTestsandSeriesEpisodeWindowTests. The four of them that build for tvOS passed there too.PersonalStateSyncTestsrun onStubURLProtocolthroughAPIv2TestStub:PUT/DELETEonce withX-Profile-Idand appliescannotConnectToHostare definite failures with no hold, and the next tap sendsnetworkConnectionLoston mark-watched is held; later set and clear taps send nothing, another flag or item still sends, and discarding releases the holdtimedOuthold belongs to its profile, andreset()clears itclient_upgrade_requiredproblem and agate()refusal on a v1-only server (nothing sent) are definite failures whose notice carries the app-update or server-update message; a 410 with another problem type keeps the generic copyactionErroruser_stateand leaves it nil when absentscripts/ci/check-no-api-v1.shpassed andscripts/ci/check-no-api-v1.test.shpassed.SiloAPI.swiftdrops from 57 to 49 v1 lines; the allowlist is not edited (it is a ceiling).withOwnerFence/sameCredentialIdentity) iniosApp/iosApp: 60 before, 62 after.Risks and follow-ups
UserItemStatePort.abandonPersonalWrite).DurableCommandStore, because nothing is queued for later dispatch.APIv2Client.personalMembershipfails to decode a legacy plain-text 404 and does not map it toserverUpdateRequired. Every read in this PR usestry?and keeps the last known value.HTTPClientrequest whose bearer is about to expire: the request waits for the shared refresh instead of going out and meeting a 401. Only the two personal-state tests above cover it directly.PersonalStateSynckeeps its own sent/never-sent rules here. W5-E moves them onto the sharedAPIv2MutationOutcome(added in W5-O), which also holds an undeclared 2xx or an unreadable answer instead of failing it.HTTPClientDiagnosticsClassificationTestsstill lists the/api/v1/favorites/%@path template. That class belongs to W5-W2 / Z1.SectionRow.swift.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 39 of 50 in the Apple API v2 stack. Base:
apiv2-stack/38-personal-collections-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code