Skip to content

fix(producer): cap a render's total sub-composition expansion - #8045

Merged
michaelwang11394 merged 4 commits into
mainfrom
sec-subcomp-expansion-budget
Nov 17, 2026
Merged

michaelwang11394 merged 4 commits into
mainfrom
sec-subcomp-expansion-budget

Conversation

@michaelwang11394

@michaelwang11394 michaelwang11394 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • assertSubCompositionsUsable re-read, re-parsed and recursed into a file for every host, because its visited set held only the ancestor chain.
  • parseSubCompositions compiled each host instance again, with the same ancestor-only guard.
  • The shared inliner queued every nested host with only the depth limit of 20.

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_LARGE error, and follows #7866 and #7992. The open PR #8034 also touches parseSubCompositions and the inliner's resolveHtml, so whichever merges second needs a small merge.

How

  • compositionSizeLimit.ts gains CompositionExpansionBudget. It charges each mount's bytes and throws the existing COMPOSITION_TOO_LARGE error (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.
  • assertSubCompositionsUsable reads 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.
  • parseSubCompositions shares one set of compiled paths across the recursion. Each path compiles the same wherever it is mounted, so it is compiled once.
  • The producer's inliner wrapper charges each resolveHtml call 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.
  • The pre-flight caches each path's check, and the inliner's disk fallback caches each read, so neither touches the disk once per mount.
  • docs/guides/rendering.mdx describes the new limit.

The pre-flight walk and parseSubCompositions find mounts with querySelectorAll, 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

  • New tests in htmlCompiler.sizeLimit.test.ts: six levels of ten mounts are refused with COMPOSITION_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.
  • All htmlCompiler*.test.ts files pass (vitest and bun lanes), and tsc --noEmit passes for the producer.
  • fallow audit and the comment ratchet pass.
  • Manual testing performed
  • Documentation updated
  • Comments follow CONTRIBUTING.md "Comments"

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

mintlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

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

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Nov 17, 2026, 6:25 AM

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

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

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 eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(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

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

Copy link
Copy Markdown
Contributor Author

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 <template> content, which linkedom's document query does not see. It charges them to the same budget but does not report them as problems, because the inliner still only warns about a broken mount there. A new test checks that a missing mount inside a template still compiles with a warning, as before. Both fan-out tests now assert the error and its mount count (mounts: 10001, exceeded: "mounts") with no wall-clock bound.

Non-blockers

  • Metadata: the error's publicMetadata now has exceeded: "bytes" | "mounts".
  • 32 MB total versus three different 12 MB scenes: I'm keeping the stricter limit for now and have asked Michael on the ticket whether real projects that size exist.
  • The preview bundler still calls the inliner without this budget. Preview runs on the user's own machine for their own project, so I've left it for a follow-up.

All htmlCompiler*.test.ts files pass (58 in the vitest lane, 213 in the bun lane), and producer tsc --noEmit passes.

@eddy-heygen
eddy-heygen dismissed their stale review November 17, 2026 07:18

(Eddy's agent) Superseded by the re-review at afc8a94.

@eddy-heygen eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 17, 2026
michaelwang11394 added a commit that referenced this pull request Nov 17, 2026
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.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 17, 2026
@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit b29e40d Nov 17, 2026
92 checks passed
@michaelwang11394
michaelwang11394 deleted the sec-subcomp-expansion-budget branch November 17, 2026 08:16
meefs pushed a commit to meefs/hyperframes that referenced this pull request Nov 17, 2026
…-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.
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