Skip to content

feat(home): load home sections and dismissals from v2 - #379

Merged
Quick104 merged 3 commits into
mainfrom
apiv2-stack/31-home-sections-v2
Sep 23, 2026
Merged

Quick104 merged 3 commits into
mainfrom
apiv2-stack/31-home-sections-v2

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

Home still loaded its rows from GET /api/v1/home/sections. Dismissing a Continue Watching or Next Up card still sent PUT /api/v1/home/dismissals/{surface}/{id}. APIv2Client already had homeSections and dismissHomeItem, but only tests called them (inventory rows 47, 48 and 49).

Solution

  • SiloAPI.homeSections() captures the request owner and calls APIv2Client.homeSections (GET /api/v2/home/sections, X-Profile-Id, image_size as before). It returns APIv2HomeSectionsRead, so callers get the rows together with the owner they were fetched for.
  • StartupContentPrefetcher.fetchHomeSections and the player's on-deck lookup confirm that the owner still matches the active session (SiloAPI.isCurrentOwner, backed by TokenStore.currentOrdinaryRequestAuth(matchingIdentityOf:)) before they cache or show the rows. The prefetcher's generation checks still run.
  • dismissContinueWatchingItem and dismissNextUpItem call APIv2Client.dismissHomeItem (PUT /api/v2/home/dismissals/{surface}/{item_id}). The body is {"progress_updated_at": …} for continue_watching and {"series_id": …} for next_up. Only a 204 counts as success. The private v1 bodies HomeDismissalBody and NextUpDismissalBody are deleted.
  • StartupContentPrefetcher.indicatesInvalidProfile now recognizes the v2 profile_verification_required problem, so a locked profile without a valid token still returns the user to profile selection when Home loads. prefetchFailureReason groups v2 errors by status, as it does for v1 errors, and adds a server_update_required token. A malformed 200 body, which the v2 read throws as a bare DecodingError, is still reported as decode_failed.
  • ErrorState now reads the status from APIv2Error.problem and .httpStatus. Without this, a v2 401 or 404 on Home had no status, was retried as a transient failure, and showed "Something went wrong" instead of "Session expired" with Sign In Again, or "Not found". 401, 403 and 404 use the same copy as v1; other problems show the server's detail text. ErrorState is shared, so every screen that shows v2 errors gets the same fix.
  • CacheKey.homeSections is now home:sections:v2.
  • ArtworkURLTests no longer reads /api/v1/home/sections.

Failure outcomes for the dismissal write (dismissHomeItem, x-silo-retry-safety: natural_idempotent)

Outcome Behavior
Definite success (204) Remove the card from Home and from the cached rows, and invalidate any in-flight Home read.
Definite failure (any other status, a problem response, or an owner change before sending) The card stays. Show the error once through actionError.
Uncertain (sent, no response) The card stays and the error is shown. Nothing replays automatically. The user can dismiss again, which is safe because a repeated PUT only refreshes the dismissal.

