Skip to content

fix(compiler): bound composition variable styles and variable media sources - #8144

Merged
vanceingalls merged 3 commits into
mainfrom
11-17-bound_composition_variable_styles
Nov 18, 2026
Merged

vanceingalls merged 3 commits into
mainfrom
11-17-bound_composition_variable_styles

Conversation

@vanceingalls

@vanceingalls vanceingalls commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What

Bounds two places where a composition variable's value could be copied without limit while a render compiles:

  • emitRootCompositionVariableStyles (core) now charges every rule it builds against a size budget and stops as soon as the budget is exceeded, before the <style> is appended. It takes an optional last parameter { chargeBytes }. With none, a core default throws a COMPOSITION_TOO_LARGE error past MAX_COMPOSITION_VARIABLE_STYLE_BYTES (32 MiB). Host data-variable-values are now parsed once per host, not once per declarer.
  • The producer's bindVariableMediaSources refuses a bound value over 8 KiB or holding an ASCII control character (a plain space still binds), leaving src unchanged and logging at debug. Every src it writes is charged.

Why

Many [data-composition-variables] elements under one host with a long data-variable-values each got a rule holding the full value, and many video[data-var-src] elements bound to one value each got a copy of it. Neither was counted, so memory use grew with elements times value length.

Related work

Refs SECOPS-2864. Builds on #8045 and #8094: reuses CompositionExpansionBudget and its typed, user-owned, non-retryable CompositionTooLargeError. No second error type in producer.

How

  • compileForRender creates one CompositionExpansionBudget and passes it to bindVariableMediaSources and inlineSubCompositions (which no longer creates its own). Both emitRootCompositionVariableStyles calls in the producer pass chargeBytes that call budget.chargeGenerated("composition variables", n), including the no-mount path that had no budget before. assertSubCompositionsUsable's preflight budget and compileHtmlFile are unchanged.
  • boundMediaSrc lives in core and is shared with the browser runtime, so it is not edited. The guard sits in the producer around its result.
  • Preview: no studio or CLI change. The preview bundler uses the core default, and a throw there is already caught by the studio server's bundle error handling, which falls back to the disk HTML, so the preview does not hang. I read that handling but did not run the studio against an oversized composition.
  • Emitted CSS is unchanged for normal inputs; the existing core compiler tests pass unmodified.
  • The generated-budget error now names which budget overran: "Composition variable styles add up to ..." or "Variable-bound media sources add up to ...", each with a matching remedy. The mount-file wording is unchanged.
  • A bound media value is trimmed before it is checked and bound, as a browser's URL parser does, so a trailing newline still binds. Only an interior control character or a value over 8 KiB is refused, and the refusal is logged as a warning.

Test plan

  • Core: about 100 declarers under one host holding a 1 MiB value throws COMPOSITION_TOO_LARGE and appends no <style>; a throwing chargeBytes stops emission at the first call.

  • Producer: the no-mount entry with the same markup fails with CompositionTooLargeError (owner: "user", retryable: false, exceeded: "generated", code COMPOSITION_TOO_LARGE through extractSafeRenderErrorCode); about 4,200 video[data-var-src] bound to one value just under 8 KiB fail the same way; an over-8 KiB value or one with a newline leaves src unchanged and a normal URL with a space binds, and one with a trailing newline binds trimmed; a mounted sub-composition whose declarers overrun the budget fails the same way (covers the after-inline wiring).

  • All of the new tests fail on origin/main by a wrong result (no throw, src set) at these sizes, and pass here. Ran htmlBundler.test.ts and src/compiler, src/runtime/applyVariableBindings in core (710 passed), htmlCompiler.sizeLimit.test.ts (19 passed) and htmlCompiler.test.ts (196 passed) in producer; tsc --noEmit clean for core and producer; oxlint and oxfmt clean.

  • Unit tests added/updated

  • Manual testing performed (no end-to-end render and no studio preview run)

  • Documentation updated (if applicable): no docs change, no CLI flag or command changed

  • Comments follow CONTRIBUTING.md "Comments"

Not exercised: the browser-side runtime injection in getVariables.ts (out of scope, it runs in the render's Chrome page), and a real render of an oversized composition through the producer server's error envelope beyond the unit-level code and fields.

🤖 Generated with Claude Code

vanceingalls and others added 3 commits November 17, 2026 22:36
…ources

Charge every compile-time composition-variable rule against a size budget
and stop emitting once it is exceeded. The render compiler shares one
CompositionExpansionBudget between mounts, variable styles and variable
media sources; other callers get a 32 MiB core default. Host
data-variable-values are now parsed once per host instead of once per
declarer. Bound media sources over 8 KiB or holding control characters are
refused, and every src written is charged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… in errors

Bind the trimmed value, as a browser does, so a trailing newline no longer
makes compile-time probing disagree with the runtime; refuse only interior
control characters or values over 8 KiB, and log the refusal as a warning.
The generated-bytes error now says which of variable styles or variable
media sources overran. Adds a with-mount test for the after-inline budget.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…t share down

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 77 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 (0)

Unstable (1)

  • seqab-none-center-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

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

Reviewed at 07e6c4e2b3e62c9b3cc994659fb578fe24b3f0d3.

The producer now carries one generated-output budget through media binding and both variable-style paths (packages/producer/src/services/htmlCompiler.ts:2339,1205,1378). Core charges host, root and declarer rules before retaining them, and a thrown charge prevents the variable stylesheet from being appended (packages/core/src/compiler/htmlBundler.ts:1607–1619). Caching parsed host values by element preserves per-instance ownership.

Validation:

  • Full workspace bun run build: passed.
  • Core htmlBundler + applyVariableBindings: 237 passed.
  • Producer htmlCompiler.sizeLimit: 20 passed; htmlCompiler with its Bun runner: 196 passed.
  • Replacing the core charge function with a no-op makes both new size-budget tests fail (“expected function to throw”). Source restored.
  • Independent adversarial inspection found no blocker. Preview’s disk fallback was inspected, but no oversized live preview or end-to-end render was run.

Nit: rule.length and src.length count UTF-16 units, consistent with existing generated-output accounting, rather than UTF-8 bytes. The limits bound amplification but should not be described as exact serialized-byte ceilings; clarify that convention or align the entire generated counter in a follow-up.

Need: yes, bound variable-driven output growth · Size: ok · Reuse: CompositionExpansionBudget and existing safe media resolver · Simpler: shared charge callback · Structure: fine (checked existing mount accounting and all variable-rule emitters; no extra budget abstraction needed)
Risk: medium — compilation limits can reject unusually large authored inputs.

Verdict: APPROVE
Reasoning: Both previously uncounted output paths now fail within the shared budget, normal compiler coverage passes, and the new tests discriminate disabled charging.

— Rames / hf-review

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