Skip to content

fix(studio): audio meters and audio groups work in a sealed preview - #8011

Merged
miguel-heygen merged 4 commits into
mainfrom
hfsupabase/audio-editing-port
Nov 17, 2026
Merged

miguel-heygen merged 4 commits into
mainfrom
hfsupabase/audio-editing-port

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What

With Studio's preview on an opaque origin (VITE_STUDIO_OPAQUE_PREVIEW_ENABLED), Studio's audio tools work on the preview again:

  • The audio meters move: group strips and Monitor read the preview's level taps.
  • A group fader, mute or FX change is heard in the preview while you drag, and is saved to the file that holds the group.
  • Grouping clips (the track header's group button, or a carve's auto-group) groups them in the preview at once, and puts the preview back if the save fails.
  • The clip menu offers Duck under voice for a music bed.

A same-origin preview, every preview today, takes the same code paths as before.

Why

Each of these read or wrote the preview frame's window or document directly (contentWindow.__hf.audioMeter, contentDocument.getElementById). An opaque frame refuses both, so with the flag on the meters stayed flat, a fader drag changed nothing you could hear until the next reload, and a group living in a sub-composition was saved to the wrong file.

How

Four new kinds on the editing port, each in its own file under core/src/runtime/editing/, appended to the kind list, the request types and the param validators in editingPort.ts and to the frame's dispatch in editingAgent.ts:

  • audio-meter ({ on }): on: true starts the frame's level taps when they are off and returns the current levels; on: false removes the taps. The meter loop keeps one read in flight and asks at most every 33 ms (about 30 reads a second, near the analyser's 2048-sample window), still painting every animation frame from the latest reply. Unmounting, or the loop moving to another frame, sends one on: false.
  • document-markup (no params): the frame's live markup and base URL. Studio's previewDocumentCopy (in previewChannel.ts) parses it into an inert copy (DOMParser: no scripts run, nothing loads) for the reads that need a whole document: which file holds a group, a gesture's value before it starts, a fresh group id, and the clip menu's duck candidates.
  • set-audio-group-attribute ({ id, attr, value }): writes one of a group's own attributes (data-volume, data-hidden, data-label, data-fx-chain, data-automation), only on an <hf-audio-group>. A drag sends at most one write per group attribute at a time; the newest value waits and older ones are dropped.
  • assign-audio-group ({ members, element }): sets or clears data-audio-group on handle-addressed members, adds or removes the group's <hf-audio-group>, and returns each member's previous group for the unwind. Members are found with the existing findOpaqueTimelineElement.

In Studio, each listed reader branches on previewFrameOpaque(iframe); the same-origin branch is the code it had. A sealed fader gesture reads the group from one copy of the frame before its first write, so the value an undo or a failed save goes back to is the one the frame held. invalidateGroupInfoCache keeps its same-origin role; a sealed preview has no Studio-side document to cache, and each copy is read fresh.

The direct same-origin reads stay for now, behind the opaque check, until the opaque preview is the default.

@hyperframes/inspector ships the runtime these kinds add to, which took its unpacked size 1.05% over its budget (3,819,666 of 3,780,000 bytes). Its budget moves to the measured size plus the script's 5% headroom (4,010,650).

Related work

Refs #7846 (the opaque preview by default).

Before

main with VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=1, headless Chrome at 1440x900, a project with two sine-tone audio clips, meters shown, 2.5 s after Play. The preview frame's origin is null. The Monitor meter stays empty (meter-mask height 100% on both bars).

Before: meters flat while playing

After

This branch, same steps: the Monitor meter shows the playing level (meter-mask height 71.4%).

After: meters move while playing

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

fails without the fix: cd packages/studio && vitest run src/components/nle/audioSealedPreview.test.ts -t "meter moves \+ group volume sealed" (the first commit; on main the meter masks stay at 100%).

  • audioSealedPreview.test.ts runs the real editing agent behind an opaque frame: the meters move and stop on unmount, a group fader is heard live and saved to the sub-composition file that holds the group, a group create applies in the frame and unwinds on a failed save, the clip menu offers Duck from a sealed preview, and a fresh group id is minted from the frame's copy.
  • core/src/runtime/editing/audioKinds.test.ts: each kind's param validation and frame-side effect.
  • The existing tests of every changed file pass unchanged, as do editingAgent.test.ts and editingPort.test.ts with the new kinds listed.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

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

COMMENT (hold: needs a rebase) at 44fe8444. The code is clean, but the head is DIRTY against main. #8009 landed restore-attributes in the same places this PR appends to: editingPort.ts (the kinds list and PARAM_PARSERS), editingAgent.ts (HANDLERS), their two test files, and scripts/package-size-budgets.json. The conflicts are adjacent appends, but they're in exactly the code this review covers, so I'll approve the resolved head. Keep restore-attributes alongside the four new kinds, and keep the inspector budget at this PR's 4,010,650 (#8009 set 3,820,000).

What I read here (no blockers):

  • The new port kinds parse strictly.
    • audio-meter takes exactly {on: boolean}.
    • set-audio-group-attribute needs the exact keys attr,id,value, allows only five attribute names and caps the id and value. It only writes to an <hf-audio-group>.
    • assign-audio-group checks exact keys on every level, takes at most 256 members by the existing handle regex, and caps the label.
    • document-markup takes no params.
    • There are no selectors and no eval anywhere.
  • Meter traffic is pulled by Studio. One request is in flight at a time, at most one every 33 ms, and it stops on unmount or a frame change. Replies are checked with Number.isFinite and clamped to 0..1, and only CSS heights are painted.
  • document-markup is parsed with an inert DOMParser. The save path read from it matches the existing sealed previewElementSourceFile, so there's no new trust boundary.
  • Same-origin behaviour is unchanged behind previewFrameOpaque.
  • Tests. Core passes 153/153 and Studio 302/302. With the Studio fix reverted, "meter moves + group volume sealed" fails, with the masks stuck at 100%. Dropping the attribute allowlist or the member bound fails audioKinds.test.ts. CI is green and all three commits are verified.

Nit: the clip menu fetches a full outerHTML copy each time it opens. That's fine now, but worth watching for large inlined compositions.

— Rames

@miguel-heygen
miguel-heygen force-pushed the hfsupabase/audio-editing-port branch from 44fe844 to b4c500c Compare November 17, 2026 04:21

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

APPROVE at b4c500ce. This clears my rebase hold at 44fe8444.

  • The rebase changed nothing in the code. Comparing the PR's own +/- lines against the merge-base before and after the rebase, the only difference is the size-budget "from" value: main's base is now #8009's 3,820,000 instead of 3,780,000. restore-attributes from #8009 sits alongside the four new kinds in EDITING_REQUEST_KINDS, the request types and PARAM_PARSERS.
  • My earlier read stands.
    • The four new port kinds parse strictly: exact keys, a five-attribute allowlist, <hf-audio-group>-only writes, members by handle (≤256), and bounded ids, labels and values.
    • Studio pulls the meter, one request in flight at most every 33 ms. Levels are checked with Number.isFinite and clamped to 0..1.
    • document-markup is parsed with an inert DOMParser.
    • Same-origin paths are unchanged behind previewFrameOpaque.

Nit (unchanged): the clip menu fetches a full outerHTML copy each time it opens.

— Rames

@miguel-heygen
miguel-heygen force-pushed the hfsupabase/audio-editing-port branch from b4c500c to f0aa3fa Compare November 17, 2026 06:26

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

