Skip to content

feat(onboarding): run the onboarding tour on v2 - #369

Merged
Quick104 merged 2 commits into
mainfrom
apiv2-stack/21-onboarding-tour-v2
Sep 23, 2026
Merged

Quick104 merged 2 commits into
mainfrom
apiv2-stack/21-onboarding-tour-v2

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

The onboarding tour still used v1 for all three of its calls: GET /api/v1/onboarding/flow, GET /api/v1/onboarding/state and POST /api/v1/onboarding/progress (inventory rows 23, 24 and 25). A 1.0 server answers v1 with 410, so the tour would stop working. Changing the paths alone is not enough. In v2, progress is a PUT guarded by the state's strong ETag: the server returns 428 when If-Match is missing and 412 when the tag is stale. The contract also marks the operation non_retryable.

The gate that decides whether to open the tour also needed a clear error rule (audit F54). The audit found that the legacy invite path returned "handled" on any error. The inventory asked that no error, whether update-required, 401, 412 or 428, ever open the tour. The gate now follows one rule: it opens the tour only when the server confirms the tour is not done.

Solution

  • Reads. OnboardingTourViewModel.load calls APIv2Client.onboardingRead(surface: "phone") through SiloAPI.shared.apiV2Client. The call reads the state and then the flow under one captured owner. It rejects a flow for a different tour and keeps the state's strong ETag in an APIv2OnboardingSession.
  • Writes. Each step, skip or finish sends one PUT /api/v2/onboarding/progress with If-Match set to the tag from the last read or receipt. The receipt then replaces the session. The view model takes the session before it sends, so a tag is never sent twice. After a 412, 428, any other error or a lost reply, the next step the user takes reads the state again before it writes. If that read shows the tour is already done, and it was not done at load, the tour closes without writing. A finish still opens the route the user picked in that case, because the finish did land. That read must come from the same owner that loaded the tour (sameCredentialIdentity).
  • Replaced tour. If the server has moved to a new tour, the write gets 409 or the re-read names another tour (OnboardingProgressError.tourChanged). The tour then closes with no route and logs the cause, because no progress for it can be saved. The gate reads the new tour on its next check. "Continue without saving" also closes the tour when its progress write fails, so the user always has a way out.
  • Receipt checks. onboardingWrite refuses a receipt for another tour, and a skip or finish receipt that is not done (OnboardingProgressError.unexpectedReceipt). The redundant writerID parameter and the session's id are removed, because the caller now passes the session itself.
  • Profile writes. A setting_choice step saves its value only while the profile that loaded the tour is still active. This PR does not change the profile write, which is still SiloAPI.updateProfile. W5-E owns that write.
  • Gate (F54). OnboardingTourGateModel opens the tour only when a state read succeeds for the checked profile, the state is not done, and that profile is still active. On any error it logs the cause and keeps the tour closed. That includes update-required servers, which the gate refuses before sending anything. The retry for an unrenderable tour and the legacy invite skip both read the state first. They write only if the tour is still open, using that read's tag, and they clear their marker once the server confirms the tour is done. The legacy skip now reads the account id through APIv2Client.currentUser() and takes the tour id from the state, so it no longer reads the flow. The gate and the view model take the API, server id and profile id as injected values so tests can supply them.
  • Unrenderable-tour marker. The marker is now keyed on the server and profile of the owner that read the tour.
  • Deleted. SiloAPI.onboardingFlow(surface:), SiloAPI.onboardingState(), SiloAPI.postOnboardingProgress(_:), the v1 doc reference in OnboardingModels.swift, and the v1 flow test. The v1 guard counts drop: SiloAPI.swift by 3, OnboardingInvitationTests.swift by 2 and OnboardingModels.swift by 1.

Failure outcomes (PUT /api/v2/onboarding/progress, non_retryable)