Validation

  • iOS, tvOS and macOS builds passed.
  • Focused tests passed on iOS and tvOS: HomeSectionsAPITests, HomeSectionsMutationTests, ArtworkURLTests, InvalidProfileRecoveryTests, ErrorStateTests, UpdateRequirementTests and RequestErrorCopyTests.
  • The new HomeSectionsAPITests run through the SiloAPI facade on StubURLProtocol. They cover:
    • the v2 GET path and the X-Profile-Id header
    • that the read's owner stops matching after a profile switch
    • that a profile_verification_required problem surfaces as an invalid profile and is not treated as an empty Home
    • the exact method, path and JSON body of each dismissal surface
    • that a 200 or 422 reply to a dismissal throws
    • that a malformed 200 Home body is classified as decode_failed
  • The new ErrorStateTests check that a v2 401 problem is an auth failure and not transient, that a v2 404 (plain status or problem) is "Not found", that a v2 5xx stays transient with the server's detail, and that a v2 upgrade problem keeps its 410 status.
  • scripts/ci/check-no-api-v1.sh passed. Fence and owner-check references in iosApp/iosApp went from 100 to 101.
  • 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

  • v2 reports a deleted profile as a generic not_found, so a Home 404 does not trigger profile recovery. At the pinned server commit, v1 also sent not_found (not profile_not_found), so this matches today's behavior.
  • The cache-key bump applies only to the in-memory ResponseCache key. The persisted row order and visibility preferences (*.homeSections.v1 in HomeSectionPreferences) keep their key. v1 and v2 use the same server home service and section IDs, so users keep their saved row layout.
  • The diagnostics path-template fixtures in DiagnosticsPathTemplateTests and HTTPClientDiagnosticsClassificationTests still contain /api/v1/home/... strings. They send no requests, and Z1 owns their final allowlist.
  • Not checked by hand on a device or simulator 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 31 of 50 in the Apple API v2 stack. Base: apiv2-stack/30-control-socket-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.

🤖 Generated with Claude Code

@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.

@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: a70aaae9-7057-49e7-93e2-15f4b6f6260e

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.

@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:24:53.978391Z 55e2710 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: e5911fed (apiv2-stack/31-home-sections-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: Home load errors lose their HTTP status once they arrive as APIv2Error, so 4xx problems count as transient and lose the Session expired / Not found actions
  • minor: The v2 Home decode failure is now classified as "other" instead of "decode_failed"

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
Quick104 force-pushed the apiv2-stack/31-home-sections-v2 branch from e5911fe to 55e2710 Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/30-control-socket-v2 branch 2 times, most recently from 2e3a00b to b8e695f Compare September 23, 2026 13:41
Base automatically changed from apiv2-stack/30-control-socket-v2 to main September 23, 2026 13:41
Quick104 and others added 3 commits September 23, 2026 09:41
Home rows and the Continue Watching and Next Up dismissals still went to
/api/v1/home/sections and /api/v1/home/dismissals/{surface}/{id}, even
though APIv2Client already implemented both v2 operations.

SiloAPI now reads Home through GET /api/v2/home/sections with the captured
request owner and dismisses cards through PUT
/api/v2/home/dismissals/{surface}/{item_id}, which must answer 204. The
startup prefetcher and the player's on-deck lookup check that the read
still belongs to the active profile before caching or showing it. A v2
profile_verification_required problem still sends the user back to profile
selection, and prefetch diagnostics bucket v2 errors by status. The v1
dismissal bodies and the v1 home test read are gone, and the in-memory
Home cache key is versioned.

Stack-PR: W5-G
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
APIv2Client turns every non-2xx response into APIv2Error.problem or
.httpStatus, but ErrorState only read a status from HTTPError and APIError.
A v2 401 or 404 on Home therefore had no status: it counted as transient, was
retried as a network blip, and ErrorView showed "Something went wrong" with
only Try Again instead of "Session expired" or "Not found".

ErrorState now takes the status from both APIv2Error cases, including for
update-required problems. 401, 403 and 404 use the same copy as the v1 path;
other problems keep the server's detail text.

Stack-PR: W5-G
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The v2 Home read decodes its 200 body outside mapErrors, so a malformed body
throws a bare DecodingError. prefetchFailureReason only knew
HTTPError.decodingFailed and APIv2Error, and reported it as "other", which
dropped the stable decode_failed token the v1 read produced.

prefetchFailureReason now classifies any DecodingError as decode_failed.

Stack-PR: W5-G
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the apiv2-stack/31-home-sections-v2 branch from 55e2710 to 049486b Compare September 23, 2026 13:41
@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 merged commit 37e63c9 into main Sep 23, 2026
3 of 6 checks passed
@Quick104
Quick104 deleted the apiv2-stack/31-home-sections-v2 branch September 23, 2026 13:41
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