Repository navigation
fix(studio): audio meters and audio groups work in a sealed preview - #8011
Conversation
jrusso1020
left a comment
There was a problem hiding this comment.
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-metertakes exactly{on: boolean}.set-audio-group-attributeneeds the exact keysattr,id,value, allows only five attribute names and caps the id and value. It only writes to an<hf-audio-group>.assign-audio-groupchecks exact keys on every level, takes at most 256 members by the existing handle regex, and caps the label.document-markuptakes 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.isFiniteand clamped to 0..1, and only CSS heights are painted. document-markupis parsed with an inertDOMParser. The save path read from it matches the existing sealedpreviewElementSourceFile, 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
44fe844 to
b4c500c
Compare
jrusso1020
left a comment
There was a problem hiding this comment.
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-attributesfrom #8009 sits alongside the four new kinds inEDITING_REQUEST_KINDS, the request types andPARAM_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.isFiniteand clamped to 0..1. document-markupis parsed with an inertDOMParser.- Same-origin paths are unchanged behind
previewFrameOpaque.
- The four new port kinds parse strictly: exact keys, a five-attribute allowlist,
Nit (unchanged): the clip menu fetches a full outerHTML copy each time it opens.
— Rames
b4c500c to
f0aa3fa
Compare
vanceingalls
left a comment
There was a problem hiding this comment.
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):
- Markup size:
previewDocumentCopy(previewChannel.ts:128) hands frame-senthtmlandbaseURItoDOMParserwith no size cap. - Source path:
timelineAudioGroupVolume.ts(~203-205) takestargetPathfromresolveGroupSourceFileon 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. - Meter levels:
meterLevels(AudioMeterStrip.tsx:146) caps neither the group count nor the level magnitude.
f0aa3fa to
d0df7e2
Compare
jrusso1020
left a comment
There was a problem hiding this comment.
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 inspectorunpackedbudget 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
packedbudget on the adjacent line, so whichever lands second will need a one-line merge of that file.
Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅
Risk: low.
— Rames
d0df7e2 to
ec16f4c
Compare
ec16f4c to
ab92abc
Compare
jrusso1020
left a comment
There was a problem hiding this comment.
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
packedcontext line moved, because main changed it. This PR's own change is stillunpackedgoing from 3830000 to 4010650. - New commit
ab92abcf: two lines inaudioSealedPreview.test.tsswitch toinstallMarkedEditingAgent. 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
ab92abcffails 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 sealedfails withexpected ['100%' x4] to deeply equal ['0%' x4]. - At the head, core
audioKinds/editingAgent/editingPort/restoreAttributespass 173/173, andaudioSealedPreviewpasses 4/4.
Nits (non-blocking)
- The
-tpattern in the body matches nothing. Vitest reads-tas 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_SETinrestoreAttributes.tsdoesn't listdata-audio-group,data-audio-fxordata-audio-automation, so undoing or redoing them returnsapplied: falseand Studio reloads the preview instead of applying it in place. That's safe, just slower.
CI: all green at this head.
— Rames
ab92abc to
043f5d6
Compare
…dio editing kinds
…s the editing port now requires
043f5d6 to
5106da5
Compare
jrusso1020
left a comment
There was a problem hiding this comment.
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
What
With Studio's preview on an opaque origin (
VITE_STUDIO_OPAQUE_PREVIEW_ENABLED), Studio's audio tools work on the preview again: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 ineditingPort.tsand to the frame's dispatch ineditingAgent.ts:audio-meter({ on }):on: truestarts the frame's level taps when they are off and returns the current levels;on: falseremoves 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 oneon: false.document-markup(no params): the frame's live markup and base URL. Studio'spreviewDocumentCopy(inpreviewChannel.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 clearsdata-audio-groupon 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 existingfindOpaqueTimelineElement.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.invalidateGroupInfoCachekeeps 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/inspectorships 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
mainwithVITE_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 isnull. The Monitor meter stays empty (meter-maskheight100%on both bars).After
This branch, same steps: the Monitor meter shows the playing level (
meter-maskheight71.4%).Test plan
fails without the fix:
cd packages/studio && vitest run src/components/nle/audioSealedPreview.test.ts -t "meter moves \+ group volume sealed"(the first commit; onmainthe meter masks stay at100%).audioSealedPreview.test.tsruns 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.editingAgent.test.tsandeditingPort.test.tswith the new kinds listed.