Approved at f0aa3fa. The rebase is clean: the range-diff against b4c500c (Rames's approved head) has commits 1 and 3 identical, and commit 2 differs only in context, with the audio kinds now beside the caption kinds. The four audio param parsers are in the exhaustively typed PARAM_PARSERS, capped by MAX_DESCRIBE_HANDLES, MAX_GROUP_VALUE and MAX_GROUP_ID. There's no new listener, and the fails without the fix: line is present.

Should-fix (Studio-side bounds on frame replies, as on #8002 and #8005):

  1. Markup size: previewDocumentCopy (previewChannel.ts:128) hands frame-sent html and baseURI to DOMParser with no size cap.
  2. Source path: timelineAudioGroupVolume.ts (~203-205) takes targetPath from resolveGroupSourceFile on that copied markup (data-composition-file) and persists through it. The write goes through the project-file API, and the tag must already exist in that file, so it's contained, but check it's a bounded relative project path before persisting.
  3. Meter levels: meterLevels (AudioMeterStrip.tsx:146) caps neither the group count nor the level magnitude.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 17, 2026
@miguel-heygen
miguel-heygen force-pushed the hfsupabase/audio-editing-port branch from f0aa3fa to d0df7e2 Compare November 17, 2026 07:25

@vanceingalls vanceingalls 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-approved at d0df7e2. This is a rebase onto main. Against f0aa3fa, the range-diff shows commit 1 identical and commit 2 differing only in context. In commit 3, only the base value of the inspector's unpacked budget moved (3820000 → 3830000 on main); the PR's own target, 4010650, is unchanged.

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

APPROVE at d0df7e29. This re-stamps my approval at b4c500ce after the rebase onto main past #7999.

  • Same change set: the PR's own sorted +/- lines against main match b4c500ce's (17 files, +903/-51), except one context line: main had moved the inspector unpacked budget from 3820000 to 3830000. The PR still sets it to 4010650, above main's.
  • Merge: the merge tree is clean against main, and all 3 commits are verified.
  • Heads-up: #8050 raises the inspector packed budget on the adjacent line, so whichever lands second will need a one-line merge of that file.

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅
Risk: low.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 17, 2026
@miguel-heygen
miguel-heygen force-pushed the hfsupabase/audio-editing-port branch from d0df7e2 to ec16f4c Compare November 17, 2026 08:07

@vanceingalls vanceingalls 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-approved at ec16f4c. This is a rebase onto main: commits 1 and 2 are identical in the range-diff against d0df7e2, and commit 3 only moves the inspector size budget onto main's new base.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 17, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 17, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 17, 2026
@miguel-heygen
miguel-heygen force-pushed the hfsupabase/audio-editing-port branch from ec16f4c to ab92abc Compare November 17, 2026 10:58

@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-approving at ab92abcf. Our last approval was on d0df7e29.

What changed since d0df7e29

  • Rebase onto main: the test and fix commits are byte-identical to the approved ones. In the size-budget commit, only the packed context line moved, because main changed it. This PR's own change is still unpacked going from 3830000 to 4010650.
  • New commit ab92abcf: two lines in audioSealedPreview.test.ts switch to installMarkedEditingAgent. Main's #8057 now gives the editing port only to pages that carry Studio's preview mark, and this test needs a marked page. Runtime code is unchanged.

Security

  • Gating: the four new message kinds now sit behind #8057's mark gate as well. Reverting ab92abcf fails all 4 sealed tests, which shows the gate is enforced.
  • Parsers: unchanged. They still require exact key sets, an attribute allowlist (setAudioGroupAttribute.ts:7-13), group id ≤ 512, and values ≤ 200000.

Fails without the fix

  • With the fix's non-test changes reverted, meter moves + group volume sealed fails with expected ['100%' x4] to deeply equal ['0%' x4].
  • At the head, core audioKinds/editingAgent/editingPort/restoreAttributes pass 173/173, and audioSealedPreview passes 4/4.

Nits (non-blocking)

  • The -t pattern in the body matches nothing. Vitest reads -t as a regex, so + must be \+. As written, all 4 tests are skipped and the run exits 0.
  • Undo/redo of the new audio attributes reloads the preview. SAFE_TO_SET in restoreAttributes.ts doesn't list data-audio-group, data-audio-fx or data-audio-automation, so undoing or redoing them returns applied: false and Studio reloads the preview instead of applying it in place. That's safe, just slower.

CI: all green at this head.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 17, 2026
@miguel-heygen
miguel-heygen force-pushed the hfsupabase/audio-editing-port branch from ab92abc to 043f5d6 Compare November 17, 2026 12:56
@miguel-heygen
miguel-heygen force-pushed the hfsupabase/audio-editing-port branch from 043f5d6 to 5106da5 Compare November 17, 2026 12:58

@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-approving at 5106da58. My last approval was on ab92abcf.

This head is a rebase only. git range-diff shows commits 1, 3 and 4 byte-identical. Commit 2 differs only in the editing-port lists, where main now carries watch-geometry and no longer has color-grading-status. The PR's own audio-meter, document-markup, set-audio-group-attribute and assign-audio-group lines are unchanged.

All four commits are verified. CI is green at this head. The timeline viewport gate failed once on an unrelated dissolve-colour sample and passed on rerun.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 93a4d29 Nov 17, 2026
149 of 150 checks passed
@miguel-heygen
miguel-heygen deleted the hfsupabase/audio-editing-port branch November 17, 2026 13:46
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