Repository navigation
feat(downloads): fetch manifests, assets and files from v2 - #373
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
There was a problem hiding this comment.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code review summaryReviewed head: 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: none. 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 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 ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 10accf0a33
ℹ️ 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".
| deliveryFormat = try keyed.decodeIfPresent(String.self, forKey: .deliveryFormat) | ||
| targetBitrateKbps = try keyed.decodeIfPresent(Int.self, forKey: .targetBitrateKbps) | ||
| mediaFileId = try keyed.decodeIfPresent(Int.self, forKey: .mediaFileId) ?? 0 | ||
| mediaFileId = try keyed.decode(String.self, forKey: .mediaFileId) |
There was a problem hiding this comment.
Preserve numeric IDs in stored manifests
When upgrading from the parent build, already-downloaded manifest.json files contain mediaFileId as a JSON number because the previous OfflineManifest.encode(to:) encoded an Int. Decoding only String now makes DownloadStore.loadManifest return nil; completed records remain marked playable but OfflinePlaybackBuilder.loadPreparedPlayback fails with manifestUnavailable, even though their media is still present. Decode both the legacy numeric representation and the new opaque string representation, and persist the normalized string.
Useful? React with 👍 / 👎.
ad27852 to
f9ad77a
Compare
10accf0 to
0b8330c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b8330ce65
ℹ️ 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".
| guard let path = url?.path, path.hasSuffix("/file"), | ||
| let range = path.range(of: "/api/v2/downloads/") else { return false } | ||
| let id = path[range.upperBound...].dropLast("/file".count) | ||
| return !id.isEmpty && !id.contains("/") |
There was a problem hiding this comment.
Inspect the percent-encoded path before rejecting transfers
When an opaque download ID contains /, downloadFileURL correctly encodes it as %2F, but URL.path decodes that back to /; the id.contains("/") check therefore rejects a URL created by this same client. DownloadSessionDelegate consequently discards its resume data and cancels its live task after relaunch, repeatedly restarting that download from zero. Parse URLComponents.percentEncodedPath so an encoded delimiter remains within the ID segment.
Useful? React with 👍 / 👎.
f9ad77a to
02365c3
Compare
The download pipeline still read the offline manifest from
/api/v1/downloads/{id}/manifest, fetched artwork and subtitles through a
generic path GET, and pointed the background transfer at
/api/v1/downloads/{id}/file. Silo 1.0 answers those v1 routes with 410, and
the transfer's retry loop resent the same resume data after a 410 until it
gave up.
The manifest now comes from getDownloadManifest, must describe the entry it
was asked for, and carries media_file_id as a string. Artwork and subtitles
use getDownloadArtwork and getDownloadSubtitle, and only paths under the
entry's own /api/v2/downloads/{id}/ asset routes are ever sent. The
background transfer requests /api/v2/downloads/{id}/file with headers taken
from one captured owner, and the whole pipeline applies results only while
the scope that started it is still loaded.
A 410, 412 or 416 on the file transfer now restarts the download from a
fresh manifest without the old resume data, bounded by the existing retry
limit. Resume data or a live background task that targets anything other
than the v2 file route is discarded before it sends a request, and its
download restarts. The v1 manifest, asset and file-URL helpers and the
unused HTTPClient.getData are deleted.
Stack-PR: W3-C
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
0b8330c to
dc6f6ed
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc6f6ed841
ℹ️ 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".
| let fileId = Int(manifest.mediaFileId) | ||
| let version = FileVersion( | ||
| fileId: manifest.mediaFileId, | ||
| fileId: fileId ?? 0, |
There was a problem hiding this comment.
Treat nonnumeric file IDs as unavailable
When a v2 manifest contains a valid nonnumeric opaque media_file_id, this stores 0 in the nonoptional FileVersion.fileId, which does not turn off server-backed subtitle actions as the comment claims. PlayerViewModel.subtitleSearchVisible only checks that the selected version exists, and SubtitleAIController.submit likewise accepts the resulting zero, so offline playback exposes search/AI controls and sends requests for media file 0. Preserve an optional legacy integer ID or explicitly gate those actions on a positive ID and non-offline playback.
Useful? React with 👍 / 👎.
Problem
After W3-B, downloads register through the v2 registry, but the pipeline that fills them still used v1 (inventory rows 94-96):
GET /api/v1/downloads/{id}/manifest(row 94).HTTPClient.getData(path)on whatever path the manifest named (row 95)./api/v1/downloads/{id}/file(row 96).Silo 1.0 answers those v1 routes with 410. The transfer failure handler sent a 410 to its default branch, which resent the same resume data up to four times and then failed the download. The v2 manifest also sends
media_file_idas a string, andOfflineManifestdecoded it as anInt.Solution
getDownloadManifest,GET /api/v2/downloads/{id}/manifest). NewAPIv2Client.downloadManifest(id:auth:)inAPIv2Client+Downloads.swift. It goes through the same owner-fenced registry transport as W3-B (gate(), pre-dispatch identity check,withOwnerFence,X-Silo-Device-IdfromHTTPClient), expects 200, and throws the newDownloadRegistryError.unusableManifestwhen the manifest names another entry or has no file or revision. Nothing from a refused manifest is stored.getDownloadArtwork,getDownloadSubtitle). NewAPIv2Client.downloadAsset(path:downloadId:auth:). It sends a manifest path only when it is exactly/api/v2/downloads/{that entry}/artwork/{kind}or.../subtitles/{ref}: relative, with no query or fragment and one reference segment that is not.or... This mirrors the server's own rewrite check indownload_manifests.go. Any other path is refused before it is sent. A failed asset is logged and skipped, as before.downloadFile).APIv2Client.downloadFileURL(id:serverURL:)builds/api/v2/downloads/{id}/filefrom the captured owner's server URL, keeping any mount path and percent-encoding the id.DownloadAuthHeaders.authorizedRequestnow takes that owner's credentials (the current token for the same owner) instead of readingTokenStorefield by field.queuedinstead of failed.handleMediaFailurenow uses a testablemediaFailureAction. A 410, 412 or 416 on the file transfer restarts the download from a fresh manifest without the old resume data, within the existingmaxRetriesbound. The other statuses keep their behavior: 409 revokes, 404/403 fail, 401 refreshes and retries, anything else resumes. A 410 on the v2 manifest fails the record instead, because it means the app is too old and a retry cannot fix that.DownloadSessionDelegate.resume(data:)returns nil, without sending, when the resume data's request is not a v2 download file route. Callers restart from the manifest.reconnectActiveTaskscancels live tasks on any other route, marking them as intentional cancels, and re-queues their downloads.OfflineManifest.mediaFileIdis a requiredString, with no dual decoder (D1). The storedmanifest.jsonkeys andsubtitleFilenames(keyed byfetch_url) are unchanged. Offline playback maps the string to the player's integer file id at the boundary. A non-numeric id becomes 0, which the v2 subtitle calls already refuse.SiloAPI.fetchManifest(downloadId:),fetchDownloadAssetData(path:),downloadFileURL(downloadId:), the now-unusedHTTPClient.getData, andDownloadSessionDelegate.activeTaskIdentifiers(replaced byliveTasks).iosApp/iosAppstays at 63.Failure outcomes
These are all reads (no
x-silo-retry-safetyon the operations), so there is no uncertain write.manifest.json, display fields appliedqueued, nothing applied. Transport error: failed (unchanged from before)completedstatus event queuedValidation
DownloadDeliveryV2Tests,OfflinePlaybackMappingTests,ArtworkURLTests,DownloadRegistryV2Tests,LegacyDownloadStorageTests,DownloadGroupingTestsandProgressSyncV2Tests. TheArtworkURLTestsmanifest case is iOS-only.DownloadDeliveryV2Tests(onStubURLProtocoland the vendoreddownload_manifest.jsonfixture at server84ed9e596) cover:media_file_idand the v2 asset references;DownloadStorecoder with its file id and subtitlefetch_urlkeys intact;X-Silo-Device-Id, seven out-of-scope asset paths refused without a request, and an asset 404 thrown;OfflinePlaybackMappingTestsandArtworkURLTestsnow sendmedia_file_idas a string.scripts/ci/check-no-api-v1.shpassed.downloadTask(withResumeData:)exposes the resumed request's URL beforeresume(). If it doesn't, the resume data is kept, and a stale one ends in a 410, which now restarts the download.Risks and follow-ups
manifest.jsonwith an integermediaFileId. Under D1 there is no dual decoder, so offline playback of a download completed on such a build reports the manifest unavailable. Release upgrades from before W1-D are unaffected, because W1-D removed that storage.DownloadAPI.swift,DownloadModels.swiftandOfflinePlayback.swift. fix(downloads): retarget store on profile and server switch #181 and feat(apple): detect and label Dolby media formats #72 touchDownloadManager.swiftandOfflinePlayback.swift. 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 25 of 50 in the Apple API v2 stack. Base:
apiv2-stack/24-downloads-registry-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code