Repository navigation
feat(collections): manage personal collections through v2 - #386
Conversation
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.
|
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 |
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:
Note: Personal collection create, rename and delete have no navigation entry point on iOS (the same on main), so they were covered by tests, not by runtime validation. 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: f6c22f8664
ℹ️ 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".
| replaceGroup(editor.value) | ||
| editorVersion = editor.version |
There was a problem hiding this comment.
Seed edit drafts from the canonical read
When a group or collection changes after the list load but before this editor read, the code pairs the fresh ETag with a draft that GroupActionSheet still initializes from the stale enum value. For example, if another device renames a group from A to B, this read installs B's ETag while the text field remains A; tapping Save submits A with the fresh tag, so the server accepts the overwrite instead of returning 412. Update the active sheet's name or move target from editor.value before enabling confirmation.
Useful? React with 👍 / 👎.
| _ = try await api.createCollection(name: name) | ||
| newCollectionName = "" | ||
| showCreateSheet = false |
There was a problem hiding this comment.
Scope collection-create completion to its originating sheet
If the user cancels or interactively dismisses the create sheet while its POST is in flight and then opens a new create sheet, the old request's success clears newCollectionName and closes the newly opened sheet; its failure similarly publishes an error into that new sheet. Capture a create-sheet generation, as the group-action flow does, and only mutate sheet-local state when the originating generation is still active.
Useful? React with 👍 / 👎.
9dc91f4 to
8af5c19
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: 83b1a84f2d
ℹ️ 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".
| break | ||
| case .rename(let group), .delete(let group): | ||
| let editor = try await api.collectionGroupEditor(id: group.id) | ||
| guard pendingGroupAction?.id == action.id else { return } |
There was a problem hiding this comment.
Scope editor reads to the sheet generation
If an edit sheet is dismissed and the same action for the same item is reopened before its first editor read finishes, this ID check still succeeds because both sheets have the same action.id. The earlier request can therefore install its ETag, clear reload state, or handle a 404 against the newly opened sheet; it may even enable confirmation while the new sheet's own read is still pending. Capture and validate sheetGeneration (or an editor-request token) across the await rather than comparing only the stable action ID.
Useful? React with 👍 / 👎.
| let capabilities = try await api.collectionCapabilities() | ||
| groupSupport = capabilities.supportsGroups ? .available : .unavailable |
There was a problem hiding this comment.
Preserve a concurrent 501 capability verdict
When a capability refresh is already in flight while a group mutation returns 501, markGroupsUnsupported sets .unavailable, but the older capability response can subsequently reach this assignment and restore .available. This is possible on a previously loaded page because loadCollections() retains the prior available state while refreshing, so group controls remain usable during the request; a stale groups: true response then defeats the definitive mutation result and exposes operations that continue to fail. Tokenize capability reads or make the 501 verdict sticky against requests started earlier.
Useful? React with 👍 / 👎.
8af5c19 to
0c0a415
Compare
The personal Collections screen listed, created, moved, renamed and deleted
collections and groups through /api/v1/collections, and the collection
detail grid read /api/v1/collections/{id}/items with offset 0 and limit 200.
v2 guards every collection and group edit with an ETag, returns 412 when
the item changed and 428 when the precondition is missing, and answers 501
for groups on stores without group support. The screen showed group
controls unconditionally.
The screen now uses v2 only. SiloAPI reads the list, the groups capability,
and the detail cards (catalog source=user_collection, every cursor page
under one owner) through the shared v2 client, and the v1 methods are gone.
Move, rename and both deletes read the canonical collection or group when
their sheet opens and send its strong ETag as If-Match under the same
owner; swipe-to-delete now opens a confirmation sheet for that read. A 412,
a 428, or a lost answer keeps the sheet and draft and blocks submission
until the user reloads; nothing is resent. Creates are dispatched once and
a lost answer re-reads the list. Group controls appear only when the
capability reports groups; a failed capability read shows a Retry notice
instead of treating groups as unsupported, and a 501 hides them.
All collection requests go through one fenced primitive in APIv2Client;
the typed operations live in APIv2Client+Collections.swift.
Stack-PR: W5-O
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Fold the duplicated item-id check into the shared editor read and drop a redundant type annotation on the create call. Stack-PR: W5-O Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A write kept running after its sheet was cancelled, and its outcome landed on whatever sheet was open next: a 412 or lost answer showed the wrong message and locked that sheet until Reload, and a success closed it. A dismissed delete with a lost answer also never re-read the list. Separately, a 404 from the write itself was shown as an ordinary error with Delete or Move still enabled, while the same 404 on Reload closed the sheet and re-read the list. Each write now records which sheet started it. The list still updates on success, but the sheet error, reload lock and dismissal apply only while that sheet is open; a dismissed write with an uncertain outcome re-reads the list instead. A 404 from an edit closes the sheet and re-reads the list, matching Reload. Stack-PR: W5-O Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Several lanes each kept their own list of "never sent" transport errors and their own rules for owner changes and unexpected 2xx answers, and they gave different answers for the same error. Collections, for one, treated HTTPError.requestIdentityChanged as a definite failure, but HTTPClient also raises it after a POST /api/v2/collections was answered. The user was then told the create failed and invited to make a duplicate. APIv2MutationOutcome now classifies a failed mutation as definite, notSent, uncertain or ownerChanged(beforeDispatch:), using the one never-sent list (APIv2Client.neverConnected, now with badURL and unsupportedURL). An owner-change error counts as before dispatch only with proof from an HTTPDispatchRecord; a non-2xx answer is definite (plan section 9) and an undeclared 2xx is uncertain. collectionRequest passes a dispatch record and reports a refusal before sending as APIv2OwnerChangedBeforeDispatch (moved down from the diagnostics lane); creates without a captured owner report the same. CollectionsViewModel.outcomeIsUncertain maps from the shared result, so an answer discarded after sending shows the "couldn't confirm" message and re-reads the list. Stack-PR: W5-O Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…delete The shared v2 write classifier now reports an owner change caught before the request reaches the URL session as APIv2OwnerChangedBeforeDispatch. The collection delete test still expected HTTPError.requestIdentityChanged and failed on iOS and tvOS. Expect the pre-dispatch error instead. Stack-PR: W5-O Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The uncertain-create test queued the POST's 201 and the list body in the
stub's one-shot queue, which answers requests in arrival order whatever
their path. The re-read in loadCollections() sends the list GET and the
capabilities GET at the same time. When the capabilities GET arrived
first it took the list body, and the list GET fell through to the
stub's "{}" fallback, so the list failed to decode and stayed empty
with exactly one list GET recorded. That happened in about 1 in 125 to
300 runs locally and failed CI on several stack PRs.
Queue only the POST's reply, and answer the list by path once the held
POST has taken its reply. The assertions are unchanged.
Stack-PR: W5-O
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
83b1a84 to
08038f1
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Problem
The personal Collections screen still used
/api/v1/collectionsfor every action: list, create, move to a group, delete, and group create, rename and delete. The collection detail grid read/api/v1/collections/{id}/itemsonce, withoffset=0&limit=200, so a collection with more than 200 items was cut off. A 1.0 server answers all of these with 410.v2 changes the write contract. Collection and group edits need an
If-Matchtaken from a fresh read of that collection or group. A stale tag gets 412stale_version, and a missing tag gets 428. Stores without group support (SQLite user stores) answer every group operation with 501capability_unsupported, yet the screen showed group controls on those stores too.Inventory rows: 69, 70, 72, 73, 74, 75, 76, 77.
Solution
SiloAPI.collections()readsGET /api/v2/collections({items, groups}). The call fails if the list says more items follow, so a cut-off list is never shown as complete.collectionItems(collectionId:)reads the display cards fromGET /api/v2/catalog?source=user_collection&collection_id=…. It follows the opaque cursor pages under the first page's owner, stops at 100 pages, and sends the tvOS image size. Both reads are dropped if the owner changes before they return.GET /api/v2/collections/{id}or/collections/groups/{id}. The client keeps the read's strongETagand refuses a missing or weak one. The write sends that tag asIf-Matchunder the owner that made the read. Swipe-to-delete used to delete immediately; it now opens a confirmation sheet, because the delete needs that read first. Move usesPATCHand sends an explicitgroup_id: nullfor Ungrouped. Group rename usesPATCH. Both deletes require exactly204.POST /api/v2/collections(collection_type: manual) andPOST /api/v2/collections/groups(name only) require201. Each is sent once.GET /api/v2/collections/capabilitiesgates the group controls: the new-group button, the section header menu, and the Move swipe. They show only when the response hasallowed,state == availableandgroups. If the capability read fails, the controls stay hidden and the page shows "Collection groups couldn't be checked." with Retry. The failure is not treated as "unsupported", so audit F48 (fail-closed) does not carry over. An earlier definite answer survives a later failed refresh. A 501 from any group operation hides the controls.APIv2MutationOutcomesorts a failed v2 mutation intodefinite,notSent,uncertainorownerChanged(beforeDispatch:)for every lane, using the single never-sent transport listAPIv2Client.neverConnected(which gainsbadURLandunsupportedURL). A non-2xx answer is definite; an undeclared 2xx, an unreadable answer or cancellation is uncertain. An owner-change error counts as before dispatch only when anHTTPDispatchRecordproves nothing was sent, becauseHTTPClientraises the samerequestIdentityChangedwhen it discards an answer. Before this, Collections treated that error as a definite failure afterPOST /api/v2/collectionshad been answered, told the user the create failed, and invited a duplicate.collectionRequestpasses a dispatch record and reports a refusal before sending asAPIv2OwnerChangedBeforeDispatch(moved here from the diagnostics lane).CollectionsViewModel.outcomeIsUncertainmaps from the shared result.APIv2Client.collectionRequest. It checks the owner, runs insidewithOwnerFence, adds optionalIf-Match, and asserts the one expected status. The typed operations live inAPIv2Client+Collections.swift, which also absorbsAPIv2CollectionCardRead.swift. The models live inAPIv2CollectionModels.swift. The unused genericcollectionEditor(_:),mutateCollectionanddeleteCollection(version:)are replaced, along withCollectionEditVersionandCollectionEditor, andAPIv2Error.missingCollectionVersionis replaced by the existingmissingEntityTag. All v1 collection methods are deleted fromSiloAPI.docs/collections-api-v2.mdnow covers the 428, lost-answer and capability-failure behavior.Failure outcomes (all writes are
non_retryablein openapi)201/200/204)The never-sent transport errors are those in
APIv2Client.neverConnected: no connection, host not found, cannot connect, DNS failure, bad or unsupported URL, and TLS or certificate failures.Validation
CollectionsV2Tests,CollectionsViewModelTestsandCatalogPagingAPITests. The four view-model tests added with the sheet-scoping fix fail against the code before that fix.CollectionsV2Testscover the list decode and a refusedhas_more; capability gating (available, no groups,not_configured); the create body and exact201, sent once even after a transport failure;If-Matchon move, rename and both deletes; the explicitnullgroup; 412 and 428 surfaced without replay; a version from another owner refused before dispatch withAPIv2OwnerChangedBeforeDispatch; a missing or weak ETag refused; an editor ID mismatch refused; percent-encoded IDs; and card paging, image size and the owner fence.CollectionsViewModelTestscover:groups: falseand a 501 hiding the group controlsAPIv2MutationOutcomeTests, which cover the shared classifier, ran in the full-suite runs below.scripts/ci/check-no-api-v1.shpassed.SiloAPI.swifthas eight fewer v1 literals.testCreateAnsweredAfterAnOwnerChangeIsUncertainAndRereadsTheListfailed with an empty list. The test queued the list reply in the stub's path-blind sequence, and the uncertain-outcome re-read sends the list and capabilities reads concurrently, so the capabilities read sometimes took the list reply. The test now answers the list by path and keeps every assertion. The app code was already correct. After the fix, 2,000 of 2,000 stress iterations passed on iOS and on tvOS.Risks and follow-ups
withOwnerFencelines iniosApp/iosAppgoes from 61 to 60. Before, two functions were fenced (editor read and mutation), and nothing in the app called them. Now onecollectionRequestfences all ten collection operations, andSiloAPI.collections()andcollectionItems(collectionId:)add post-readisCurrentOwnerchecks. No collection request is unfenced.APIv2MutationOutcomelands here, but lanes lower in the stack keep their own classification. Later PRs map onto it (W5-E'sMutationDelivery, W5-P's request mutations and W5-Q's subtitle dispatch); W5-M's favorite/watchlist/watched dispatcher keeps its own list until W5-E replaces it.allowedvalue the live server sends for a SQLite-backed account. The server buildsstatefrom the capability's owncapabilityState()(alwaysavailablewhen configured). Group support comes only fromgroups, which the client also checks.GET /collections/{id}. That read omits the presigned poster, which this screen does not show.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 38 of 50 in the Apple API v2 stack. Base:
apiv2-stack/37-favorites-watchlist-lists-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code