Skip to content

fix(downloads): let a series download start with one free slot - #1704

Closed
rangoDJ wants to merge 2 commits into
Silo-Server:mainfrom
rangoDJ:fix/series-download-concurrent-limit-1703
Closed

rangoDJ wants to merge 2 commits into
Silo-Server:mainfrom
rangoDJ:fix/series-download-concurrent-limit-1703

Conversation

@rangoDJ

@rangoDJ rangoDJ commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #1703
Related issue: Silo-Server/silo-android#424 (the Android client doesn't report this failure)
Related PR: Silo-Server/silo-android#429 shows the server's reason when a download is rejected. The two are independent and can merge in either order.
Validation tasks: changes #1217 C1; changes #1218 C1 (both not run yet; their next runs should cover the series batch limit)

Download series failed every time for any series with more episodes than the per-user concurrent download limit, which defaults to 3. It did so even with nothing downloading. The server checked the limit against every episode in the batch and answered 429 rate_limited, and the Android app showed nothing. On a real deployment, every Download series attempt got a 429 while the user's download list was empty.

Approach

QuantityLimiter.Check now requires one free concurrent slot for a request, whatever its batch size (active + min(batchSize, 1) > maxConcurrent). A series batch's episodes are downloaded one after another, so needing a slot per episode only blocked series longer than the limit. Single downloads (batch size 1) behave as before. A batch's queued records still count as active once created, so they keep further downloads blocked until they finish, and the period quota still counts every record in the batch.

The limit only applies when downloads are created; serving the file doesn't check it. The more thorough fix would enforce concurrency when a transfer starts and queue the rest server-side. Every client would then need to handle a "not yet" response, so that's left as a separate decision.

Validation

Run in WSL2 against Postgres 18 (full schema):

  • New Postgres tests cover the concurrent limit across batch sizes: a series longer than the limit with nothing active, with one slot free, and with no slot free; single downloads with and without a free slot; and a single download behind a queued series. They also cover the period quota counting the whole batch. With the previous check restored, the two series cases fail; with this change, all pass.
  • internal/downloads passes, apart from TestConcurrentArtifactCreatesCannotBypassQuotaDB, which times out on main in the same environment too. The download tests in internal/apiv2 and internal/api/handlers pass.
  • make lint-changed: 0 issues.
  • I haven't tried Download series against a deployment running this change.

Evidence

The same Download series request for a five-episode series, from a user with no downloads and the default limit of 3 concurrent downloads, first on main, then on this branch.

Before (main):

POST /api/v1/downloads
{"content_id": "<series id>", "series": true}
HTTP 429 Too Many Requests
{"error": "download_limit_exceeded", "message": "Maximum concurrent downloads reached"}

After (this branch):

POST /api/v1/downloads
{"content_id": "<series id>", "series": true}
HTTP 202 Accepted
5 episode downloads, all queued

On main, a series request that sends X-Silo-Device-Id (managed downloads) already succeeds since #1713, which registers original-quality episodes as ready rather than active. The request above, without a device ID, still reaches the per-episode check this PR changes.

Surface and build: downloads API, local builds of main at c7621772d and this branch at 8529074b9 against one database, with downloads enabled and generated test media.

Risks

A user can now queue a whole series even when it's longer than the limit, so the number of unfinished downloads can exceed the limit until they finish. The period quota (download.max_per_period) still caps the total. If maintainers read max_concurrent_per_user as a hard cap on unfinished downloads, this needs the transfer-time enforcement described above instead.

Checklist

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

