Skip to content

fix(cli): cloud render sends one zip when it fits and uploads only the largest media - #7859

Merged
jrusso1020 merged 4 commits into
mainfrom
fix/cli-cloud-small-media-uploads
Nov 15, 2026
Merged

jrusso1020 merged 4 commits into
mainfrom
fix/cli-cloud-small-media-uploads

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What

cloud render no longer refuses a project cut from many short clips. When the files the film uses fit under the 200 MB upload limit, they go as one zip with no per-file uploads. When they do not, media nothing names is left out first, then the largest media files the film uses go up as HeyGen assets, eight at a time, just enough for the rest to fit. A project that fits is sent whole, so frames a script loads by a built path ("frames/frame_" + i + ".png") still reach the render.

Why

Only media of 5 MB or more ever left the zip. A project of 176 clips, stills and sounds of 3 to 10 MB each kept about 229 MB of them in the zip and was refused with "Project too large for cloud render", even though nothing in it was large. The person was then asked to move files to HeyGen assets by hand.

Timed on a dev account from a Linux box, uploads only, no render:

60 files of 4 MB seconds
one at a time (today) 63.3
four at a time 15.6, 16.5, 16.6
eight at a time 10.3, 8.7, 8.7
the same 240 MB as one zip 5.5

Each upload costs about a second of requests whatever its size, so one zip is the fastest path and only what does not fit should leave it. On that 176-file project's shape (its file names and sizes, every media file played by the page):

export uploads zip total
today: media of 5 MB or more 2 229 MB refused
every used media file, eight at a time 176 under 1 MB 26.6 s
this PR: largest first, until the zip fits 12, in 2.5 s 187 MB, sent in 4.6 s 11.1 s
this PR, exporting again 0 (12 reused) 187 MB 8.9 s

Totals include building the zip.

Related work

None.

How

  • offloadHeavyMedia takes zipBudgetBytes. Only while the zip is over it: media no page, script or variable names leaves first, largest first; then used media uploads, largest first, counting the staged bytes each one takes out of the zip. cloud render passes 95% of the upload limit, which leaves room for the zip's own records. Without a budget, every used media file goes up, as the tests use it.
  • Unused media used to leave the zip only at 5 MB or more. It now leaves only when the zip is over budget, because "unused" is a guess: a path a script builds at run time is not a mention.
  • The 5 MB floor no longer decides what uploads. It still decides which staged files stay on disk instead of in memory, and when an entry GIF becomes a video first.
  • Uploads run eight at a time through runWithConcurrencyLimit. Each upload keeps its own retries. Two files with the same bytes share one upload. After the first failure the helper starts nothing new and rejects only once the started work has finished, so offloadHeavyMedia never deletes a temp copy an upload is still reading. Its other callers (lambda batch render, snapshot, the registry resolver) get the same guarantee.
  • A trim plan reads the entry page after its probe returns, so two files planned at once cannot lose each other's rewrite.
  • The cloud deploy and CLI docs say the new rule.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

New tests, red on main and green on this branch (3 runs in a row, Linux):

  • offload.test.ts: "with no zip budget, uploads every media file a page uses whatever its size, and leaves unused media out"; "uploads up to eight files at once"; "uploads two files with the same bytes once when both start together"; "with a zip budget › uploads nothing and keeps every file when the zip fits"; "with a zip budget › uploads the largest files first, only until the rest fits"; "with a zip budget › keeps frames a script loads by a built path when the zip fits" (red on the first head of this PR too: only index.html was left).
  • render-batch.test.ts: "after a rejection starts nothing new and settles only once started work has finished".

Existing tests that pinned the old 5 MB floor now say it as a budget: four pass a 1 MiB budget, so their tiny stand-ins stay in the zip as before. One compares the asset ids as a set, since uploads run together. offload.test.ts: 48 of 48 pass. render-batch.test.ts: 16 of 16 pass.

