Skip to content

feat(downloads): report preparation progress on listed downloads - #1881

Merged
Quick104 merged 10 commits into
feat/download-quality-overridesfrom
feat/download-preparation-progress
Oct 4, 2026
Merged

Quick104 merged 10 commits into
feat/download-quality-overridesfrom
feat/download-preparation-progress

Conversation

@Quick104

@Quick104 Quick104 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

A download the server has to prepare first (a remux or a lower-quality transcode)
sits in preparing with no sign of how long it will take. Encodes run one or two
at a time, so a season can wait an hour, and clients can only show a spinner. They
cannot tell "waiting behind ten other jobs" from "almost done".

This adds the queue position and encode progress to listed preparing downloads,
so clients can show "3rd in line" or "35%, 6 min left".

Approach

  • GET /api/v2/downloads attaches a preparation object to each entry whose
    status is preparing and that is linked to a prepare job:
    • state: queued, running, or retrying;
    • queue_position: 1-based place among every queued job on the server, while
      queued;
    • progress and remaining_seconds: the encoded fraction and the time left at
      the encode's reported speed, once a running encode reports them.
  • The values come from the same query the admin preparation queue uses, so both
    views rank the queue the same way, and that ranking follows the order workers
    claim jobs in. A running job whose worker lease expired is claimable again,
    so both views now count it as queued, without its stale progress. The claim
    query breaks ties the same way the position does.
  • The download capability reports preparation_progress. Other responses that
    return an entry do not carry preparation.
  • If the lookup fails, the list is returned without it and the server logs a
    warning.

Stacked on #1880 (download quality for season batches and monitors); it
shares that PR's capability struct and generated contracts. It does not depend on
its behaviour.

Validation

  • Go: build, gofmt, go vet, changed-line lint on the touched packages, and
    the downloads and API v2 test packages. The only failures are the two that also
    fail on main (see feat(downloads): let season downloads and series monitors choose a quality #1880).
  • New tests cover the progress and time-left arithmetic, the queue ranking against
    Postgres (another account's job ahead, a job waiting out a retry backoff, a
    finished job, a ready row), and the v2 transport. The Postgres test is added to
    scripts/ci/db-contracts.txt.
  • Generated OpenAPI, fixtures, and web types are current.
  • Deployed to a shared development server; a listed preparing download returned
    {"state":"queued","queue_position":5}. A running encode's percentage was not
    observed there; the tests cover it.

Risks

  • queue_position counts every queued job on the server, so a user can infer how
    many prepare jobs other accounts have queued. It does not reveal whose jobs or
    what they are.
  • The ranking covers every unfinished prepare job on the server. Each node runs
    it at most once every 5 seconds and shares the result across list reads, so
    its cost grows with the queue, not with the number of polling clients;
    positions and progress can be up to 5 seconds stale.
  • The iOS client is feat(downloads): show titles and progress for downloads the server is preparing silo-apple#599; Android parity is not done.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (Claude Agent SDK, in T3 Code)
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5[1m]
  • Involvement: AI-assisted
  • Adversarial review: The independent review agent used for feat(downloads): let season downloads and series monitors choose a quality #1880 could not read this part's code, so the code itself has had no independent review. From the design it raised that queue_position reveals server-wide queue depth and that the ranking runs on every list read; both are under Risks. On the PR, Codex found that a job whose worker lease expired still read as running with frozen progress; fixed in f38d116. Later passes found that the claim query broke created_at ties differently from the reported position (fixed in fb957b2) and that every list read ranked the whole queue (now a 5-second snapshot per node, bbe27e9).

🤖 Generated with Claude Code

Note

Add preparation progress reporting to listed downloads in the v2 API

  • Download listings now include a preparation object on rows in queued, running, or retrying state, with queue position, progress fraction (0-1), and remaining seconds. Only GET /api/v2/downloads attaches it.
  • New DownloadPreparation type in download_registry.go and preparation_status.go; OpenAPI contract, docs, and generated TypeScript schema are updated.
  • The downloads capability response now reports preparation_progress: true when the downloads service is configured.
  • Preparation status comes from a node-local 5-second shared snapshot (preparationStatuses) that ranks queued jobs across the whole server and computes running progress from encode position and speed. Refresh failures are logged and do not fail the listing.
  • Risk: contract change — preparation_progress is now a required field in the download capability schema in openapi.json, so old capability responses without it fail validation. Also, preparationStatesCTE in preparations.go now classifies expired running leases as queued.

Macroscope summarized 7538192.

- 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]>
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

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: b09fe5a3-b54b-4a18-a6c5-d9099827fcb7

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
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 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-10-04T16:00:43.565493Z 7538192 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.

@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: e833e707a9

ℹ️ 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".

Quick104 and others added 2 commits October 4, 2026 02:00
…paration-progress

# Conflicts:
#	scripts/ci/db-contracts.txt
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]>

@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: f38d116888

ℹ️ 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".

Quick104 and others added 2 commits October 4, 2026 02:09
…paration-progress

# Conflicts:
#	scripts/ci/db-contracts.txt
…ports

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]>

@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: fb957b2eef

ℹ️ 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".

Quick104 and others added 2 commits October 4, 2026 02:29
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]>

@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: bbe27e9dd2

ℹ️ 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".

Quick104 and others added 2 commits October 4, 2026 02:43
…paration-progress

# Conflicts:
#	scripts/ci/db-contracts.txt
…ving

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]>

@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: d0e6c716e0

ℹ️ 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".

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]>
@Quick104
Quick104 merged commit 0b17865 into feat/download-quality-overrides Oct 4, 2026
14 checks passed
@Quick104
Quick104 deleted the feat/download-preparation-progress branch October 4, 2026 16:06
Quick104 added a commit that referenced this pull request Oct 4, 2026
…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]>
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