Repository navigation
feat(catalog): page catalog queries with v2 cursors - #382
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 ( |
141bc83 to
ff7d1da
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff7d1da5af
ℹ️ 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".
|
|
||
| offset = requestOffset + response.items.count | ||
| continuation = page.continuation | ||
| total = response.total ?? results.count |
There was a problem hiding this comment.
Avoid presenting estimated search totals as exact
When v2 search returns total_exact: false—for example, the semantic-search response covered by testSearchWindowIsNotGlobalTotalAndInstantDecodes, where total is 10,000 but the result window is only 250—this assigns the estimate to total, and SearchView renders it as an exact “10000 results.” Preserve totalExact (and ideally the result-window limit) or derive a lower-bound label from the loaded results instead of displaying the estimate as an exact count.
Useful? React with 👍 / 👎.
58c61e8 to
72a03f9
Compare
Every catalog-shaped list (library browse, the tvOS library grid, search, watch history, person credits and collection grids) still paged through GET /api/v1/catalog with offset, snapshot and include_total. A 1.0 server answers that route with 410, and v1 bracket-key filter groups have no v2 equivalent. SiloAPI.catalog(query:) and its history, person and collection wrappers are replaced by catalogPage(_:) and nextCatalogPage(_:), built on the existing APIv2Client catalog continuation. The first page captures the acting owner and image size; each screen keeps the returned continuation and hands it back for the next page, so every page reuses the first page's query and owner and a profile switch refuses the next page. Filter sets whose JSON groups exceed the 32768-character GET limit go through POST /api/v2/catalog/query, and the continuation keeps that operation. CatalogQueryBuilder now returns an APIv2CatalogQuery with typed rule values (JSON booleans for watched/hdr/..., numbers for year ranges), which the v2 query executor requires. A cached first page carries no cursor, so a load-more over it restarts from page 1 instead of guessing an offset; this also fixes the collection grid's pull-to-refresh, which re-fetched from the old offset and replaced page 1 with page 2. The browse, tvOS grid and history cache keys move to v2 names and library collection items get their own key. CatalogResponse drops the v1-only snapshot, source and title fields. Stack-PR: W5-I Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Person credits and the tvOS library grid picked the next page with a startsOver flag and then re-checked the continuation, unlike the other catalog screens. They now take the same nextPage = reset ? nil : continuation step the history, collection and search screens use. Behavior is unchanged. Stack-PR: W5-I Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
When a collection changes, a library scan runs, or the viewer's access policy changes between pages, the server answers the next cursor with 400 invalid_cursor. The client also refuses a repeated or dropped cursor (invalidCatalogContinuation). Every catalog grid kept the dead cursor and hasMore, hid the error because items were on screen, and resent the same cursor on every scroll, so the grid stopped at 60 or 100 items. SiloAPI.nextCatalogPage now treats either error as a restart: it reads a fresh first page with the continuation's query, operation and owner and marks it startsOver. History, browse, the tvOS library grid, search, person credits and the collection grid replace their items with that page and page on from its new cursor. Other failures still keep the cursor for a retry. Stack-PR: W5-I Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ff7d1da to
d449f74
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Problem
Every catalog-shaped list in the Apple clients paged through
GET /api/v1/catalogwithoffset,snapshot/snapshot_atandinclude_total: library browse and its startup prefetch, the tvOS library grid, search, watch history, person credits, library and user collection grids, and the DEBUG search helper. A 1.0 server answers/api/v1/*with410 client_upgrade_required. The v1 bracket-key filter groups (groups[0][rules][0][value]) have no v2 form, and the v2 query executor rejects string values for boolean and numeric rules.Inventory rows 54 (the
SiloAPI.catalog(query:)funnel), 63 (history) and 71 (collection items).Solution
SiloAPI.catalog(query:),historyCatalog,personCatalogItems,libraryCollectionItems,userCollectionItemsandcatalogCollectionItemsare deleted. They are replaced bySiloAPI.catalogPage(_:)andSiloAPI.nextCatalogPage(_:), which use the existingAPIv2Client.catalogPageandnextCatalogPageand their owner fences.APIv2CatalogContinuationand passes it back for the next page, so every page uses the first page's query, operation and owner. If the profile changes, the next page is refused before any request is sent.groupsare longer than the 32768-character GET limit, the query goes throughPOST /api/v2/catalog/query, and the continuation keeps POST. Smaller queries stay onGET /api/v2/catalog.APIv2CatalogQuerygainshistory,personCredits(sort=-year),collectionItemsandsearchfactories, plus aCatalogListPagetype (cards and totals, plus the continuation).CatalogQueryBuilderreturns anAPIv2CatalogQuery, built from the legacy branch's version as a reference. Rule values are typed: JSON booleans forwatched,in_progress,favorited,in_watchlist,hdranddolby_vision, and numbers for decadeyear betweenranges.BrowseViewModelandStartupContentPrefetcher.fetchBrowseFirstPage(the prefetched page 1 now also returns the page-2 continuation),TVLibraryGridViewModel,SearchViewModel(a new search generation stops an older load-more from appending to new results),HistoryViewModel,PersonDetailViewModel,LibraryCollectionDetailViewand the DEBUG search inContentView.400 invalid_cursor: a collection edit, a library scan, or a changed access policy), or the server repeats or drops a cursor (invalidCatalogContinuation),SiloAPI.nextCatalogPagereads a fresh page 1 with the same query and owner and marks itstartsOver. Every grid replaces its items with that page and pages on from its new cursor, so the dead cursor is never sent again. Without this, the grid kept the rejected cursor, resent it on every scroll and stopped at 60 or 100 items with an "N+ items" label. The restart happens once per load-more; if the fresh page 1 fails, the grid keeps its items and the next scroll tries page 1 again. Other failures keep the cursor for a retry.browse:v2:…,tvlibrary:v2:…andpersonal:history:v2. Library collection items move tocollection:<id>:catalog:v2, separate from the raw collection-items list thatCollectionDetailViewstill reads over v1. The prefixes used for invalidation (browse:,tvlibrary:,collection:) are unchanged.CatalogResponsedrops the v1-onlysnapshot,sourceandtitlefields. It staysCodablebecause the v1 favorites, watchlist and collection-items reads still decode it.This PR changes reads only.
queryCatalogItemsisnatural_idempotentandlistCatalogItemsis a GET, so no failure-outcome table applies.Paging is bounded. UI grids request one page per user scroll, with no automatic loop. The continuation rejects a missing, empty or repeated cursor (
invalidCatalogContinuation). The only looping reader,personalCollectionCards, keeps its 100-page bound.Validation
CatalogPagingAPITests,CatalogQueryBuilderTests,CatalogV2Tests,CollectionsV2Tests,BrowseViewModelTestsandHomeSectionsAPITests, plusArtworkURLTestson iOS.CatalogPagingAPITestscover:GET /api/v2/catalog, with no v1 paging parametersPOST /catalog/query, with the cursor in the body and the first page's query sent againdecode_failedinstead of an empty list400 invalid_cursoron page 2 that reads a fresh page 1 markedstartsOverand then pages on from the new cursor without resending the rejected one; a repeated cursor that starts over the same way; and another problem (validation_failed) that throws without rereading page 1CatalogQueryBuilderTestsis ported to the v2 query. It checks the signed sort, thegroupsJSON, boolean and numeric rule types, and the switch from GET to POST.scripts/ci/check-no-api-v1.shpassed.SiloAPI.swiftandCatalogQueryBuilder.swifthave fewer v1 literals, and no/api/v1/catalogliteral remains in app sources.Risks and follow-ups
invalid_cursordifferently: it stops paging and shows "This result expired or changed. Reload from the first page." until the user reloads. Apple restarts from page 1 on its own because its grids show errors only when they are empty.TVLibraryGridViewModelchanged here because it calls the funnel. Only its paging state changed; focus, layout and the view are untouched. W5-H still owns the library sections and collections routes.CollectionDetailView(/api/v1/collections/{id}/items), favorites and watchlist still read v1 intoCatalogResponse. W5-O and W5-N own them.personalCollectionCardsstill has no production caller. The user-collection grid pages by cursor like every other grid instead of reading the whole collection up front.type=videosearch scope go through v2 unchanged. The server's v2 sort allowlist was not compared field by field againstCatalogSortKey.query_builder.gochecks at84ed9e596. This has not been exercised against a live server.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 34 of 50 in the Apple API v2 stack. Base:
apiv2-stack/33-filters-calendar-trailers-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code