Skip to content

fix(engine): remote downloads get an absolute deadline and stop before the disk fills - #7827

Merged
michaelwang11394 merged 1 commit into
mainfrom
sec-download-limits-1115
Nov 15, 2026
Merged

michaelwang11394 merged 1 commit into
mainfrom
sec-download-limits-1115

Conversation

@michaelwang11394

@michaelwang11394 michaelwang11394 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Remote media downloads (the <video>, <audio>, image and font URLs a composition names) get three new limits:

  • An absolute deadline per attempt: 30 minutes by default. A retried stall or too-slow attempt starts a new 30 minutes (HYPERFRAMES_MAX_DOWNLOAD_MS). Incoming data never moves it. A download past it fails with a timeout error that is not retried.
  • A lower per-file cap: 8 GiB instead of 20 GiB (HYPERFRAMES_MAX_DOWNLOAD_BYTES, unchanged name).
  • Free-space headroom: a download must leave 512 MiB free on its volume (HYPERFRAMES_DOWNLOAD_MIN_FREE_BYTES; 0 turns the check off). Before the body is read, a download claims its declared size, and the claim counts against every parallel download on the same device. Free space is measured again every 4 MiB received. The error is a non-retryable filesystem error. If free space cannot be measured, the download continues.

Why

Every chunk of a response with a Content-Length re-armed the attempt timeout. The only other limit was a 32 KiB/s throughput floor. So a server that streamed just above that floor with a huge declared length was never stopped by time. Several such URLs downloading in parallel, each allowed up to 20 GiB, could fill the render host's work volume.

Related work

Refs #7786, which added the per-file cap, the compressed-response refusal and the throughput floor.

How

  • runDownloadAttempt starts a second timer that only the end of the attempt clears.
  • DiskHeadroomGuard tracks bytes that in-flight downloads declared but have not received, per device. fetchToPartial claims the declared size before reading and checks headroom as bytes arrive. The attempt releases its claim in finally.
  • The error classification in the catch block now builds one error and emits telemetry once, instead of repeating the telemetry call per branch.
  • docs/packages/engine.mdx lists the four download environment variables and their defaults.

No per-render byte budget was added. It would need a budget object threaded through five producer and engine callers, and the headroom check already covers parallel downloads in one process. Separate render processes on one host see each other's writes when they measure free space again, every 4 MiB.

Why these defaults: 8 GiB holds about 20 minutes of 4K H.264 at 50 Mbps, or hours of 1080p. Finishing an 8 GiB file in 30 minutes needs about 4.6 MB/s. All three limits can be raised through the environment.

Test plan

  • 3 new tests fail on main and pass now: a server that streams steadily above the throughput floor with a large declared length is stopped by the deadline; a declared size that would cross the free-space minimum is refused before the body is read; and parallel bodies are stopped once their combined claims cross the minimum.

  • The downloader tests (120) passed 3 runs in a row. An existing test that streams for over 15 minutes still passes.

  • Engine unit suite: 3096 pass. The same 15 tests fail on main too (they need ffmpeg and local fixtures).

  • Producer download-related tests: 21 vitest and 308 bun tests pass.

  • Engine tsc, oxlint, oxfmt, fallow and the comment ratchet pass.

  • Unit tests added/updated

  • Manual testing performed (no render run against a slow server)

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments"

…e the disk fills

A download whose response declares a Content-Length re-arms its attempt
timeout on every chunk, so a server that trickles just above the throughput
floor was never cut off by time. Parallel downloads also had no shared limit
on the disk they could fill.

- Each download attempt now has a deadline that incoming data never moves:
  30 minutes by default, HYPERFRAMES_MAX_DOWNLOAD_MS to change it. Passing it
  fails the download without a local retry.
- The default per-file cap drops from 20 GiB to 8 GiB
  (HYPERFRAMES_MAX_DOWNLOAD_BYTES still overrides it).
- Downloads keep 512 MiB free on their volume
  (HYPERFRAMES_DOWNLOAD_MIN_FREE_BYTES, 0 turns it off). A declared size is
  claimed before the body is read and counted against every parallel
  download on the same device, and free space is measured again every 4 MiB
  as bytes arrive. Free space that cannot be measured does not block.
