Skip to content

Commit 7855bbd

Browse files
committed
fix(cli): cloud render handles media over 2 GiB and explains a too-large upload
Media of 5 MB or more stays on disk until it is used: it is hashed and uploaded as a stream, and a file edited after staging stops the run instead of caching the wrong upload. Files left in the zip are sized before any is read, so a 4 GB file reports "too large" instead of crashing. The asset API rejects an over-limit upload as invalid_parameter with "File too large"; that now gets the dry-run hint instead of the --help one.
1 parent 65d3869 commit 7855bbd

10 files changed

Lines changed: 494 additions & 95 deletions

File tree

‎docs/deploy/cloud.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ hyperframes cloud render --resolution 4k
5959

6060
## Check what will upload
6161

62-
Media files of 5 MB or more that the project names by path upload as HeyGen assets and are referenced by public, unsigned URL, so large footage and audio do not count against the 200 MB project archive limit. Uploads are cached, so re-rendering uploads only new or changed media. Inspect what will upload before starting a render:
62+
Media files of 5 MB or more that the project names by path upload as HeyGen assets and are referenced by public, unsigned URL, so large footage and audio do not count against the 200 MB project archive limit. Uploads are cached, so re-rendering uploads only new or changed media. Media is streamed from disk as it uploads, so a large file never has to fit in memory; editing one while the command is preparing it stops the run. Inspect what will upload before starting a render:
6363

6464
```bash
6565
hyperframes cloud render --dry-run

‎packages/cli/src/cloud/errors.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ describe("cloud/errors reportApiError", () => {
5353
);
5454
});
5555

56+
it("points an upload the server refuses as too large to dry-run, not to --help", () => {
57+
const err = new HyperframesApiError({
58+
status: 400,
59+
message: "File too large. Maximum is 200 MiB.",
60+
code: "invalid_parameter",
61+
});
62+
expect(() => reportApiError("Upload failed", err)).toThrow(CliRuntimeError);
63+
expect(errorBox).toHaveBeenCalledWith(
64+
"Upload failed (HTTP 400)",
65+
"File too large. Maximum is 200 MiB.",
66+
expect.stringContaining("hyperframes cloud render --dry-run"),
67+
);
68+
});
69+
5670
it("prefers the code-specific hint over a caller suggestion", () => {
5771
const err = new HyperframesApiError({
5872
status: 400,

‎packages/cli/src/cloud/errors.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ const ERROR_CODE_HINTS: Record<string, string> = {
3030
rate_limit_exceeded: "Retry after the duration in the Retry-After header.",
3131
};
3232

33+
// The asset upload API reports an over-limit file as invalid_parameter; only its message says why.
34+
function hintCode(err: HyperframesApiError): string | undefined {
35+
if (err.code === "invalid_parameter" && /^File too large\b/.test(err.message)) {
36+
return "hyperframes_project_too_large";
37+
}
38+
return err.code;
39+
}
40+
3341
/**
3442
* Print an errorBox and `process.exit(1)` for any unknown error from
3543
* the cloud subverbs. The `stage` is the human-readable name of the
@@ -64,7 +72,8 @@ export function reportApiError(
6472
errorBox("Not found", options.notFound);
6573
failCommand();
6674
}
67-
const hint = err.code ? hints[err.code] : undefined;
75+
const code = hintCode(err);
76+
const hint = code ? hints[code] : undefined;
6877
const title = `${stage} (HTTP ${err.status})`;
6978
// Priority: code-specific hint > caller suggestion > bare code
7079
// label > no third line. Code-specific hints win because they

‎packages/cli/src/cloud/offload.test.ts‎

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import { afterEach, describe, expect, it, vi } from "vitest";
2-
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2+
import {
3+
existsSync,
4+
mkdirSync,
5+
mkdtempSync,
6+
readFileSync,
7+
rmSync,
8+
truncateSync,
9+
utimesSync,
10+
writeFileSync,
11+
} from "node:fs";
312
import { tmpdir } from "node:os";
413
import { dirname, join } from "node:path";
5-
import { buildPublishFileMap } from "../utils/publishProject.js";
14+
import { buildPublishFileMap, stagePublishFiles } from "../utils/publishProject.js";
615
import {
716
type GifPrep,
817
OFFLOAD_MIN_BYTES,
@@ -384,6 +393,72 @@ describe("offloadHeavyMedia", () => {
384393
expect(fileMap.has("logo.gif")).toBe(true);
385394
});
386395

396+
it("hashes and encodes media over 4 GiB from disk, never reading it whole", async () => {
397+
const dir = project({ "index.html": html(`<video src="take.mov"></video>`), "take.mov": "" });
398+
truncateSync(join(dir, "take.mov"), 2 ** 32 + 1);
399+
const fileMap = stagePublishFiles(dir, OFFLOAD_MIN_BYTES);
400+
const run = vi.fn(async () => ({
401+
bytes: Buffer.from("mp4"),
402+
filename: "take.mp4",
403+
contentType: "video/mp4",
404+
}));
405+
406+
const [item] = await offloadHeavyMedia(dir, fileMap, {
407+
apiBaseUrl: "https://api.example",
408+
upload: fakeUpload(),
409+
reencoder: { choose: async () => "video", run },
410+
cachePath: cachePath(),
411+
});
412+
413+
expect(run).toHaveBeenCalledWith(join(dir, "take.mov"), "video", undefined);
414+
expect(item).toMatchObject({ path: "take.mov", action: "reencode", size_bytes: 2 ** 32 + 1 });
415+
expect(fileMap.has("take.mov")).toBe(false);
416+
}, 60_000);
417+
418+
it("uploads media staged on disk as a stream of the file", async () => {
419+
const dir = project({
420+
"index.html": html(`<video src="clip.mp4"></video>`),
421+
"clip.mp4": HEAVY,
422+
});
423+
const upload = fakeUpload();
424+
425+
await offloadHeavyMedia(dir, stagePublishFiles(dir, OFFLOAD_MIN_BYTES), {
426+
apiBaseUrl: "https://api.example",
427+
upload,
428+
cachePath: cachePath(),
429+
});
430+
431+
expect(upload).toHaveBeenCalledWith({
432+
path: join(dir, "clip.mp4"),
433+
size: HEAVY.byteLength,
434+
filename: "clip.mp4",
435+
contentType: "video/mp4",
436+
});
437+
});
438+
439+
it("stops without caching when media staged on disk changes during its encode", async () => {
440+
const dir = project({
441+
"index.html": html(`<audio src="voice.flac"></audio>`),
442+
"voice.flac": HEAVY,
443+
});
444+
const fileMap = stagePublishFiles(dir, OFFLOAD_MIN_BYTES);
445+
const cache = cachePath();
446+
const run = vi.fn(async (sourcePath: string) => {
447+
utimesSync(sourcePath, new Date(), new Date(Date.now() + 5_000));
448+
return { bytes: Buffer.from("wav"), filename: "voice.wav", contentType: "audio/wav" };
449+
});
450+
451+
await expect(
452+
offloadHeavyMedia(dir, fileMap, {
453+
apiBaseUrl: "https://api.example",
454+
upload: fakeUpload(),
455+
reencoder: { choose: async () => "audio", run },
456+
cachePath: cache,
457+
}),
458+
).rejects.toThrow(/changed on disk/);
459+
expect(existsSync(cache)).toBe(false);
460+
});
461+
387462
it("re-encodes the staged bytes, not a file saved on disk after staging", async () => {
388463
const dir = project({
389464
"index.html": html(`<audio src="voice.flac"></audio>`),

0 commit comments

Comments
 (0)