Repository navigation
fix(downloads): pick the version the profile watches when none is named - #1630
Conversation
A download that omits media_file_id (season, series and monitored episodes, and any client that leaves Auto to the server) always got the highest-resolution file, with ties going to database order. A user who watches a different version, such as a 1080p file with a sidecar .srt next to a 2160p file without one, got the other file offline. Native requests now pick from the profile's watch history: the file last played for that movie or episode, then for an episode the version closest to the series' most recent play (edition, resolution, HDR, video codec) within the profile's latest 200 progress rows, then the highest resolution with the lowest file id breaking ties. The v1 bridge keeps its highest-resolution default, so a repeated v1 request never swaps files a device already has. Items with one file skip the history reads.
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Providing Context (Files & MCPs)Add these hints in your PR description (or a comment) to unlock deeper checks:
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Warning Review limit reachedNext included review available in 33 minutes. View limit detailsLimit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (8)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (9)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughDownload file selection can use profile watch history. Native requests and paged subscription sync pass profile context for selection; regular subscription sync retains the default behavior. The API documentation describes how the server selects a version when ChangesDownload version history
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant DownloadClient
participant Registry
participant DownloadsService
participant ProgressStore
participant FileRepository
DownloadClient->>Registry: Submit download request
Registry->>DownloadsService: Create with VersionFromHistory enabled
DownloadsService->>ProgressStore: Load profile progress and recent history
ProgressStore-->>DownloadsService: Return progress rows
DownloadsService->>FileRepository: Resolve episode files for history rows
FileRepository-->>DownloadsService: Return episode files
DownloadsService->>DownloadsService: Select preferred file
Suggested reviewers: Merge Risk: 🟡 Moderate · up to Some downloads can appear ready but fail whenever requested. Align file selection with the serving access rules before merging. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to A download can now be registered for a previously watched version that the user is no longer allowed to retrieve. File delivery still blocks access, but the affected download may appear ready and remain unusable. The impact is limited to affected users and entries; no unauthorized file delivery was established. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 26.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 8 files. (1 skipped: 1 unsupported.) ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
An automatic pick could register a version the profile's library access or quality ceiling forbids, leaving an entry that looks ready but can never be served. Candidates are now narrowed with the request's access filter first; when none qualify the full list is kept and serving reports the refusal as before.
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Providing Context (Files & MCPs)Add these hints in your PR description (or a comment) to unlock deeper checks:
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
Validation impact: Please update the line so it does not describe C1 as unaffected. Suggested line: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
An automatic pick narrows candidates to versions the profile may play but keeps all of them when none qualify, so the create or the later file request can still be refused. The doc claimed that could not happen. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Providing Context (Files & MCPs)Add these hints in your PR description (or a comment) to unlock deeper checks:
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Quick104
left a comment
There was a problem hiding this comment.
Review summary
Reviewed head: f077ae8
Addressed
- Doc overclaim (low, docs only):
docs/downloads-api.mdsaid an automatic pick never registers a file the server would refuse to serve. When none of an item's versions pass the access filter,allowedCandidateskeeps all of them, so a series or season page atoriginalcan still register a file that serving refuses. f077ae8 describes the fallback and leaves the behavior as it is. The fallback lets aqualitypreset transcode an over-ceiling source. - Kody's access finding: checked 1626a35.
resolveFileandepisodeItemsWithSkippedboth filter candidates before picking.
Checked, no defect found
- A repeated v2 request without
media_file_idcan't swap a downloaded file. Managed single downloads requireexpected_revision, season pages keep unguarded existing entries, and monitor sync only inserts absent entries. - v1 keeps highest resolution. The file lookups already order by
id ASC, so the new lowest-id tie-break matches the old pick and v1 devices see no swap. - Missing files are excluded at the query. Progress hints are copied from the source file's fields, so the resolution, HDR, codec and edition comparisons use the same format. The history read is one top-200 page per request.
Validated features: none affected. Every case on #1168, Silo-Server/silo-apple#319 and Silo-Server/silo-android#329 is still "Not run", and the PR's Validation tasks: line is accurate.
Validation: internal/downloads and internal/apiv2 pass against a freshly migrated Postgres with no DB skips; gofmt and go vet are clean. All CI checks pass on this head. Go test first failed in TestFailedBackendIsReplaced (internal/librarymonitor, a 10 s timing test outside this diff) and passed on re-run.
Mergeability: 9/10, ready. The server picks a version only when the client names none, the order is documented, and the frozen v1 bridge keeps its old default. No open findings remain.
AI-assisted review: Claude Code with claude-opus-5-5.
Problem
Related issue: #1167
Validation tasks: changes #1168 C1 (not yet run; automatic picks now respect library access and the quality ceiling)
When a download request has no
media_file_id, the server saves the highest-resolution file and breaks ties by database order. That covers season and series downloads, monitored series, and any client that leaves Auto to the server. A user who watches a different version, for example a 720p file with an English sidecar.srtnext to a 1080p file without one, gets the 1080p file offline and loses the subtitles.Approach
Native v2 requests now pick from the profile's watch history, in this order:
The frozen v1 bridge keeps the highest-resolution default for single, series and monitor requests, so a repeated v1 series request never swaps files a device already has. v2 season pages already keep existing entries unless the client guards them, and monitors only add entries, so a change in watch history never replaces downloaded episodes. Only versions the profile may play (library access and quality ceiling) are candidates for an automatic pick. Requests with
media_file_idbehave as before, and items with one file skip the history reads.docs/downloads-api.mddocuments the order.The clients now send the version they show: Silo-Server/silo-apple#536. Android also needed Silo-Server/silo-android#407, because episode downloads were rejected with 404, and Silo-Server/silo-android#408.
Validation
gofmt,go vet,make lint-changed(0 issues) and every verify target in the gate pass.internal/downloadsagainst a migrated Postgres test database passes with no skips. New tests cover the three rules, the v1 opt-out for single and monitor requests, and the bounded history read.make test-gofails only in tests this branch does not touch, and they fail the same way on unmodifiedmainon the macOS machine used:TestAdminResourceCapabilitiesAndScope(expects Linux cgroups) and theinternal/playbackhardware-probe tests. Threeinternal/jellycompattranscode-timing tests failed under full-suite load and pass when run alone.make test-webfails on this machine's Node v25 (localStorage.clear is not a functionfrom jsdom); the branch has noweb/changes..srtand a 1080p file: after E1 was played in 720p, a v2 season download registered 720p for both episodes (1080p before). With no history it registered 1080p, and the same request through v1 still registered 1080p. Repeating a season request after the history moved to 1080p kept the existing entries.Risks
v2 clients that omit
media_file_idcan now get a different file than before; the docs describe the order. Each download that needs a choice adds one bounded progress read (200 rows) and one file lookup, and a failed read falls back to the old default.Checklist
AI Disclosure
codex review --uncommitted) for independent reviewNote
Use profile watch history to pick download versions when no
media_file_idis givenmedia_file_id, the service now picks the version the requesting profile last watched: the item's last-played file first, then the best match for recent series history (edition, resolution, HDR, codec), then the old default orderingpickBestFilehighest-resolution selector withversionPreference.pickandpreferredByDefaultin version_preference.go; see also service.go and download_create.gomedia_file_id) download version selection can now return a lower-resolution file than before when history points there; explicit file IDs are unchanged, and legacy subscription sync keeps the old behaviorMacroscope summarized f077ae8.