AI Disclosure

  • Harness: Claude Code (Claude desktop app, Code tab)
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Self-review. It checked that the limit is only enforced at creation (serving the file doesn't check it), that single-download callers pass a batch size of 1 and are unaffected, and that the new test fails against the previous check.

🤖 Generated with Claude Code

Note

Fix series downloads to require only one concurrent slot per batch

QuantityLimiter.Check in limiter.go now checks concurrent count as min(batchSize, 1) instead of the full batch size. A batch still counts every created episode toward the period quota, and queued batch entries still occupy concurrent slots.

  • Adds tests in limiter_test.go covering oversized batches, batches with exactly one free slot, single downloads at and below the limit, and period-quota behavior for whole batches
  • Risk: a batch larger than the concurrent limit can now start when one slot is free; verify CheckCounts callers that assumed batch size equals slot usage

Macroscope summarized 8529074.

The concurrent download limit was checked against every episode in a series
batch, so with the default limit of 3 any series longer than 3 episodes was
rejected with 429 every time, even with nothing downloading.

A batch now needs one free concurrent slot. Its episodes are downloaded one
after another and still count as active once queued, so they hold back
further downloads until they finish. The period quota still counts the
whole batch.

Closes Silo-Server#1703

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2aa1d2f7-df65-4cdd-a653-fce393439519
📥 Commits

Reviewing files that changed from the base of the PR and between e50d93a and 8529074.

📒 Files selected for processing (1)
  • internal/downloads/limiter.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The concurrent download limit now counts at most one slot for each batch, regardless of batch size. The period quota continues to count every download in the batch. Tests cover concurrent-limit cases and batch period quotas.

Changes

Batch download limits

Layer / File(s) Summary
Batch limit calculation and validation
internal/downloads/limiter.go, internal/downloads/limiter_test.go
QuantityLimiter.Check adds at most one slot for a batch when checking the concurrent limit. Queued records remain active for that check. The period quota still counts the full batch. Tests cover concurrent limits and batches of five and six against a quota of five.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104

Merge Risk: 🔵 Low · up to 85290

A caller that requests multiple files from a batch at once can exceed the configured concurrent-transfer limit. The change is mergeable with awareness that the server does not enforce one-at-a-time delivery.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 85290

Series downloads can now exceed the configured active-download limit without server-enforced sequential transfers. Download permissions, ownership checks and whole-batch period quotas remain intact, but client-side scheduling is not a reliable resource-control boundary.

Retained concerns

  • Medium · security · observed: One-slot admission removes the device-less batch's active-record bound without enforcing the sequential transfers used to justify that change. With a concurrent limit of three and two active records, a ten-item batch can create ten additional queued records, subject to period quota. Each distinct ID can then be requested independently. The resulting resource-control gap concerns shared database and file-serving capacity, not access to another user's content.
Security review details

Security Blast Radius

  • inferred — The directly affected scope is an authorized user's device-less series or season batch. Batch cardinality follows available, accessible episodes and remaining period quota when enabled; the concurrent setting no longer bounds it. Capacity effects could reach other users sharing the database and file-serving process, but operational impact was not measured.

Security Findings and Attack Paths

  • inferred — An authenticated caller with download permission can omit device identity, select an accessible large series, obtain its queued IDs with one free admission slot, and request different IDs concurrently. The inspected server path does not enforce the presumed one-at-a-time client behavior. This supports the admission-control concern, not a claim of verified service exhaustion.

Trust Boundaries and Controls

  • observed — User ownership and catalog authorization remain server-enforced. Client transfer sequencing is different: the new limiter comment assumes sequential episodes, but delivery accepts independent per-ID requests without a batch-level gate. Managed-device creation branches away from the changed Check and uses unchanged CheckCounts accounting.

Resilience and Maintainability Implications

  • observed — Configured bandwidth controls limit aggregate bytes, not simultaneous file handles or streams. Queued rows continue counting as active and constrain further admission under the quota lock. Direct downloads already served authorized files without creating quota-counted records; that pre-existing exposure limits claims that this PR introduces unrestricted streaming for the first time.

Hardening Proposals

  • proposed — Separate queued-record admission from transfer concurrency explicitly. A server-owned transfer reservation or scheduler could enforce concurrent capacity across interruption and retry, while a distinct batch or pending-record budget bounds persistent queue growth. This is a design proposal, not an existing guarantee.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Directly linked issue #1703 is closed, so it supplies historical context only. No active directly linked issue sets coding requirements for this pull request.
Out of Scope Changes check ✅ Passed The reported changes adjust batch concurrency accounting in internal/downloads/limiter.go and add tests for that behavior and period quotas. These changes match the pull request's stated purpose. Th…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
Title check ✅ Passed The title clearly summarizes the main change: series downloads need only one available concurrent slot per batch.
Description check ✅ Passed The description explains the series-download limit problem, the proposed change, validation, and its risk. It is directly related to the changeset.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

@macroscopeapp

macroscopeapp Bot commented Sep 30, 2026

Copy link
Copy Markdown

#1217 C1 is the Server case for limit enforcement. This PR changes the per-user concurrent admission rule for series batches; C1 is currently Not run, so there is no recorded result to invalidate or unblock. Please update the PR field to identify the affected case:

Validation tasks: changes #1217 C1

The batch behavior should be included when C1 is run; single-download and period-quota behavior remain unchanged.

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

…o fix/series-download-concurrent-limit-1703

# Conflicts:
#	internal/downloads/limiter.go
@macroscopeapp

macroscopeapp Bot commented Oct 6, 2026

Copy link
Copy Markdown

The updated line also needs Web admin case #1218 C1. Its steps set global/per-user limits and verify their effect with the Server task; the Downloads settings page exposes download.max_concurrent_per_user, whose series-batch enforcement changes here. Please include that case so its future run covers the changed behavior:

Validation tasks: changes #1217 C1; changes #1218 C1

Both C1 results are currently Not run, so this adds planned coverage rather than invalidating or unblocking a recorded result.

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@Quick104
Quick104 marked this pull request as draft October 6, 2026 19:20

Quick104 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Silo's pull request guidance changed today (#2016). A PR that changes what a user sees now needs before-and-after evidence in its Evidence section, and a PR with no visible change says Evidence: none, no user-visible change. This PR was opened before the rule existed, so it hasn't had a chance to meet it yet.

Missing here: A before-and-after recording of Download series on a long series, or before-and-after excerpts of the download-create response (429 versus success) for the same request.

The rules are in Show visible changes, and the PR template shows the Evidence section layout. I've converted this PR to draft for now. Mark it ready for review once the Evidence section is filled in.


Generated by Claude Code

@rangoDJ

rangoDJ commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Closing: #1713 already fixed this on main. A series or season request that carries X-Silo-Device-Id (managed downloads) registers original-quality episodes as ready, so a series longer than the concurrent limit no longer gets a 429. That is the path every current client uses: Android and Apple create downloads through v2 with the device ID, and the web app has no series download. I confirmed it against a local build of main.

The only request this PR still changes is a series download without a device ID, such as the legacy v1 POST /api/v1/downloads call. No current client sends that, so it isn't worth a separate change.

🤖 Posted by Claude Code

@rangoDJ rangoDJ closed this Oct 6, 2026
@rangoDJ
rangoDJ deleted the fix/series-download-concurrent-limit-1703 branch November 15, 2026 00:45
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.

[bug] Download series always fails with 429 when the series has more episodes than the concurrent download limit

2 participants