Skip to content

fix(connection): explain v1-only servers instead of reporting them unreachable - #355

Merged
Quick104 merged 2 commits into
mainfrom
apiv2-stack/07-explain-v1-only-servers
Sep 23, 2026
Merged

Quick104 merged 2 commits into
mainfrom
apiv2-stack/07-explain-v1-only-servers

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

When the server and the app are on incompatible versions, the app blames the connection instead of saying what to update:

  • Server add shows "Could not reach a Silo server at that address."
  • Cold-launch restore opens the recovery screen with "We can't verify this server".
  • Error screens show "Something went wrong while talking to the server." (HTTP 410) or retry silently as if the failure were a network blip (APIv2Error.serverUpdateRequired had no status, so ErrorState.isTransient was true).
  • APIv2Client.mapErrors dropped the body of a non-problem 404. A v1-only server's legacy listener answering a v2 route (404 page not found) became APIv2Error.httpStatus(404), which reads the same as any other 404.

This gets worse as each later PR in the stack moves a call to /api/v2. On a v1-only server, every moved call fails this way.

Solution

This implements owner decision D7 (reduced): it reuses the existing copy and adds no new pill or banner UI.

  • New UpdateRequirement (Networking/UpdateRequirement.swift) with two cases:
    • .server: the server is v1-only. The message is the existing "This server needs to be updated before this version of Silo can use it." It moved here from APIv2Error.
    • .app: the server no longer accepts this app version. The message is "Update Silo to keep using this server."
  • The classification covers both request layers, since most calls are still v1 at this point in the stack:
    • APIv2Error.serverUpdateRequired maps to .server. The probe verdict (ConnectionMonitor.isServerUpdateRequired) reaches it through the existing gate().
    • APIv2Client.mapErrors now maps a 404 whose body is exactly the legacy listener's body (APIv2Probe.isLegacyNotFound, match unchanged) to APIv2Error.serverUpdateRequired. This mapping is safe only on /api/v2 paths.
    • HTTP 410 with problem type client_upgrade_required maps to .app, whether it arrives as HTTPError.http or as APIv2Error.problem. On the HTTPError layer, a 410 carrying the v1 error envelope {"error":"client_upgrade_required",...} also maps to .app, because the server's API contract describes the v1 tombstone that way.
    • A bare 410, or a 410 with any other type (playback_session_ended, expired device login), is not an update prompt.
    • A legacy 404 on a v1 path is not classified either, because it does not prove that a v1-only Silo server answered.
  • Where the classification is used:
    • Server add (ServerSetupViewModel): if any candidate URL shows a version mismatch, the update message replaces "Could not reach a Silo server". The view model now takes its server check as an injectable closure; production still calls AuthService.checkServer.
    • Cold-launch restore (RestoredSessionValidator): a classified error returns the new recovery reasons .serverRecovery(.serverUpdateRequired) / .serverRecovery(.appUpdateRequired) instead of .serverNotRecognized or .indeterminate. RestoredServerRecoveryView shows "Server update required" / "Update Silo" with the update message and the existing "saved sign-in information has not been removed" line.
    • Error screens: ErrorState carries updateRequirement and uses the update message. It is neither isNotFound nor isTransient, so Home shows it rather than auto-retrying. ErrorView shows the headline "Update required".
    • Sign-in and other localizedDescription users: HTTPError.errorDescription and APIv2Error.errorDescription return the app-update message for the 410 problem.
  • A 410 never invalidates a session. Refresh still fires only on 401, and the refresh-failure classifier (400/401/403) is unchanged. A test covers this.