Every other test that reads a changed file passes: all of commands/cloud/*.test.ts (one dry-run test now says the new rule: a project that fits keeps its clip in the zip, plans no uploads and leaves an unused take out; 3 runs) and registry/resolver.test.ts (23 of 23). oxfmt and oxlint are clean on the changed files. The CLI typecheck shows no error in them; the box's checkout lacks a built @hyperframes/inspector, so three unrelated files fail there, and CI runs the full typecheck.

fails without the fix: the new offload tests and the new concurrency test, above. fallow audit against the merge base passes on the devbox; its two remaining CRAP findings (planFile, prepareLocalArchive) are on main already, and planFile's went down (79.4 to 71.3).

@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, 7:51 PM

💡 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.

Request changes at 41ce7e87. Uploading largest-first until the zip fits is the right idea, and the concurrency helper's settle-before-reject change is sound. But one part of the change drops media that a render needs.

Blocking: small media named by a script-built path is now left out of the zip, even when everything fits.

dropUnusedMedia now removes any unreferenced media file, where the old dropUnusedHeavyFiles only removed files of 5 MB or more. It runs before the budget loop and doesn't depend on the budget. "Unused" is decided by static references (referencedFiles) plus isStillMentioned. isStillMentioned only matches a whole file stem between quotes or slashes, so a path a script assembles at run time doesn't count as a mention. Image sequences are the obvious case: "frames/frame_" + i + ".png".

Probe (vitest, real buildPublishFileMap plus offloadHeavyMedia, no upload): index.html has a script that loads frames/frame_${i}.png for i = 1–3, and the three PNGs are a few bytes each.

  • At this head (with a 190 MB budget, or none): the file map afterwards is ["index.html"]. All three frames are gone from the zip, so the cloud render can't load them.
  • With main's offload.ts/concurrency.ts: the file map keeps frames/frame_1.png … frame_3.png.

That conflicts with the description ("When the files the film uses fit under the 200 MB upload limit, they go as one zip"). A project that fit and rendered before can now render with missing frames. Possible fixes:

  • Keep the old 5 MB floor for dropping unreferenced media.
  • Drop unreferenced media only while the zip is over budget, largest first, the same way as uploads.
  • Never drop media that a script could be loading, e.g. when its folder or stem prefix appears in script code.

Whichever you pick, please add a test with a script-built path that stays in the zip when it fits.

CI

  • Comments fails: the comment share rose in cloud/offload.ts (57 → 66 lines) and commands/cloud/render.ts (96 → 97).
  • Fallow audit fails. Its log wasn't available yet while the run was in progress.

Non-blocking

  • left -= item.size_bytes: if size_bytes is the uploaded size after a trim or re-encode, it's smaller than the staged bytes that left the zip, so left stays high. That can upload a file or two more than needed. It's conservative, so it isn't wrong, but subtracting the staged size would be exact.
  • Now that the budget loop exists, the no-budget path ("every used media file goes up") has no production caller. Only cloud render calls offloadHeavyMedia, and it always passes a budget. You could make the budget required.

Need: real (projects of many mid-size files were refused) · Size: ok · Reuse: runWithConcurrencyLimit, extended with a safer failure mode · Simpler: fine · Structure: fine
Risk: medium as posted. Renders silently lose media a script loads. Low once unused-media dropping is scoped back.

— Rames

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 109 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

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Thanks, the frame-sequence case was real. Fixed at c4e7e1a2.

Blocking: unused media dropped when the zip fits. I took your second option. Unused media now leaves the zip only while the zip is over budget, largest first, before any upload (dropUnusedMediaWhileOver). A project that fits goes whole, so a path a script builds at run time still reaches the render.

  • New test "with a zip budget › keeps frames a script loads by a built path when the zip fits" is your probe: frames/frame_${i}.png for i = 1 to 3, a 190 MB budget. On 41ce7e87 it fails with only index.html left; at this head the three frames stay.
  • "uploads nothing and keeps every file when the zip fits" now keeps the unused take too. A new test, "leaves unused media out before uploading anything", covers the over-budget case.
  • The dry-run test in render.test.ts now expects the unused take in the archive.

CI.

  • Comments: both files' comment share is now below the base. The rewrite is in names: uploadsInFlightByKey, entryHtmlAfterOthersPlanned, ZIP_BUDGET_BYTES_WITH_ROOM_FOR_ZIP_RECORDS.
  • Fallow: offloadHeavyMedia is split into dropUnusedMediaWhileOver and uploadLargestWhileOver, so its cognitive complexity finding is gone. fallow audit against the merge base passes on a Linux box. The two CRAP findings it still lists are inherited from main (introduced: false): planFile went from 79.4 to 71.3, and prepareLocalArchive is unchanged at 31.6.

Non-blocking.

  • left now subtracts the staged size of the file that left the zip, so a trimmed or re-encoded upload no longer makes it upload one more.
  • I kept the budget optional. About 45 test calls use "no budget means every used file goes up" to reach the upload paths, and requiring it would add zipBudgetBytes: 0 to each with no behaviour change. The only production caller passes one.

Tests at this head, Linux, offload.test.ts 48 of 48, 3 runs in a row; offload.undecodableTrack.test.ts, every commands/cloud/render*.test.ts, render-batch.test.ts and registry/resolver.test.ts pass.

@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.

Re-review at c4e7e1a2. My earlier blocker is fixed, but one new test in this PR is flaky, so I'm requesting changes for that one item.

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅ · Structure ✅ · Risk: low (one test to make deterministic)

Resolved: unused media left the zip regardless of the budget. dropUnusedMediaWhileOver now drops unused media largest first, and only while the zip is over zipBudgetBytes. With no budget it is 0, so all unused media still goes, as before. uploadLargestWhileOver starts from the size that's left after that. Two new tests cover it: "keeps frames a script loads by a built path when the zip fits", which is my earlier probe, and "uploads nothing and keeps every file when the zip fits". Both are red against the old dropUnusedMedia, because nothing in the page's text names frame_1.png, so the frames counted as unused and were dropped whatever the budget. Subtracting stagedSize(batch[index]) rather than item.size_bytes is also right: the staged size is what actually leaves the zip. Comments and Fallow audit are green at this head.

Blocking: offload.test.ts › "uploads up to eight files at once" is flaky. The Flake gate failed it in 2 of 10 runs at this head, both times with expected 7 to be 8 (run 43754689971). Each worker does async work (hashing and the cache lookup) before it calls upload, and the fake upload resolves after a fixed 20 ms. So the first upload can finish before the eighth worker reaches upload, and the peak is 7. On main this would fail about one CLI unit run in five. Suggested fix: hold the fake uploads until 8 are in flight, then release them, instead of using a timer. For example, park each call on a promise, and when inFlight reaches 8 (or every remaining file has started), resolve the parked calls. Then peak === 8 is exact, and a regression to fewer than 8 at once fails the run every time instead of 20% of the time.

— Rames

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at 1ccbb7a6, as you suggested. The fake upload no longer resolves on a timer. Each call parks on a promise, and the parked calls are released once 8 are in flight or every file has started. So the peak is 8 exactly when the limit is 8, and a lower limit never reaches 8 and fails the test every time.

On a Linux box: the test passes 30 runs in a row. With OFFLOAD_CONCURRENCY cut to 7 it fails 3 runs of 3 (the uploads never reach 8, so they stay parked until the test's timeout). offload.test.ts is 48 of 48 at this head.

@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.

Re-review at 1ccbb7a (test-only change since c4e7e1a).

The flake is gone, because parking uploads until eight are in flight makes reaching 8 deterministic. But the test no longer checks the upper bound its name promises ("uploads up to eight files at once"). The parked uploads are released in the same tick the eighth one starts, so they finish before a ninth worker gets past its own hashing and cache read and calls upload. Results with OFFLOAD_CONCURRENCY changed locally, 5 runs each:

limit result
7 fails 5/5 (never reaches 8)
8 passes 5/5
9 passes 5/5
12 passes 5/5

So raising or dropping the cap would no longer be caught. The 20 ms timer version did catch that, since all workers started inside the window.

Suggested fix: keep the barrier, but hold the eight a moment before releasing them. A correct limit can never exceed 8 however long they wait, so the hold cannot flake, and an over-limit worker has time to start and raise peak:

      if (inFlight === 8 || started === clips.length) {
        const release = parked;
        parked = [];
        // Held a moment first: an upload past the eighth would start now and raise the peak.
        setTimeout(() => release.forEach((go) => go()), 50);
      }

With that change locally: limit 8 passes 10/10, limit 9 fails 3/3, limit 12 fails 3/3. The rest of offload.test.ts passes (48/48).

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅ · Structure ❌ (the cap test passes at any limit ≥ 8) · Risk: low once the hold is in

— Rames

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Taken as you suggested, at b4d3437c: the parked uploads are held 50 ms before they are released, so an upload past the eighth starts and raises the peak.

On a Linux box: limit 8 passes 30 runs of 30. With OFFLOAD_CONCURRENCY at 7, 9 and 12 it fails 3 runs of 3 each. offload.test.ts is 48 of 48 at this head.

@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.

Re-review at b4d3437c: my upper-bound finding from 1ccbb7a6 is resolved.

What changed: the only change since 1ccbb7a6 is offload.test.ts (+4/−2). Once eight uploads are parked, they are released after a 50 ms hold. With a cap above eight, a ninth upload starts during that hold and raises the peak, so the test now fails at a cap that is too high.

Verified: I measured this exact change on the previous head:

  • cap 8: passes 10/10;
  • caps 9 and 12: fail 3/3 each.

Cap 7 fails by construction: the peak never reaches eight, and the release on the last start leaves peak at 7. All 70 checks on this head pass, including the repeat gate that caught the earlier flake.

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅ · Structure ✅
Risk: low (test-only delta).

— Rames

@jrusso1020
jrusso1020 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 9bc2b23 Nov 15, 2026
86 checks passed
@jrusso1020
jrusso1020 deleted the fix/cli-cloud-small-media-uploads branch November 15, 2026 21:40
timothybrush pushed a commit to timothybrush/hyperframes that referenced this pull request Nov 15, 2026
* chore: release v0.9.55

* chore: release v0.9.55 notes include heygen-com#7830

* chore: release v0.9.55 notes include heygen-com#7859 and heygen-com#7867

* chore: release v0.9.55 notes name the docs change and cloud render

* chore: release v0.9.55 notes include heygen-com#7866 and heygen-com#7801

* chore: release v0.9.55 notes match the style bar
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