Repository navigation
fix(producer): cap a render's total sub-composition expansion - #8045
Conversation
The 16 MB limit checked each composition file alone, so a few small files that mount each other many times assembled a page far larger, and the pre-flight walk and sub-composition compile redid their work for every mount. The pre-flight walk now reads each file once and charges every mount to one budget: 32 MB of composition HTML across at most 10,000 mounts. Past either limit the render fails with the existing non-retryable COMPOSITION_TOO_LARGE error, before compiling. Sub-composition compilation handles each path once, and the inliner charges each mount to the same budget as it builds the page.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
The pre-flight walk resolved and checked a mount's path on disk for every mount, and the inliner's disk fallback did the same for every mount it inlined. Both now do it once per path, so a refused fan-out costs about half a second instead of several. The test now covers both a fan-out the pre-flight refuses and one inside templates, which only the inliner sees.
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit c00fa7f.
Verdict: changes requested. The blocker below needs to be resolved; comment here when updated and I will re-review and clear this.
The design looks right, and the new commit fixes the cause of the earlier failure. One budget per render is charged for every mount, in bytes and in count, before the expensive work, and each mount path is now checked once. A reviewer agent read the whole change at the previous commit; I read the budget class and this commit.
Blockers
packages/producer/src/services/htmlCompiler.sizeLimit.test.ts: The change's own new test still fails the flake gate at this commit. The case "while inlining, when the mounts sit in templates" failed 1 of 10 runs, at about 5.3 seconds. The assertion inside the test allows 15 seconds, so what it hit looks like the test runner's own per-test time limit, which the test does not raise. Merged as is, it would make the default branch's test job flaky. To resolve: assert on the work done (the mount count in the error) without a wall-clock bound, or raise the per-test time limit to match the assertion; better, make the inlining refusal trip earlier so it does not need seconds.
Non-blockers
- For the owner to decide: the total limit is twice the per-file limit, so a project with three different scenes of 12 MB each, each legal on its own, is now refused. The repository's fixtures are far smaller; if real projects of that size exist, the limit needs raising.
- The preview bundler calls the same inliner without this budget, so only the depth limit applies there.
- The error's metadata does not say which limit tripped when the mount count is the one exceeded; the message text names both.
CI: the unit job passes at this commit; the flake gate fails on the test above. Several other jobs were still running when I looked.
How this was reviewed: a code-review pass and a security-review pass by a reviewer agent at commit dac70fe; I read the budget class, the commit added since and the failing job's log. Nothing was built or run.
…budget The pre-flight walk could not see mounts inside a <template>, so a template-wrapped fan-out was only refused by the inliner, after seconds of work. The walk now charges those mounts to the same budget without reporting them, since the inliner still only warns about a broken one. The refusal now names which limit it passed, and the tests assert the mount count instead of a time.
|
Thanks, the blocker is fixed in afc8a94. Blocker: the template-wrapped fan-out is now refused by the pre-flight in about 4 ms, instead of by the inliner after seconds. The walk now also reads mounts inside Non-blockers
All |
(Eddy's agent) Superseded by the re-review at afc8a94.
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit afc8a94.
Verdict: approved as a partial fix (see what stays open below).
Re-review. I saw the head move and read the one commit since my change request at c00fa7f, which is now dismissed.
- The blocker is resolved. Mounts inside template content are now charged to the budget in the pre-flight walk, so the refusal for both shapes of project happens before compiling, and the test no longer waits for the inliner or asserts on wall time. It asserts on the mount count and on which limit was exceeded.
- The error's metadata now names the limit that tripped, which was one of my notes.
- A new test keeps the old behaviour for a missing mount inside a template: the inliner still skips it with a warning.
For the owner to decide (not a defect), as before: the total limit is twice the per-file limit, so a project with three different scenes of 12 MB each, each legal on its own, is refused.
What stays open: the preview bundler calls the same inliner without this budget, so only the depth limit applies there.
Blockers
None.
CI: every check that runs this change's tests passes at this commit (the producer unit and integration jobs and the flake gate). Two Windows jobs for other packages and one regression shard were still running when I looked.
How this was reviewed: an earlier round was a code-review pass and a security-review pass by a reviewer agent; I read the budget class and the two commits since. Nothing was built or run.
With the sub-composition expansion budget (#8045) on top of the probe pre-check change (#8044), the producer packs to 930,774 bytes. That is over its 921,000 budget by more than the 1% tolerance, so the merge queue's Build step refuses #8045. The growth is the new expansion budget class and pre-flight walk in the compiler.
…-com#8054) With the sub-composition expansion budget (heygen-com#8045) on top of the probe pre-check change (heygen-com#8044), the producer packs to 930,774 bytes. That is over its 921,000 budget by more than the 1% tolerance, so the merge queue's Build step refuses heygen-com#8045. The growth is the new expansion budget class and pre-flight walk in the compiler.
What
A render now has a total budget for sub-composition expansion: at most 32 MB of composition HTML across at most 10,000 mounts. The pre-flight walk and the sub-composition compile also stop redoing their work for every mount.
Why
The 16 MB limit checks each composition file on its own. A few tiny files that each mount the next one ten times assemble a page with millions of copies of the leaf. Before anything was refused, three steps did work for every mount:
assertSubCompositionsUsablere-read, re-parsed and recursed into a file for every host, because itsvisitedset held only the ancestor chain.parseSubCompositionscompiled each host instance again, with the same ancestor-only guard.All of this runs on the render server's main thread. One small upload could hold it for an unbounded time or exhaust its heap. With six levels of ten mounts each, the old code was still in the pre-flight walk after 90 seconds. The new code refuses it in about a second.
Related work
Builds on the per-file size limit and its
COMPOSITION_TOO_LARGEerror, and follows #7866 and #7992. The open PR #8034 also touchesparseSubCompositionsand the inliner'sresolveHtml, so whichever merges second needs a small merge.How
compositionSizeLimit.tsgainsCompositionExpansionBudget. It charges each mount's bytes and throws the existingCOMPOSITION_TOO_LARGEerror (user-owned, not retryable, already on the safe wire list) once the total passes 32 MB or 10,000 mounts. The error names the mount where the budget ran out.assertSubCompositionsUsablereads and checks each file once, keeps the current mount chain in one set for the cycle check, and charges every mount it walks. Work is bounded by the budget plus one read per distinct file. A problem reported for the same path and reason is listed once.parseSubCompositionsshares one set of compiled paths across the recursion. Each path compiles the same wherever it is mounted, so it is compiled once.resolveHtmlcall to a fresh budget. That caps the assembled page as it is built, including compiled output that grew, or a file that changed after the pre-flight.docs/guides/rendering.mdxdescribes the new limit.The pre-flight walk and
parseSubCompositionsfind mounts withquerySelectorAll, which does not look inside a<template>. Before this PR, mounts nested in a template-wrapped sub-composition were never walked or compiled. They still aren't, so the inliner's budget is what refuses that shape.Test plan
htmlCompiler.sizeLimit.test.ts: six levels of ten mounts are refused withCOMPOSITION_TOO_LARGE, as bare fragments by the pre-flight (4 ms) and inside templates by the inliner (about 1.5 s locally); one file a little over 8 MB mounted four times is refused; a scene mounted twice inside a wrapper mounted three times still compiles to six copies.htmlCompiler*.test.tsfiles pass (vitest and bun lanes), andtsc --noEmitpasses for the producer.fallow auditand the comment ratchet pass.