Skip to content

feat(profiles): list, create, verify and edit profiles through v2 - #388

Merged
Quick104 merged 5 commits into
mainfrom
apiv2-stack/40-profiles-v2
Sep 23, 2026
Merged

Quick104 merged 5 commits into
mainfrom
apiv2-stack/40-profiles-v2

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

Profiles and user libraries still used /api/v1 (inventory rows 26-30):

  • SiloAPI.libraries() called GET /api/v1/user/libraries. Every library list uses it: startup prefetch, Browse, Libraries tab, tvOS sidebar, settings and the new-profile form.
  • SiloAPI.listProfiles() called GET /api/v1/profiles for the profile picker, settings, diagnostics and the current-profile store.
  • SiloAPI.verifyProfileSelection called POST /api/v1/profiles/{id}/verify-pin.
  • SiloAPI.createProfile called POST /api/v1/profiles.
  • SiloAPI.updateProfile called PUT /api/v1/profiles/{id} for the onboarding tour's profile-field steps.

The new-profile form had three related problems:

  • It used try? on the library read, so a failed read showed "No libraries are available to assign."
  • Its error mapping matched v1 HTTPError codes (profile_limit_reached, bad_request), which v2 does not send.
  • A wrong PIN was thrown as APIError.httpError(401), so the UI said "Your session has expired."

Solution

  • SiloAPI now calls the shared apiV2Client methods that already existed. They are owner-fenced and check the status of every response:
    • userLibraries(): GET /api/v2/user/libraries. Rows map through Library(v2:). A non-canonical ID fails the read instead of dropping the row.
    • householdProfiles(): GET /api/v2/profiles.
    • verifyHouseholdPIN: POST /api/v2/profiles/{id}/verify-pin. The ID is percent-encoded. valid: false throws the new ProfileTransitionError.incorrectPIN ("That PIN is incorrect. Try again.").
    • createHouseholdProfile: POST /api/v2/profiles. Accepts only 201. Library IDs are sent as strings, and unset members are omitted.
    • updateProfile(id:patch:): PATCH /api/v2/profiles/{id} with UpdateProfileBody.asAPIv2Patch. The legacy "" language value is sent as a clearing null.
  • In CreateProfileView, a failed library read now shows "Couldn't load libraries" with the reason and a Try Again button. An empty list still says no libraries are available. A retry keeps the failed row and its button in place and shows progress inside the button, so focus stays on it on tvOS.
  • The new CreateProfileFailure replaces mapSubmitError. It shows problem.detail for 409 conflict, which covers both a taken name and a full household, and for 403 permission_denied, which covers a demo-mode server. For 422 validation_failed, it shows the first member error. Update-required errors use the existing F5 copy.
  • The new MutationDelivery (Networking) gives the create form and PersonalStateSync one sent/never-sent/owner-changed rule. It maps from the shared APIv2MutationOutcome (W5-O) and keeps no transport or status lists of its own; PersonalStateSync drops its private classifier. One behavior change follows for favorite, watchlist and watched: an undeclared 2xx (anything other than 204) or an unreadable answer is now held as unconfirmed instead of reported as a failure. Before this, a create answered with an undeclared 2xx kept the form open and invited a duplicate profile.
  • Deleted:
    • the v1 Profile and ProfilesResponse wire models;
    • the bare-array branch of LibrariesResponse, which is now only the ResponseCache shape {"libraries": [...]};
    • testLibrariesResponseDecodesBareArray.
  • LibraryVisibilityTests now decodes the cache shape. Stale v1 doc comments were fixed. UpdateProfileBody is no longer Encodable because nothing encodes it directly.

Failure outcomes for the writes (x-silo-retry-safety checked in contracts/api/v2/openapi.json at 84ed9e596):

Operation Retry safety Definite success Definite failure (non-2xx answer, never sent, update-required gate) Uncertain (sent with no answer, an undeclared 2xx, an unreadable answer, or an owner change)
createProfile (POST) non_retryable 201: the form closes and the list reloads Alert with the server's reason; the form stays open; nothing is re-sent Alert "Profile May Have Been Created"; OK closes the form and reloads the list so the user sees the result before trying again; never re-sent. An owner change gets the same treatment, because the fence can throw after the server answered 201
updateProfile (PATCH, onboarding) non_retryable 200 with the profile The onboarding step reports the error as before; no automatic retry Same as a definite failure: the step reports the error and waits for the user; never re-sent automatically
verifyProfilePIN (POST) natural_idempotent 200 valid: true: the profile is activated with its proof valid: false gives incorrectPIN; other errors surface through ErrorState Surfaces the error; the user can enter the PIN again

An owner change during a call throws HTTPError.requestIdentityChanged or .authorityChanged, and the client applies nothing under the new owner. .authorityChanged can fire after the server answered, so the server may already have applied the write. For create, the form closes and the list reloads (see the table). For the onboarding update, the step reports the error and the user can choose again.

