Skip to content

feat(catalog): load similar and discover rows from v2 - #380

Merged
Quick104 merged 2 commits into
mainfrom
apiv2-stack/32-similar-discover-v2
Sep 23, 2026
Merged

Quick104 merged 2 commits into
mainfrom
apiv2-stack/32-similar-discover-v2

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

The "More Like This" rails on iOS and tvOS and the Discover tab still read /api/v1/recommendations. The v1 similar route returned only scored item IDs, so each rail then requested item detail for every ID: up to 12 extra requests per detail page (tvOS sent them three at a time). Discover decoded the v1 rows/label body.

Solution

  • SiloAPI.recommendationsSimilar(contentId:limit:) now calls APIv2Client.similarCards, which sends GET /api/v2/recommendations/similar/{item_id}?limit=. The item ID is percent-encoded, the limit must be 1...50, and the call runs under the owner fence. The server returns full cards in ranked order. If the acting owner changes while the request is in flight, the fence rejects the read with authorityChanged. The facade checks again after decoding and throws requestIdentityChanged if the owner changed in that window.
  • PhoneSimilarRail and TVSimilarRail map those cards straight to SimilarPosterItem(card:). The per-item detail fan-out and its reordering are gone. tvOS keeps its delayed start and its rail cache.
  • SiloAPI.recommendationsDiscover() now calls APIv2Client.discover (GET /api/v2/recommendations/discover). It maps each row's title into the same discover_<index>_<type> ResolvedSection IDs, so StartupContentPrefetcher and the Discover screens are unchanged.
  • Deleted the v1-only models DiscoverResponse, DiscoverRow, ScoredItemsResponse and ScoredItemRef.

Both operations are profile_scoped GETs, so no failure-outcome table applies. Failures reach the caller as typed errors and never become empty results. The rails still hide on any failure, and the Discover prefetch reports the reason (decode_failed, invalid_profile, and so on).

Validation

  • iOS, tvOS and macOS builds passed.
  • Focused tests passed on iOS and tvOS: RecommendationsAPITests, LibraryDetailScopeTests and HomeSectionsAPITests.
  • The new RecommendationsAPITests cover:
    • a single similar request with the encoded path, limit and X-Profile-Id, returning cards in server order
    • a similar read refused with HTTPError.authorityChanged after a profile switch mid-read
    • out-of-range limits rejected before dispatch
    • Discover rows mapped by title to the existing section IDs
    • a v1 Discover body and a 403 problem surfaced as errors, not an empty tab
  • scripts/ci/check-no-api-v1.sh passed.
  • The final stack passed the full suites (iOS 1981 tests and tvOS 1792 tests, 0 failures), the macOS build and the v1 path guard. Every branch in the stack, this one included, builds on its own.

Risks and follow-ups

  • tvOS used to seed the item-detail cache from the hydrated recommendations, so opening a recommended title could show its detail at once. Cards are not full details, so the destination now loads its detail on open, like any other card tap.
  • Not run on a live server or device. Wire shapes were checked against contracts/api/v2/openapi.json at 84ed9e596 (listSimilar, getDiscover).
  • No test covers the facade's post-decode owner check. Testing a switch in that window needs a seam between the fence's check and the facade guard, and none exists. The mid-read test covers the fence.
  • The v2 client methods already lived in APIv2Client.swift; this PR did not move them into a per-domain file.

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 32 of 50 in the Apple API v2 stack. Base: apiv2-stack/31-home-sections-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 92c39f0d-e910-4740-9e23-83d2b72a7e82

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T13:23:08.691686Z 9faf9fd New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Quick104

Copy link
Copy Markdown
Contributor Author

Code review summary

Reviewed head: 019a4084 (apiv2-stack/32-similar-discover-v2).

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:

  • minor: PR body and doc comment name the wrong error for a mid-read owner switch, and the new test cannot tell the two apart

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 /api/v1 request from the new builds except the retained health probe.

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 (claude-opus-5-5) agents in Claude Code (T3 Code).

Quick104 and others added 2 commits September 23, 2026 09:41
The "More Like This" rails and the Discover tab still read
/api/v1/recommendations. The similar route returned scored IDs only, so
each rail then fetched item detail for every ID: up to twelve extra
requests per detail page. Discover decoded v1 `rows`/`label`.

SiloAPI now calls the existing v2 client reads. Similar cards come from
GET /api/v2/recommendations/similar/{item_id} as full cards in ranked
order, so both rails drop the per-item detail fan-out and map cards
directly; the facade refuses cards whose owner changed mid-read.
Discover reads GET /api/v2/recommendations/discover and maps each row's
`title` into the same ResolvedSection ids as before. The v1-only
DiscoverResponse, DiscoverRow, ScoredItemsResponse and ScoredItemRef
models are deleted.

Stack-PR: W5-K
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The similar-cards doc comment and PR text said the facade throws
`requestIdentityChanged` when the profile switches mid-read. The owner
fence inside `APIv2Client.similarCards` rejects that read first with
`authorityChanged`; the facade guard only catches a switch during
decoding. The regression test caught any error, so it could not tell
the two apart.

The doc comment now names both checks, and the test asserts
`HTTPError.authorityChanged`.

Stack-PR: W5-K
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Base automatically changed from apiv2-stack/31-home-sections-v2 to main September 23, 2026 13:41
@Quick104
Quick104 force-pushed the apiv2-stack/32-similar-discover-v2 branch from 9faf9fd to 2a2aa0c Compare September 23, 2026 13:42
@Quick104
Quick104 merged commit 3d5f933 into main Sep 23, 2026
2 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Quick104
Quick104 deleted the apiv2-stack/32-similar-discover-v2 branch September 23, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant