Skip to content

fix(producer): materialize runtime blob and inline data audio during probe - #8932

Merged
miguel-heygen merged 3 commits into
mainfrom
fix/materialize-runtime-blob-audio
Nov 26, 2026
Merged

miguel-heygen merged 3 commits into
mainfrom
fix/materialize-runtime-blob-audio

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What changed

Compositions whose scripts synthesize or load audio into browser blob: URLs (via URL.createObjectURL) or embed inline data: audio URIs play in preview, but failed during render because audioMixer only reads local files and http(s) URLs and tried to resolve blob: / data: strings as paths inside the project folder.

  • Added packages/producer/src/services/render/stages/runtimeAudio.ts to materialize same-origin blob: audio URLs from the live probe page and inline data: audio URIs into compiled/__hf_runtime_audio/<sha256>.<ext> (inside compiledDir, so both local and distributed renders read and clean them up through existing asset roots).
  • Enforced strict same-origin checking for blob: URLs, per-clip (64 MiB) and total (128 MiB) byte caps, strict base64/data-URI validation, and content-hash deduplication. Failed, cross-origin, empty, or oversized sources log a warning and stay unchanged so audio mixing fails closed rather than silently dropping tracks.
  • Updated hasRuntimeMediaChanges in packages/producer/src/services/render/stages/probeStage.ts to probe pages that both contain media elements and call createObjectURL(, even when the element is populated through a helper function whose selector cannot be resolved statically.
  • Wired materializeBlobAudioSources (while the probe page is live) and materializeDataAudioSources (for both static and probed renders, ahead of dropMediaOutsideProject and preflightCompositionAssetMediaTypes) in probeStage.ts.

Verification

  • fails without the fix:
    • packages/producer/src/services/render/stages/probeStage.test.ts:
      • probes when a script calls createObjectURL on a page with media elements
      • materializes same-origin blob audio from the probe page into compiledDir and deduplicates shared blobs
      • materializes inline data: audio even when no browser probe runs
    • All three failed on origin/main before the fix and pass 3/3 runs with the fix.
  • packages/producer/src/services/render/stages/runtimeAudio.test.ts: unit tests covering same-origin vs cross-origin blob: handling, MIME extension mapping, byte limits, revoked blobs, base64 and percent-encoded data: URIs, deduplication, and invalid input refusal (3/3 runs pass under --preload ./scripts/no-network.mjs).
  • packages/producer/src/services/render/stages/runtimeAudio.integration.test.ts (registered in packages/producer/scripts/integration-tests.json): end-to-end test proving a real PCM WAV data: URI materializes into compiled/__hf_runtime_audio/, passes dropMediaOutsideProject and FFprobe preflightCompositionAssetMediaTypes, and mixes into a real audio.m4a via runAudioStage with FFmpeg (3/3 runs pass).
  • Sibling tests: packages/producer/src/services/assetMediaType.test.ts (31/31) and packages/producer/src/services/render/stages/audioStage.test.ts (18/18) pass.
  • test:classification, tsc --noEmit, oxlint, oxfmt --check, and fallow health (100 A, 0 dead exports, 0 complexity findings) all 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.

Reviewed at c3bfa88. No blocker; approving.

Read in full: runtimeAudio.ts, the probeStage.ts change with the surrounding media discovery and preflight code, the three new probeStage.test.ts cases, and runtimeAudio.integration.test.ts. Skimmed runtimeAudio.test.ts (case names and assertions). Review by reading; I did not run the tests. CI was still in progress when I posted (24 green, 34 running, none failed).

What I checked

  • A blob URL is read only when it starts with the file server's own origin; anything else is logged and left as it was, so the mix still fails loudly instead of dropping a track.
  • Per-clip and total byte caps apply before decode (length check on the base64 text) and after; the cache is filled only after a successful write, so a refused source is never reused.
  • The blob read runs while the probe page is open and before the audio volume step; the data URI pass runs for static renders too, ahead of dropMediaOutsideProject and the media type preflight, so a written file still goes through both.
  • Files land in compiled/__hf_runtime_audio/<hash>.<ext> and the integration test resolves that path through the real asset-root check, FFprobe preflight and the audio stage.
  • "fails without the fix:" names three tests in probeStage.test.ts; all three exist at this head and assert the new behavior (probe trigger, blob written once for two clips, data URI written with no probe).

Notes, none blocking

  1. decodePercentWithin goes through decodeURIComponent and UTF-8, so a percent-encoded payload with raw binary bytes that are not valid UTF-8 is refused. Base64 is the common form, and the refusal warns and leaves the source, so this is a limit and not a wrong output. A byte-wise percent decode would lift it.
  2. The blob path is tested with a mocked page.evaluate; the in-page fetch + FileReader code itself is not run by any test here. The integration test covers the data URI path only.
  3. createObjectURL( anywhere in an inline script now starts a probe on any page with managed media, also when the object URL is for an image or a download. Cost only, no wrong result.
  4. An unknown or missing MIME type gives a .bin file; whether FFmpeg reads it then depends on content sniffing. Fine as a fallback.

Need: yes, preview and export disagreed · Size: fits, 272 lines of code and the rest tests · Reuse: uses the existing compiled dir and asset roots · Simpler: no · Structure: one new module, two call sites
Risk: low; new work only happens for blob or data audio sources, and every refusal leaves the old behavior.

— Rames

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 62 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

Unstable (2)

  • seqrepeat-none-center-r0-root-z100: 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 / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true
  • seqab-none-pct-r0-root-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

5fadc5b raises the @hyperframes/producer unpacked size budget in scripts/package-size-budgets.json from 3740484 to 3800000 bytes (actual 3785897 bytes) to cover the new runtimeAudio.ts helper and its declarations.

@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-reviewed at 5fadc5b (approved before at c3bfa88). No blocker; approving.

One commit since my last review. Comparing the full diff at both heads, the only difference is scripts/package-size-budgets.json: the producer's unpacked budget goes from 3740484 to 3800000 bytes (about 60 KB of room). The packed budget and all code and tests are unchanged, so my earlier review and its four notes stand as written.

Not checked: the measured unpacked size at this head (I did not build the package), so I cannot say how much of the new room the change uses.

Need: yes, the new module pushed past the old budget · Size: one line · Reuse: n/a · Simpler: no · Structure: n/a
Risk: low.

— Rames

@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-reviewed at f8f9e17 (approved before at 5fadc5b). No blocker; approving.

One commit since my last review. Comparing the full diff at both heads, the only difference is in writeRuntimeAudio in runtimeAudio.ts: the existsSync check followed by writeFileSync becomes a single writeFileSync(target, bytes, { flag: "wx" }), with EEXIST swallowed and any other error rethrown. The unused existsSync import is dropped. Behavior is the same for the normal case (a file with the same content hash is kept, not rewritten) and the gap between check and write is gone. Tests and the size budget line are unchanged; my earlier notes stand.

Same as before and not a blocker: a file left half written by an interrupted earlier run in the same work dir would be kept, since the name already exists.

Need: yes, clears the check-then-write pattern · Size: 5 lines · Reuse: n/a · Simpler: no · Structure: n/a
Risk: low.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit c7b6c71 Nov 26, 2026
97 checks passed
@miguel-heygen
miguel-heygen deleted the fix/materialize-runtime-blob-audio branch November 26, 2026 21:07
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.

3 participants