Validation

  • iOS, tvOS and macOS builds passed, before and after the review fixes.
  • Focused tests passed on iOS and tvOS: ProfilesV2Tests (new), PersonalStateSyncTests, LibraryVisibilityTests, DetailVersionSelectionTests, CatalogV2Tests, APIv2ContractTests, APIv2ProbeTests and BrowseViewModelTests, plus the iOS-only OnboardingInvitationTests.
  • ProfilesV2Tests uses StubURLProtocol and covers:
    • method, path and body for each operation
    • percent-encoding of the verify-pin ID
    • the exact-201 rule for create
    • PATCH clearing nulls
    • wrong-PIN mapping
    • filtering of unsupported library types, and a failure on a non-numeric library ID
    • the cache-only LibrariesResponse shape
    • each create failure outcome, including that an unanswered create is sent once and closes the form
    • a 201 discarded because the profile changed while the request was in flight: sent once, and the form closes
    • a 403 demo-mode refusal: the server's message is shown and the form stays open
  • 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.
  • Not run: manual simulator checks of the profile picker, PIN entry, the new-profile form on iOS and tvOS, and the onboarding tour against a live v2 server.

Risks and follow-ups

  • OnboardingTourAPI.updateProfile(profileId:body:) keeps its signature; only its transport changes, so OnboardingTourViewModel (moved to v2 by W5-F earlier in the stack) is untouched.
  • v2 makes PATCH /api/v2/profiles/{id} and POST /api/v2/profiles demo-restricted; v1's PUT/POST /api/v1/profiles were not. On a server with demo.enabled, a non-admin now gets a 403 permission_denied with the detail "This action is not available in demo mode." The new-profile form shows that message. In the onboarding tour, every profile_field choice shows the same message, and Finish fails too, because it saves the current step's default first. "Continue without saving" is the only way to finish the tour. Treating that refusal as a skipped step is an open follow-up; nothing in this stack does it. The v2 problem has no demo-specific type, so the client can recognize the refusal only as a 403 permission_denied or by its detail text.
  • The tvOS "Try Again" button stays mounted during a retry. Its focus has not been checked on a device or simulator.
  • avatar_upload_enabled from ProfileCollection is still not surfaced, as before.

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 40 of 50 in the Apple API v2 stack. Base: apiv2-stack/39-membership-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: 32d0386f-a0b7-4e3c-bd0c-3ae74dffbf9c

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:22:57.880877Z fc08eec 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: 669cc6da (apiv2-stack/40-profiles-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: A create that the server applied, followed by an owner change, is reported as a plain failure with "Try again"
  • minor: Onboarding profile-field writes are newly refused on demo-mode servers; the PR does not mention it
  • minor: On tvOS, activating "Try Again" removes the focused button from the view

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:44
The profile picker, PIN check, new-profile form and the onboarding tour's
profile-field steps still called /api/v1/profiles, and every library list
came from /api/v1/user/libraries. The new-profile form also treated a failed
library read as "No libraries are available to assign", matched v1 error
codes that v2 no longer sends, and a wrong PIN surfaced as an expired
session.

SiloAPI now routes these calls through the shared APIv2Client methods that
already existed and are owner-fenced: GET /api/v2/profiles, POST
/api/v2/profiles (expects 201, library IDs as strings), POST
/api/v2/profiles/{id}/verify-pin, PATCH /api/v2/profiles/{id} (the
UpdateProfileBody becomes an APIv2ProfilePatch, "" language clears with
null) and GET /api/v2/user/libraries. A wrong PIN throws
ProfileTransitionError.incorrectPIN.

The new-profile form keeps a failed library read apart from an empty list
and offers Try Again. Create is non_retryable and is sent once:
CreateProfileFailure shows the server's reason for a 409 or 422, keeps the
form open for any definite failure, and closes the form for an unanswered
request so the refreshed list shows whether the profile exists. The
sent-or-not classification from PersonalStateSync moves to a shared
MutationDelivery type so both surfaces use the same rule.

LibrariesResponse is now only the cache shape, so its v1 bare-array decode
is gone. The v1 Profile and ProfilesResponse wire models are deleted.

Stack-PR: W5-E
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…nDelivery

Stack-PR: W5-E
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Base automatically changed from apiv2-stack/39-membership-v2 to main September 23, 2026 13:44
Quick104 and others added 3 commits September 23, 2026 09:44
…iscarded

The owner fence can throw authorityChanged after the server already answered
201 to POST /api/v2/profiles. The form treated that as a plain failure and
said "Try again", so a retry hit a name conflict or created a second profile.
A 403 refusal, such as a demo-mode server, also fell through to the generic
"Couldn't Create Profile" alert.

An owner change now closes the form like an unanswered create, with copy
that points the user at the refreshed profile list. A 403 problem shows the
server's reason under "Can't Create Profile", like a 409 or 422.

Stack-PR: W5-E
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
On tvOS, pressing Try Again after a failed library read swapped the focused
button for a progress row, so focus jumped to another control.

A retry now leaves the failed state in place and shows progress inside the
button until the result arrives; repeated presses are ignored. Only the first
read shows the progress row.

Stack-PR: W5-E
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
MutationDelivery kept its own never-sent URLError list and treated every
APIv2Error as definite, so a create answered with a 2xx other than the
declared 201 kept the form open and invited a duplicate profile. It now
maps from APIv2MutationOutcome: an undeclared 2xx or an unreadable
answer is unconfirmed and closes the form, like a lost answer.

Stack-PR: W5-E
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the apiv2-stack/40-profiles-v2 branch from fc08eec to 0fa1b3f Compare September 23, 2026 13:44
@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 1856715 into main Sep 23, 2026
3 of 6 checks passed
@Quick104
Quick104 deleted the apiv2-stack/40-profiles-v2 branch September 23, 2026 13:44
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