Outcome Behavior
Definite success (200 with a strong ETag, a matching tour, and done when finishing) The receipt becomes the session. The tour moves to the next step or closes.
Definite failure (412 stale tag, 428, 4xx/5xx, update-required, owner changed before dispatch, or a receipt that fails the checks) No session is kept. The error shows once in the tour with the existing "Continue without saving" option, which closes the tour even if its own write fails. The real cause is logged. Nothing is re-sent. The next step the user takes reads the state again first.
Tour no longer current (409, or a re-read naming another tour) The tour closes with no route and the cause is logged. Nothing is re-sent.
Uncertain (sent, no reply) Same as definite failure. The write is never replayed. The next step the user takes reads the state first. If the earlier write landed and finished the tour, the tour closes without another write and a finish still opens its route. If it moved the step, the new write goes out under the new tag.

The gate's unrenderable-tour retry and legacy invite skip are one-shot writes too. Each one runs only after a fresh state read shows the tour still open. If an earlier write landed, the server has already moved the tag on, and a write that races it gets 412 instead of being applied twice.

Validation

  • iOS, tvOS and macOS builds passed on this branch.
  • Focused iOS tests passed: OnboardingInvitationTests and OnboardingV2Tests (35 tests, 0 failures). On tvOS, OnboardingV2Tests passed (8 tests). OnboardingInvitationTests is not in the tvOS target because the tour is #if !os(tvOS).
  • scripts/ci/check-no-api-v1.sh passed.
  • The new Tests/Support/OnboardingServerStub.swift models the server on StubURLProtocol: a revisioned state, "r<revision>" tags, 428/412 checks, a write that never arrives, a write whose reply is lost after it was applied, and a replaced tour that answers 409.
  • OnboardingV2Tests covers the wire: state then flow with X-Profile-Id and surface, refusal of a weak tag, the PUT body and If-Match, one dispatch on 412 and on a lost reply, an unfinished finishing receipt, and no request after a profile switch or on an update-required server.
  • OnboardingInvitationTests runs the view model and gate against the stub: receipt-tag chaining, re-read after a lost reply or a stale write, a lost finishing reply that still opens the chosen route, both replaced-tour paths, "Continue without saving" when its write fails, the gate staying closed on a 503 and on an update-required server, the unrenderable-tour retry, and the legacy invite skip for an open state, a done state, a failed state read and another account's marker.
  • The final stack passed the full suites (iOS 1981 tests and tvOS 1792 tests, 0 failures), the macOS build and the v1 path guard, and every branch in the stack builds on its own.
  • Not run: a manual tour on a simulator against a live v2 server.

