Repository navigation
feat(downloads): let admins pause, resume, and cancel download preparation - #1925
Conversation
…ation Administrators could watch offline-download preparation jobs but not stop them, so a queue of long transcodes held every prepare slot until each one finished, including jobs nobody was waiting for any more. Pause keeps a job's queue position but hides it from ClaimNext through a new paused_at column; a running encode is fenced out through its lease and stopped at once on the replica that took the request. Resume clears the pause. Cancel deletes the job and fails the downloads still waiting on it with "Canceled by an administrator". The v2 admin API adds pause, resume, and cancel operations with per-job outcomes, and the web Activity tab adds row actions, bulk selection, and a cancel confirmation. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
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. |
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (39)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
| const results: AdminDownloadPreparationActionResult[] = []; | ||
| for (let start = 0; start < ids.length; start += ADMIN_DOWNLOAD_PREPARATION_ACTION_MAX_IDS) { | ||
| const response = await v2(ACTION_OPERATIONS[action], { | ||
| profileContext: context, | ||
| body: { ids: ids.slice(start, start + ADMIN_DOWNLOAD_PREPARATION_ACTION_MAX_IDS) }, | ||
| retryAuthentication: false, |
There was a problem hiding this comment.
runAdminDownloadPreparationAction batches the caller's IDs without removing duplicates across chunk boundaries, so a job ID repeated before and after the 500-ID boundary is processed twice, producing duplicate results, incorrect action counts, and a possible unchanged result while violating the one-result-per-distinct-ID client API contract. Deduplicate IDs before chunking while preserving first-occurrence order.
const unique = [...new Set(ids)];
const results: AdminDownloadPreparationActionResult[] = [];
for (let start = 0; start < unique.length; start += ADMIN_DOWNLOAD_PREPARATION_ACTION_MAX_IDS) {
const response = await v2(ACTION_OPERATIONS[action], {
profileContext: context,
body: { ids: unique.slice(start, start + ADMIN_DOWNLOAD_PREPARATION_ACTION_MAX_IDS) },
retryAuthentication: false,
});
results.push(...response.results);
}Prompt for LLM
File web/src/api/v2/adminDownloadPreparations.ts:
Line 50 to 55:
`runAdminDownloadPreparationAction` batches the caller's IDs without removing duplicates across chunk boundaries, so a job ID repeated before and after the 500-ID boundary is processed twice, producing duplicate results, incorrect action counts, and a possible `unchanged` result while violating the one-result-per-distinct-ID client API contract. Deduplicate IDs before chunking while preserving first-occurrence order.
Suggested Code:
const unique = [...new Set(ids)];
const results: AdminDownloadPreparationActionResult[] = [];
for (let start = 0; start < unique.length; start += ADMIN_DOWNLOAD_PREPARATION_ACTION_MAX_IDS) {
const response = await v2(ACTION_OPERATIONS[action], {
profileContext: context,
body: { ids: unique.slice(start, start + ADMIN_DOWNLOAD_PREPARATION_ACTION_MAX_IDS) },
retryAuthentication: false,
});
results.push(...response.results);
}
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
Integrates #1925: a preparation an administrator paused is reported to the device with state "paused" (added to the preparation state enum and the downloads API doc) and is not counted in queue positions. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| running={runningPreparations} | ||
| queued={preparationCounts.queued} | ||
| retrying={preparationCounts.retrying} | ||
| paused={preparationCounts.paused} |
There was a problem hiding this comment.
The server-activity empty-state calculation excludes paused preparations even though the new summary receives and displays a paused count, so totalActive remains zero when all preparation jobs are paused and there are no recent failures, hiding the preparation section and the jobs administrators need to resume. Include preparationCounts.paused in activePreparations or otherwise include it in the empty-state predicate.
const activePreparations = preparationCounts
? preparationCounts.running + preparationCounts.queued + preparationCounts.retrying + preparationCounts.paused
: 0;Prompt for LLM
File web/src/components/ServerActivity.tsx:
Line 307 to 310:
The server-activity empty-state calculation excludes paused preparations even though the new summary receives and displays a paused count, so `totalActive` remains zero when all preparation jobs are paused and there are no recent failures, hiding the preparation section and the jobs administrators need to resume. Include `preparationCounts.paused` in `activePreparations` or otherwise include it in the empty-state predicate.
Suggested Code:
const activePreparations = preparationCounts
? preparationCounts.running + preparationCounts.queued + preparationCounts.retrying + preparationCounts.paused
: 0;
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
A preparing download whose server job an administrator paused reads "Preparation paused on the server" (Silo-Server/silo-server#1925). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ality (#1880) * feat(downloads): let season downloads and series monitors choose a quality - Native season and series batches accept any advertised quality preset, resolved per episode; episodes the preset cannot reach are skipped with quality_unavailable. - Monitors store a quality (new column, default original) and register new episodes in it, preparing files before the monitor lock and pacing prepared episodes to the account's free concurrent download slots. - The download capability reports bulk_quality and monitor_quality. - /api/v1 batches stay original-only. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): share free download slots across concurrent monitor syncs A monitor sync with prepared episodes now holds the account's quota lock from counting free concurrent download slots until its rows commit, so monitors of one account syncing at once cannot each claim every free slot. Quality is still resolved before any lock. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): count prepared replacements and ready files correctly - A season page that replaces an existing entry with a prepared file does so under the quota lock and counts toward the concurrent limit when the replacement adds an active download. - A monitor sync re-reads the monitor before queueing encodes and queues none when the monitor was edited or paused since planning. - An episode whose prepared file is already ready takes no free slot. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): count version changes and refuse stale guards before encoding - A prepared replacement that switches the episode to another media file counts toward the concurrent limit. - A replacement whose expected revision is stale is refused before its encode is queued. - The monitor PATCH body declares quality's preset enum. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): count prepared replacements by readiness, not the period - A prepared replacement counts toward the concurrent limit only when its entry isn't already active and the target's prepared file isn't ready, using the same lookup as monitor pacing. - The period quota counts only new downloads; a replacement updates its entry in place. QuantityLimiter.CheckCounts takes the two counts apart. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * feat(downloads): report preparation progress on listed downloads (#1881) * feat(downloads): report preparation progress on listed downloads - GET /api/v2/downloads attaches a preparation object to preparing entries: queue state and position, or the running encode's progress and estimated time left, ranked the same way as the admin preparation queue. - The download capability reports preparation_progress. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): count a job whose worker lease expired as queued A running prepare job whose lease expired is claimable again, so the preparation view now reports it as queued, with a queue position and without its stale progress. Both the device-facing preparation object and the admin preparation queue use this classification. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): claim prepare jobs in the order the queue position reports ClaimNext now breaks created_at ties by id, the same order the reported queue position uses. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * perf(downloads): share one preparation queue snapshot per node Ranking the preparation queue covers every unfinished job on the server, so download list reads now share one snapshot per node, refreshed at most every 5 seconds, instead of ranking the queue on each request. Concurrent readers wait for a single refresh. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): stop reporting encode progress once samples stop arriving A running encode's progress and estimate are reported only while its worker marks progress available and the last sample is under 30 seconds old (six flush intervals). A worker whose reports stopped no longer shows a frozen percentage. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): share a failed preparation refresh among waiting readers When the queue ranking fails, readers waiting on that refresh now get an empty snapshot for the snapshot TTL instead of each repeating the failing query. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> * chore(api): drop the breaking-change approval consumed by #1925 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…ad sheet (#597) * feat(downloads): show monitored series and simplify the series Download sheet - A Monitored list in Downloads shows each monitored series, its rule, and what downloads next, using the airing calendar for upcoming episodes. - The series page's Download action opens one sheet: One Time (this episode, a season, or all episodes) or Monitor (All Episodes, Future Episodes, or Last Season), with delete-after-watching and a storage limit. - A banner on a monitored series' page says what downloads next. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): keep monitor choices to what the server offers - A new monitor starts on the first rule the server advertises instead of a hidden Future Episodes. - An existing monitor's tab stays reachable when the server stops offering monitoring, so it can still be stopped; saving is disabled there. - A calendar refresh after a profile switch no longer waits on the old profile's load and keeps nothing. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): keep the shown episode version and existing monitor rules - The Download sheet downloads the episode version the series page shows, including an automatic pick, rather than leaving it to the server. - An existing monitor's rule stays listed when the server stops advertising it, and is not resent unless the user changes it. - Monitored series load their titles and posters four at a time. - A failed download no longer hides its episode from "next episode". Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): don't call a monitor up to date before its calendar loads - An idle monitor shows "Monitoring" until the airing calendar has loaded for the profile, instead of "Up to date". - The Download sheet treats an episode whose download request is still in flight as on its way, so it isn't offered again. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): back off series detail reads that failed A monitored series whose title and poster read failed isn't read again until the calendar refresh interval passes, instead of on every view appearance. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): fence the monitor schedule by scope and load - A schedule loaded for another server or profile reads as empty and not loaded, so a switched profile shows "Monitoring" until its own loads. - Each calendar load carries a token; only the current one publishes or clears the in-flight slot. - The Monitor tab is hidden for a new monitor when the server advertises no rule the sheet offers, such as specific seasons only. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): scope monitored series titles and posters to the profile Series titles and posters are read through a scope-checked accessor, and a details load after a profile switch first drops the previous profile's data instead of storing alongside it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): mention monitoring on the empty Downloads screen When the server offers monitoring, the empty Downloads screen also says how to start one, since the Monitored list is reached from Downloads only once something is downloaded or monitored. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * feat(downloads): choose a quality for season downloads and monitors (#598) * feat(downloads): choose a quality for season downloads and monitors - The series Download sheet has a Quality row for one-time downloads and monitors. It starts at the quality set in Settings, and an existing monitor opens with its own. - Season and series downloads send the chosen quality, and monitors store it, on servers that report bulk_quality and monitor_quality. Older servers keep original quality, and the sheet says so. - A monitor at a lower quality shows it in the Monitored list. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): describe season and monitor quality in Settings The download quality footer says the setting is the default for every download and monitor when the server takes a quality for seasons, and keeps "original quality" for seasons only on servers that don't. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): drop quality choices the server stops offering A one-time or new-monitor quality the server no longer offers falls back to the Settings default when the presets change, so the menu never shows a quality the request wouldn't use. Only an existing monitor's stored quality stays listed when it isn't offered. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): mention monitors in the quality note only when they take one On a server that takes a quality for seasons but not for monitors, the Settings note says monitored series download in original quality. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * feat(downloads): show titles and progress for downloads the server is preparing (#599) * feat(downloads): show titles and progress for downloads the server is preparing - Season, series, and monitor downloads arrive without a title or artwork, and their manifest was read only once the file was ready. The app now reads each untitled download's manifest right away for its title, episode number, and series poster. - A preparing row shows the server's queue position or encode progress and time left, on servers that report preparation_progress. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): retry display reads after connection failures Only a refusal of a download (a 4xx other than a timeout or rate limit) stops its manifest being read again this session. A connection failure, timeout, or busy server ends the pass, and the next pass retries. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): run another display pass for records added during one Pages of a season registered while a display pass runs now get their own pass once it finishes, instead of waiting for an unrelated trigger. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): skip an unusable manifest instead of ending the display pass A manifest the app can't use is now a lasting failure for that download, like a refusal, so later downloads still get their titles and artwork. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): don't record a display failure from an outdated scope A manifest read that fails after the server or profile changed no longer adds its download to the new scope's skip list. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): read display manifests four at a time and retry after outages - Untitled downloads' manifests are read four at a time instead of one by one. - A pass that a connection failure, timeout, or busy server ends schedules another, waiting 15 seconds and doubling up to five minutes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * feat(downloads): show when a download's preparation is paused A preparing download whose server job an administrator paused reads "Preparation paused on the server" (Silo-Server/silo-server#1925). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): drop a display retry when the scope changes A pending display-fill retry is cancelled when the server or profile changes, and a retry only runs in the scope that scheduled it, so the previous scope's backoff can't hold back the new scope's retries. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): keep long quality values on one line in the Download sheet The Quality and Storage limit menus shared the row width with their label, so a preset like "1 Mbps · up to 480p" wrapped out of the row. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): keep the monitor banner and display-fill retries reachable Show the series banner for an existing monitor even when the server no longer offers monitoring, as the Monitored list does, so it can still be stopped from the series page. A display-fill retry that woke after its scope was gone returned without clearing itself, so if that scope came back the finished task blocked every later retry. It now clears itself before checking the scope. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): cancel the display-fill retry on deactivation Deactivation already cancels the poll and scope-load tasks; the retry now goes with them instead of waking later to find its scope gone. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Problem
Related issue: #998
Validation tasks: none
Administrators can watch offline-download preparation jobs on Activity → Download preparation, but they cannot stop them. A queue of 4K-to-720p transcodes holds every prepare slot until each encode finishes or fails, even when nobody needs the result any more. That includes jobs whose downloads were deleted on the device, which keep encoding (#998). The only way out today is to wait or restart the server.
This change lets an administrator pause, resume, and cancel preparation jobs, one row at a time or for a selection.
preparing.Approach
download_artifactsgets a nullablepaused_at.ClaimNextskips paused rows, so pausing needs no new values in the recipe status families (queued,tone_map_queued,audio_v2_queued,tracks_v1_queued).Stopping a running encode reuses the existing lease fence. Pausing returns the row to its queued status and clears
lease_owner, and canceling deletes the row; either way the worker's next heartbeat fails and it aborts FFmpeg, and itsMarkReadyorMarkFailedOrRetrywrite is rejected. On the replica that handled the request the encode is canceled at once through an in-process registry of running attempts. On another replica it stops at its next heartbeat, within about 40 seconds. A paused job keeps an unownedlease_expires_atone lease length (two minutes) ahead thatClaimNextwaits out, so a quick resume cannot start a second attempt on the same local output path while the first may still run.Cancel needs two more guards. New jobs write to a path that includes the job id, so a job created after a cancel never shares a file with the canceled encode, and a local encode that finishes after its row was deleted removes its file. Remote attempts already go through the orphan cleanup queue, which treats a locator whose row is gone as abandoned. A download linked to a job while the cancel commits fails with the same message, when
ConfirmArtifactLinkruns or at the next queue reconciliation, so it cannot wait inpreparingforever.The v2 admin API adds
POST /api/v2/admin/downloads/preparations/pause,/resume, and/cancel. Each takes{"ids": [...]}(up to 500) and returns one outcome per distinct id:applied,unchanged,not_found, ornot_applicable. The list gains apausedstate withpaused_at,counts.paused, and the capability document gainscontrols. Each action publishes the existingdownload_preparation.changedevent, and cancel publishes the usualdownloaduser-state event for each failed download. The web Activity tab adds row actions, checkbox selection with a bulk bar, and a confirmation before cancel that says how many waiting downloads will fail.Validation
go testforinternal/downloads,internal/apiv2,internal/api,internal/contractledger,internal/contractspecpass apart from two tests that also fail onmainlocally (TestAdminResourceCapabilitiesAndScopeon macOS,TestManagedCreateAbsenceRacePostgres). The new DB tests are listed inscripts/ci/db-contracts.txt.verify-apiv2-openapi,verify-apiv2-fixtures,verify-apiv2-web-types,verify-route-inventory, andverify-migration-ledgerpass.verify-apiv2-contractpasses with the approval inbreaking-approvals.json(see Risks).make lint-changed: 0 issues. Web:tsc -b, eslint (no errors), prettier, and the Activity and preparation vitest suites pass.make verify-local-pathscrashes on macOS in files this change does not touch; the diff was checked for local paths by hand.Evidence: https://evidence.siloserver.org/r/silo-server/download-prep-controls/
Risks
stateon the preparation list gains the valuepaused, which the contract check counts as breaking. Only the web admin reads this endpoint (silo-apple and silo-android do not), and this change teaches it the value. The approval is recorded incontracts/api/v2/breaking-approvals.json.paused_atand can still claim a paused job until it is upgraded.Checklist
AI Disclosure
preparingforever, that a canceled encode on another replica could share an output file with a re-requested job or leave its file behind, a stop grace shorter than the lease, a gap in the local attempt registry, and bulk actions that reached rows hidden by filters. All of these were fixed and tested. Its remaining finding, older replicas claiming paused jobs during a rolling upgrade, is listed under Risks.🤖 Generated with Claude Code
Note
Add admin pause, resume, and cancel endpoints for download preparations
POST /api/v2/admin/downloads/preparations/pause,/resume, and/cancelroutes in admin_download_preparations.go. Each accepts 1-500 preparation IDs and returns per-ID outcomes (applied, unchanged, not_found, not_applicable).paused_atcolumn ondownload_artifactsin 20261004050341_add_download_artifact_paused_at.sql, plus paused state, counts, and ordering in preparation listings.ClaimNextno longer claims paused or lease-grace-period jobs; the list-preparations response adds apausedenum value (approved in breaking-approvals.json); existing artifact output paths change because of the new ID component.Macroscope summarized 459aa9d.