Validation

  • iOS, tvOS and macOS builds: PASS.
  • iOS tests: PASS, 92 tests, 0 failures. Classes: UpdateRequirementTests, RestoredSessionValidatorTests, APIv2ProbeTests, APIv2ContractStateTests, PlaybackProtocolV3ConformanceFixtureTests, CatalogV2Tests.
  • iOS tests, second run: PASS, 339 tests, 0 failures. Classes: APIv2SubtitleTests, ArtworkURLTests, AuthDeviceV2Tests, CollectionsV2Tests, HomeSectionsMutationTests, ProfileAndQualitySettingsTests, PlayerSettingsFlushTests, SettingValuesAPITests, UICustomizationPreferencesTests, RequestErrorCopyTests, AccountSessionPersistenceTests.
  • tvOS tests: PASS, 64 tests, 0 failures. Classes: UpdateRequirementTests, RestoredSessionValidatorTests, APIv2ProbeTests, APIv2ContractStateTests, RequestErrorCopyTests, PlaybackProtocolV3ConformanceFixtureTests.
  • After a final cleanup (removing an unused probe-result initializer), UpdateRequirementTests and RestoredSessionValidatorTests were re-run on iOS and tvOS (21 tests each, PASS), and macOS was rebuilt (PASS).
  • New tests, all on StubURLProtocol:
    • A classification table covering both layers, including a 410 with a different problem type, a bare 410, and a legacy 404 on a v1 path.
    • APIv2Client.setupStatus against a legacy 404 page not found, a problem+json 410, and an HTML 404.
    • An HTTPClient-layer 410 with a problem document or the v1 error envelope, checked through localizedDescription and ErrorState.
    • A 410 on an authenticated HTTPClient GET and on v2 account/me: no refresh request is sent, and both tokens are kept.
    • ServerSetupViewModel table: a v1-only server on every candidate, a v1-only server behind one scheme, a 410 through each layer, a legacy 404 on the HTTPClient layer, a proxy 404, and no server answering.
    • RestoredSessionValidator table: real v2 setup or HTTPClient requests against a legacy 404 and a problem+json 410, plus a 410 from the account probe. Each case keeps the access token and skips the account probe after a setup failure.
  • Review fixes: the first revision's tests added six /api/v1 literals, which the v1 path guard rejected. The HTTPClient-layer cases now use a neutral /probe path, and the v2 no-fallback check asserts the exact requested paths. A new classification row and wire test cover the v1-envelope 410. After these fixes, UpdateRequirementTests, RestoredSessionValidatorTests and PlaybackProtocolV3ConformanceFixtureTests passed on iOS and tvOS (25 tests each, 0 failures), and the iOS, tvOS and macOS builds passed.
  • scripts/ci/check-no-api-v1.sh: ok.
  • No manual run against a real v1-only or 1.0 server.
  • Final stack: with all 50 PRs applied, the full iOS suite (1981 tests) and tvOS suite (1792 tests) passed with 0 failures, the macOS build passed, and the v1 path guard passed. Every branch in the stack, this one included, builds on its own.

Risks and follow-ups

  • On this base, a v1-only server still passes server add and cold-launch validation, because setup and auth/me are still v1 calls. The new messages appear once W1-B moves those calls to v2, or when a server answers with the 410 problem. Server version 84ed9e596 defines client_upgrade_required but does not send it yet.
  • The tombstone body shape is not verified against a server. The server's API contract describes it once as a problem code and once as "the existing v1-shaped client_upgrade_required error", so the classifier accepts both on a 410.
  • Not done, per D7 (reduced): a persistent update banner, disabling writes for a cached session, and update copy for cached item detail (ItemDetailViewModel keeps cached content and hides the error).
  • The plan names ContentView.swift:2772 as a deep link that swallows errors with try?. That line is the iPad neighbour-detail prefetch, where ignoring the error is intended. The play deep link (routePlayDeepLink) falls through to the player, which shows its own error. Neither was changed.
  • SettingsAPIError.serverUpgradeRequired (the v1 settings fallback) is separate and belongs to W1-C.
  • QRLoginViewModel prefixes errors with "Couldn't start sign-in." The update message now follows that prefix. W5-B owns the QR flow.
  • Expected conflict: open PR feat(watch-party): add iOS and tvOS rooms and synchronized playback #347 touches RestoredSessionValidator.swift and ContentView.swift. This PR does not change ContentView.swift.

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 7 of 50 in the Apple API v2 stack. Base: apiv2-stack/06-delete-unused-media-fixtures. 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: c8145c6a-af87-4f58-85f3-0845065a6306

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:35:22.506951Z 28244ca 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: f348ff01 (apiv2-stack/07-explain-v1-only-servers).

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:

  • major: New tests add /api/v1 path literals, which the F2 v1-path guard rejects once this PR is stacked
  • minor: The v1-layer app-update check recognizes only a problem+json 410, but the server's authoritative contract describes the v1 tombstone as the v1-shaped error

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: f348ff014e

