Skip to content

refactor(networking): delete the v1 transport - #398

Merged
Quick104 merged 2 commits into
mainfrom
apiv2-stack/50-delete-v1-transport
Sep 23, 2026
Merged

Quick104 merged 2 commits into
mainfrom
apiv2-stack/50-delete-v1-transport

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

The Apple clients now send only /api/v2 requests plus the unauthenticated GET /api/v1/health probe, and the leftover v1 transport is deleted. A DEBUG assertion and an exact CI guard keep it that way.

Problem

After the earlier PRs in this stack, every request from the Apple clients goes to /api/v2 except the retained, unauthenticated GET /api/v1/health probe (ConnectionMonitor.healthPath). Leftover code still made v1 calls look possible:

  • HTTPClient still had the v1-era JSON verbs (post, postVoid, put, putVoid, patch, patchVoid, delete, postRaw, putRaw, postMultipart) and their send/sendRaw/sendRawBody helpers. None had a production caller.
  • HTTPError still parsed the v1 {error, message} error envelope. StartupContentPrefetcher still matched the v1 profile codes profile_unverified and profile_not_found.
  • The v1 wire models AuthUser and ImpersonationInfo and the unused APIv2Client.requestPost were still in the tree.
  • Several doc comments and test inputs still named /api/v1 routes.
  • The /api/v1 guard only enforced a ceiling, so a removed v1 path could stay in the allowlist.

Solution

  • Transport deletions. Deleted the unused HTTPClient verbs and helpers. Also deleted the JSON request-body encoding (AnyEncodable, EmptyResponse) and HTTPError.encodingFailed, which only those verbs used. get is now a single path-only method; its two production callers pass no query. Removed .encodingFailed from the eight exhaustive switches that listed it. multipartBody, requestData, getUnauthenticated*, getWithBearer and revokeSession stay because they have production callers.
  • v1 error parsing. Removed HTTPError.serverErrorCode and the v1 message display. Non-2xx HTTPError.http now reads "Server returned status N" unless the response is the client-upgrade 410. v2 problem bodies have no message field, so v2 errors show the same text as before. UpdateRequirement still recognizes the v1 tombstone envelope {"error":"client_upgrade_required"} through a private decoder, because the health probe is the one request that can still receive it. StartupContentPrefetcher.indicatesInvalidProfile now recognizes only the v2 profile_verification_required problem.
  • Models. Deleted AuthUser, ImpersonationInfo and APIv2Client.requestPost, plus the requestPost case in the CatalogV2Tests fence test. I11 check: grepped for bare, inferred-case (.encodingFailed), trailing-closure and #if uses before each deletion. All three platform builds confirm no uses remain.
  • DEBUG assertion. HTTPClient.buildRequest now calls assertionFailure in DEBUG builds when the route is neither /api/v2 (exactly, or followed by /) nor ConnectionMonitor.healthPath. The check reads the route argument, not the final URL, so servers mounted under a base path still pass. The assertion covers only requests HTTPClient builds. Token refresh builds its URL separately, from the constant /api/v2/auth/refresh. These builders join routes onto the server URL themselves and are not checked: TopShelfHTTPClient, PairingDeviceAPI, APIv2Client.downloadFileURL, the playback control socket handshake and ApplePushDisplayMetadata. HostedDiagnosticsAPI (external host) and server-minted absolute media URLs are not checked either. The CI guard below covers literal v1 paths in all of them. healthPath is now nonisolated so the nonisolated predicate can read it.
  • Comments. Rewrote the remaining /api/v1 doc comments in HTTPClient (route normalization, the refresh-retry log example, the dotted-segment example), the HTTPClient type doc and the perform() call-site list that named the deleted verbs and body encoding, and AuthModels, plus the stale "v1 paths keep working" note in AuthService and the "pilot" wording in APIv2Probe.
  • Tests. Moved neutral inputs to v2 routes in MediaRequestAuthorizationTests, MediaAuthorizationPlaybackTests, RefreshSessionV2Tests, UpdateRequirementTests, DiagnosticsRedactionTests and the StubURLProtocol usage example. Tests that used postVoid now use requestData, which takes the same ordinary refresh path. The health-probe tests in SettingValuesAPITests now use ConnectionMonitor.healthPath. Rewrote InvalidProfileRecoveryTests (in ProfileLaunchPolicyTests.swift) for the v2 problem, and deleted the v1 426 envelope test in PlaybackProtocolV3ConformanceFixtureTests together with its only input, the vendored PlaybackV3/error_response.json. PlaybackV3/SOURCE now lists six vendored files and says why error_response.json is not vendored. Added HTTPClientRequestPathTests for the assertion's predicate, including the base-path case.
  • Guard. scripts/ci/check-no-api-v1.sh is now exact: it fails when any file's count is above or below its allowlist entry, and when an unlisted file matches. The --exact flag is removed because exact matching is now the only mode. The script's test covers removals and lowered counts. The final allowlist has one production file, ConnectionMonitor.swift (the health path). The other entries are DiagnosticsPathTemplateTests (templating vectors), APIv2ProbeTests and HTTPClientRequestPathTests (tests that assert v1 is never requested), and two vendored fixtures (DiagnosticsContract loglines and SettingsContract/SOURCE). HostedDiagnosticsAPI.swift has no entry because its external /v1/... host paths do not match the api/v1 pattern.
  • Docs. docs/native-api-v2.md now says the health probe is the only v1 request and names the assertion and the guard that enforce it.

sites.tsv sweep. The only production /api/v1 match is ConnectionMonitor.healthPath (row 10, retained). Production has no "api", "v1" or appendingPathComponent("v1") construction. git grep -n '"v1"\|appendingPathComponent("v1")' -- iosApp finds only test ETags and video keys. No other row, including E1 and E2, still has production code.