Risks and follow-ups

  • If the Settings replay route re-runs a tour that is already done, it still sends step progress with completed: false, as v1 did. This PR does not check whether the server keeps completed_at in that case.
  • Profile choices made in the tour still go through SiloAPI.updateProfile on v1 until W5-E. W5-E can switch this caller to APIv2Client.updateProfile(id:patch:auth:) using the tour's owner.
  • Open PR feat(player): support all marker occurrences #343 also edits APIv2Client.swift and SiloAPI.swift, in different hunks. Whichever lands second rebases.

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 21 of 50 in the Apple API v2 stack. Base: apiv2-stack/20-overlay-config-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: 04228e18-2869-40dd-9be8-9d8271ff8cb8

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:42:31.928686Z 8c8d7f8 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: 5745236c (apiv2-stack/21-onboarding-tour-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: After a lost reply, finishing the tour closes it without opening the route the user picked
  • minor: The new tourChanged error tells the user to close the tour, but no control can close it
  • minor: The rewritten legacy-invite skip in the gate has no test, and the PR body says it does

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5745236c46

ℹ️ 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".

Comment on lines +554 to +556
guard state.tourId == body.tourId,
!(body.completed || body.skipped) || state.done else {
throw OnboardingProgressError.unexpectedReceipt

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate the step recorded by progress receipts

When an intermediate progress request receives a 200 response for the same tour but with an unchanged or different last_step, this guard accepts the receipt and the view model advances while chaining its ETag, even though the requested step was not confirmed. This can leave the UI ahead of the durable server state and cause a later launch to resume at the wrong step; require state.lastStep == body.lastStep for non-terminal writes before treating the receipt as saved.

Useful? React with 👍 / 👎.

@Quick104
Quick104 force-pushed the apiv2-stack/20-overlay-config-v2 branch from 2d85bb6 to ac2291a Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/21-onboarding-tour-v2 branch from 5745236 to 34e0370 Compare September 23, 2026 13:19

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34e0370ac1

ℹ️ 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".

Comment on lines +292 to +294
guard fresh.state.tourId == tourId else { throw OnboardingProgressError.tourChanged }
if fresh.state.done, !loadedDone { return .finishedElsewhere }
current = fresh

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reconcile newer server progress before writing

After a stale or unanswered write, the fresh state can contain a later nonterminal lastStep recorded by another client. This path checks only done and the tour ID, then writes the Apple client's earlier step with the fresh ETag, overwriting the newer durable resume position. Compare the returned step against the flow and adopt already-reached progress instead of issuing a regressive write.

Useful? React with 👍 / 👎.

@Quick104
Quick104 force-pushed the apiv2-stack/20-overlay-config-v2 branch from ac2291a to a3b7150 Compare September 23, 2026 13:37
Base automatically changed from apiv2-stack/20-overlay-config-v2 to main September 23, 2026 13:38
Quick104 and others added 2 commits September 23, 2026 09:38
The onboarding tour still read its flow and state from /api/v1 and posted
progress there. A 1.0 server answers those with 410, and v2 guards
progress with the state's ETag, so the tour could not move to v2 by path
alone. The gate also had no clear rule for errors: it had to be proven
that it never opens the tour unless the server confirms it is unfinished.

The tour now reads state and flow through APIv2Client.onboardingRead and
keeps that session's strong ETag. Each progress step is one
PUT /api/v2/onboarding/progress with If-Match, and the receipt's tag
replaces the old one. The operation is non_retryable: the tag is taken
before dispatch, so a 412, 428, 409 or lost reply is never re-sent. The
next step the user takes reads the state again first and closes the tour
if it is already finished. A finishing receipt that is not done, or that
names another tour, is refused. Profile writes from the tour act only for
the profile that loaded it.

The gate opens the tour only on a confirmed, unfinished state and stays
closed on any error, including an update-required server. Its retry of an
unrenderable tour and its legacy invite skip read the state first and
write under that tag. The legacy skip reads the account through
APIv2Client.currentUser. SiloAPI's three v1 onboarding methods are gone,
and onboardingWrite drops the redundant writer id.

Stack-PR: W5-F
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A finish whose reply was lost left the tour open with an error. When the
user tapped the button again, the re-read showed the tour done and the
tour closed without opening the route the user had picked. A tour the
server had replaced was worse: every control wrote progress, got 409 or a
re-read naming another tour, and the error told the user to close a tour
that had no close control.

A finish now keeps its route when the re-read shows it already landed;
only the write is skipped. A 409 or a re-read naming another tour closes
the tour with no route and logs the cause, and the gate reads the new
tour on its next check. "Continue without saving" closes the tour even
when its progress write fails. The tourChanged copy no longer points to
a control that does not exist.

Tests cover the route after a lost finishing reply, both replaced-tour
paths, and the gate's legacy invite skip for an open state, a done state,
a failed state read and another account's marker.

Stack-PR: W5-F
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the apiv2-stack/21-onboarding-tour-v2 branch from 34e0370 to 8c8d7f8 Compare September 23, 2026 13:38
@Quick104
Quick104 merged commit 2eebb40 into main Sep 23, 2026
3 of 6 checks passed
@Quick104
Quick104 deleted the apiv2-stack/21-onboarding-tour-v2 branch September 23, 2026 13:38
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