ℹ️ 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 +43 to +44
case APIv2Error.problem(let problem) where Self.isClientUpgradeRequired(problem):
self = .app

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 Preserve the HTTP status when classifying v2 upgrade problems

When a /api/v2 response has a non-410 HTTP status but its JSON body contains status: 410 and the client_upgrade_required type, APIv2Client.mapErrors discards the transport status and this branch incorrectly tells the user to update Silo. This bypasses the outer-status check applied to HTTPError and can misclassify an inconsistent server or proxy response; retain the HTTP status in APIv2Error.problem or only classify the problem as an upgrade when the actual response status is 410.

Useful? React with 👍 / 👎.

@Quick104
Quick104 force-pushed the apiv2-stack/06-delete-unused-media-fixtures branch from 5dded52 to 3938db4 Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/07-explain-v1-only-servers branch from f348ff0 to 5dc5b35 Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/06-delete-unused-media-fixtures branch from 3938db4 to 1b2df9c Compare September 23, 2026 13:30
Quick104 and others added 2 commits September 23, 2026 09:30
…reachable

A v1-only server, or a server that no longer accepts this app version,
surfaced as "Could not reach a Silo server" on server add, "We can't verify
this server" on cold launch, and a generic "Something went wrong" on error
screens. APIv2Client also dropped the legacy 404 body, so a v2 route
answered by a v1-only server became a plain HTTP 404.

Add one UpdateRequirement classification (server update or app update)
that both request layers map to: APIv2Error.serverUpdateRequired, a legacy
404 on any /api/v2 route (now mapped in APIv2Client.mapErrors), and HTTP
410 with the client_upgrade_required problem type from either layer. Server
add, the restored-session validator and its recovery screen, ErrorState and
ErrorView, and the HTTPError/APIv2Error descriptions (used by sign-in) now
show the existing server-update copy or "Update Silo to keep using this
server." A 410 never triggers a refresh or clears tokens.

Stack-PR: F5

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…tombstone envelope

The new UpdateRequirement tests added six /api/v1 path literals, which
F2's v1-path guard rejects once this PR sits on top of it. Classification
also accepted only a problem document on a 410, while the server's API
contract describes the v1 retirement tombstone as the v1-shaped
client_upgrade_required error, so that answer would still read as an
unreachable or unrecognized server.

The HTTPClient-layer tests now request a neutral path and assert exact
requested paths instead of checking for a v1 prefix. A 410 whose body is
the v1 error envelope with error client_upgrade_required now classifies
as an app update, covered by a table row and a wire test.

Stack-PR: F5

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Base automatically changed from apiv2-stack/06-delete-unused-media-fixtures to main September 23, 2026 13:30
@Quick104
Quick104 force-pushed the apiv2-stack/07-explain-v1-only-servers branch from 5dc5b35 to 28244ca Compare September 23, 2026 13:30
@Quick104
Quick104 merged commit 45315c2 into main Sep 23, 2026
3 checks passed
@Quick104
Quick104 deleted the apiv2-stack/07-explain-v1-only-servers branch September 23, 2026 13:31
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