- docs/packages/engine.mdx lists the download limits and their variables.
@mintlify

mintlify Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Nov 15, 2026, 9:47 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. Reviewed at 218fc25cf1105e79ef34555abbf90a02ec37cbca. The deadline can't be reset by incoming data, a deadline abort is non-retryable and removes the partial, and the headroom claim is released on every exit. The three nits below are wording and operator notes, not blockers.

Need: yes, the attempt timer was re-armed by every sized chunk, so a stream just above the floor was never stopped by time · Size: ok · Reuse: integerFromEnv, UrlDownloadError and the existing attempt finally are reused; the catch-block consolidation removes three copies of the telemetry call · Simpler: already minimal · Structure: fine (checked whether the claim belongs in downloadWithRetry instead; per attempt is right because each attempt has its own partial)
Risk: low for the code. The behaviour change is real for operators, since a download that ran 30+ minutes or past 8 GiB now fails without a retry; both are env-tunable and documented.

What I ran

  • urlDownloader* suites in packages/engine: 120 passed.
  • Revert check: I restored urlDownloader.ts from the base. The three new tests fail (both free-space tests and the absolute-deadline test), and the other 117 still pass.
  • Release check: with headroom.release() removed from the finally, the parallel declared-bodies test fails. Claims leaked by earlier tests on the same device push it over the minimum, so the release is covered too.
  • Read-through of the accounting:
    • claim and its measurement run synchronously, so parallel downloads in one process can't both pass on the same free space.
    • Bytes count as received when the chunk arrives, slightly before they reach the disk. That gap is a stream buffer, which is negligible.
    • Undeclared bodies claim 0 and rely on the re-measure every 4 MiB, so N parallel downloads can overshoot the minimum by at most about N x 4 MiB.

Nits (non-blocking)

  1. The claims are per process. unreceivedBytesByDevice is module state. Two render processes on one host don't see each other's claims; each sees the other's writes only when it re-measures free space. The PR body says the check "covers parallel downloads and parallel renders on one host", and the docs say it "counts the declared sizes of all downloads running at the same time". Both read as host-wide. Suggest "in this process" in the docs line.
  2. The deadline is per attempt. A retryable stall or a too-slow abort at minute 29 starts attempt 2 with a fresh 30 minutes. A download can therefore run about an hour wall-clock. The docs row calls it "Longest download, however fast data arrives". The PR body says "per attempt" correctly; the docs row could too.
  3. 512 MiB is below many hosts' own low-disk thresholds. On a container host that evicts workloads at a percentage of free disk, eviction fires long before 512 MiB is left. A short docs sentence could tell operators of shared hosts to set HYPERFRAMES_DOWNLOAD_MIN_FREE_BYTES above that threshold.

— Rames

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 111 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

Unstable (1)

  • seqplainkeys-none-pct-r0-nested-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo false, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@michaelwang11394

Copy link
Copy Markdown
Contributor Author

Thanks, Rames. I fixed the PR description for nits 1 and 2 (claims are per process, and the deadline is per attempt). To keep your approval, I did not push to this branch. The docs wording for all three nits goes into a small follow-up PR, which I will open after this merges.

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit e104365 Nov 15, 2026
140 checks passed
@michaelwang11394
michaelwang11394 deleted the sec-download-limits-1115 branch November 15, 2026 17:46
daedal-ping Bot pushed a commit to DaedalGames/hyperframes that referenced this pull request Nov 15, 2026
* chore: release v0.9.54

* chore: release v0.9.54 notes include heygen-com#7827, heygen-com#7825, heygen-com#7845, heygen-com#7848 and heygen-com#7849

* chore: release v0.9.54 notes include heygen-com#7853

* chore: release v0.9.54 notes include heygen-com#7851 and heygen-com#7855

This branch was successfully deployed

1 active deployment
staging - docs — 218fc25c Deployed Nov 15, 2026 by mintlify[bot]
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.

2 participants