Validation

  • iOS, tvOS and macOS builds pass on this branch.
  • This branch is the top of the stack. The full suites pass: iOS 1981 tests and tvOS 1792 tests, 0 failures. Every branch in the stack also builds on its own.
  • The lane's full-suite runs used the Debug configuration (SWIFT_ACTIVE_COMPILATION_CONDITIONS includes DEBUG), so the new assertion was live, and no test sent a route outside /api/v2 or the health path.
  • bash scripts/ci/check-no-api-v1.test.sh passes, and bash scripts/ci/check-no-api-v1.sh passes in exact mode.
  • After the review fixes (doc comments, fixture removal), focused iOS and tvOS runs of PlaybackProtocolV3ConformanceFixtureTests, PlaybackProtocolV3Tests and HTTPClientRequestPathTests pass (78 tests each, 0 failures).

Risks and follow-ups

  • Behavior change: a non-2xx HTTPError.http whose body used the v1 message field no longer shows that message. Only v1 routes sent that shape, and the client no longer calls them.
  • The fence-line count (withOwnerFence/sameCredentialIdentity in iosApp/iosApp) drops from 68 to 67 on the stacked branch. The removed line was the fence inside the deleted requestPost, which had no production caller, so no live path lost a fence.
  • The server has not yet decided whether the v1 tombstone replies with a problem document or the v1 envelope (S5, S10), so UpdateRequirement still accepts both.
  • Unverified: whether other in-file-only model types (for example OnboardingSettingOption, RequestTarget) are v1 leftovers. They are referenced by live v2 models, so this PR keeps them.

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 50 of 50 in the Apple API v2 stack. Base: apiv2-stack/49-diagnostics-uploads-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: f8282fce-ac5c-4209-91c0-265f7ac119a7

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:47.700347Z d1df5f8 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: ca8bdb60 (apiv2-stack/50-delete-v1-transport).

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: The PR body and the isSiloServerPath doc overstate what the DEBUG assertion covers
  • minor: v1 error-envelope fixture is left with no consumer
  • minor: Doc comments still describe the deleted post/raw/multipart verbs and JSON body serialization

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

ℹ️ 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 80 to 83
} else if ($2 + 0 > allowed[$1]) {
printf "OVER\t%s\t%d\t%d\n", $1, $2, allowed[$1]
} else if (exact && $2 + 0 < allowed[$1]) {
} else if ($2 + 0 < allowed[$1]) {
printf "UNDER\t%s\t%d\t%d\n", $1, $2, allowed[$1]

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 Pin the allowed v1 route, not only its count

When an allowed occurrence is replaced rather than added—most importantly, if ConnectionMonitor.healthPath changes from /api/v1/health to another v1 endpoint—the count remains 1, so this comparison reports no difference. The DEBUG predicate and HTTPClientRequestPathTests also trust that same constant, meaning CI, runtime assertions, and tests would all accept the forbidden route even though the health probe is documented as the sole exception. Pin the production exception's matched text or independently assert the literal health path.

Useful? React with 👍 / 👎.

@Quick104
Quick104 force-pushed the apiv2-stack/50-delete-v1-transport branch from ca8bdb6 to d1df5f8 Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/49-diagnostics-uploads-v2 branch 2 times, most recently from 844efc1 to 2cd4e12 Compare September 23, 2026 13:46
Base automatically changed from apiv2-stack/49-diagnostics-uploads-v2 to main September 23, 2026 13:46
Quick104 and others added 2 commits September 23, 2026 09:46
Every Silo request now goes through /api/v2 except the retained
unauthenticated health probe, but HTTPClient still carried the v1-era
JSON verbs, the v1 error envelope parsing and wire models with no
production caller, and the /api/v1 guard only enforced a ceiling.

Delete HTTPClient's post, postVoid, put, putVoid, patch, patchVoid,
delete, postRaw, putRaw and postMultipart with the send/sendRaw helpers,
the JSON request-body encoding and HTTPError.encodingFailed they alone
used, the v1 `{error, message}` envelope parsing (serverErrorCode), the
v1 profile error codes in StartupContentPrefetcher, AuthUser and
ImpersonationInfo, and APIv2Client.requestPost. UpdateRequirement keeps
recognising the tombstone envelope, which only the health probe can
still receive.

Add a DEBUG assertion in HTTPClient's request builder: a Silo server
route must be a /api/v2 operation or ConnectionMonitor.healthPath.
Rewrite the stale v1 comments, move test inputs to v2 routes, make the
guard exact in both directions and set the allowlist to its final
state.

Stack-PR: Z1
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…rror fixture

The isSiloServerPath doc said only hosted diagnostics and media URLs
bypass HTTPClient's request builder, but TopShelfHTTPClient,
PairingDeviceAPI, the download file URL, the control socket handshake
and the push display URL also build server URLs themselves. The
HTTPClient type doc and the perform() call-site list still described the
deleted post, raw and multipart verbs and JSON body encoding. The
PlaybackV3 error_response.json fixture lost its only test and is the
retired v1 426 envelope.

Name every builder the DEBUG assertion does not cover, describe the
remaining verbs and the refresh-only encoder, delete the fixture and
record in PlaybackV3/SOURCE why it is not vendored.

Stack-PR: Z1
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the apiv2-stack/50-delete-v1-transport branch from d1df5f8 to 6c076a5 Compare September 23, 2026 13:46
@Quick104
Quick104 merged commit 44d9989 into main Sep 23, 2026
3 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.

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