Skip to content

fix(core): retire worklet processors, retry failed registration, reuse FFT scratch - #3175

Merged
vanceingalls merged 510 commits into
mainfrom
wa-19c-worklet-fixes
Aug 13, 2026
Merged

vanceingalls merged 510 commits into
mainfrom
wa-19c-worklet-fixes

Conversation

@vanceingalls

Copy link
Copy Markdown
Collaborator

Worklet lifecycle and one perf fix.

A processor lives until process() returns false, so every chain rebuild that dropped a limiter, compressor, gate or bitcrush left one running on the audio thread for the rest of the session. They are now told to retire on dispose.

Also: a failed worklet registration can be retried rather than poisoning the context, a blank FX parameter no longer reads as zero, the audio failure that took the whole mix down silently is now classified, and the carve's FFT scratch arrays are reused across windows.

🤖 Generated with Claude Code

@miga-heygen miga-heygen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: fix(core): retire worklet processors, retry failed registration, reuse FFT scratch — #3175

Verdict: LGTM

Five fixes, headlined by a worklet lifecycle bug that left processors running on the audio thread forever.

Processor retirement — the core issue: disconnecting an AudioWorkletNode is not enough. process() must return false for the processor to be garbage-collected. All four processors (compressor, limiter, gate, bitcrush) returned true unconditionally, so every chain rebuild that dropped a worklet effect left it running. After a few edits to a carved bed, you'd accumulate a stack of them, each still answering data-fx-chain edits by rebuilding a whole graph around a dead source.

The fix is simple and correct: { __hfDispose: true } message, this.dead = true, process() returns false. The test in audioFxWorklets.test.ts is creative — it loads the actual base64-encoded module source, evaluates it with a mock AudioWorkletProcessor base class, and tests each processor directly: keeps running before dispose, retires after, stays retired even after a later parameter update. This is the right level of test — it proves the actual processor code that runs on the audio thread, not a mock of it.

Registration retry — the rejected promise stayed in registered, so every later ensureAudioFxWorklets replayed the same rejection. One transient failure (slow module load, context still warming up) permanently disabled half the rack. The .catch now deletes from registered and re-throws. readyContexts.add(ctx) only runs on success, so callers correctly keep asking.

Blank FX param — Number(null), Number(""), Number(false), Number([]) are all 0 and all pass Number.isFinite, so a missing or blanked value clamped to 0 instead of falling back to the declared default. A compressor whose threshold arrived as null sat at 0 dB and never engaged, silently. The fix: only parse strings that actually spell a number. Tests cover all the blank variants plus the string-number case ("-30" → -30).

Classified audio failure — audioStage.ts now synthesizes an audioFailures array for fatal errors (stage "internal", owner "system", retryable false, detail bounded to 2000 chars). Previously undefined, so the warning policy described a FATAL failure with less classification than a single dropped track gets.

FFT scratch reuse — moves re/im Float64Array allocation outside the hop loop. ~7000 hops for a 5-minute clip was ~460 MB of transient allocation. re is fully overwritten each window; only im needs clearing (im.fill(0)) since the FFT writes into it. The test verifies identical results for short (0.5s, few windows) and long (12s, many windows) clips with the same steady tone, plus a dynamics envelope flatness check to catch contamination between windows.

No issues found.


Review by Miga

🤖 Generated with Claude Code

vanceingalls and others added 25 commits August 13, 2026 01:30
* feat(core): carve against every voice over a bed, always dynamically

A bed usually runs under a whole sequence — a narrator, an interview answer, a
second presenter — and carving against one of them left the others fighting it.
`source` becomes `sources`, and `mixCarveSources` sums every voice onto the BED's
clock before anything is measured. That is what keeps one analysis sufficient: the
chain is fixed, so there is no per-voice filter to switch between, and bands drawn
from all the speech there is with envelopes that rise wherever any of it happens
answer the actual question — where and when is speech masking this bed.

Summed rather than averaged: two people talking at once mask more than either
alone. Audio before the bed starts is dropped rather than folded in at zero, since
it plays over nothing and shifting it would put a cut where there is no voice.

`dynamic` is gone. A fixed depth thins the bed through every pause, and once both
have been heard there is no reason to want it, so every carve follows the speech.

Two helpers the panel and the headless script now share instead of each carrying a
copy — two definitions of "what does this name suggest" drift, and then the two
disagree about which track is the voice:

- `classifyAudioName` reads a track's kind from its id and filename together.
  `unknown` is deliberately common: treating an unrecognised name as "not a voice"
  would hide the one track somebody needs to pick.
- `clipsOverlap` keeps out a voice that never plays while the bed does. An unwritten
  duration counts as unbounded, not zero — refusing a clip whose length the
  composition leaves to the media would drop the commonest case there is.

Files written before this still load: a single `source` reads as a one-voice list,
a stored `dynamic` is ignored, and an absent attribute means the defaults whole.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(core): stop \b from missing underscore-separated names, guard clipsOverlap's negative duration

\b treats `_` as a word character, so \bbed\b never matched bed_01,
music_bed_loop, or theme_song, and \bvo\b/\bvox\b/\btts\b had the same gap —
an underscore-separated bed classified as "unknown" and could end up offered
as its own carve source. Replaced the short hints with a boundary that
actually excludes letters and digits on both sides.

clipsOverlap computed end = start + duration without guarding sign, so a
negative duration put end before start — an interval that does not describe
anything, and one specific case showed it silently dropping a real overlap
(a shorter, earlier broken end rejected a clip that genuinely contained the
point). Duration clamps to zero instead: a clip cannot un-play time, and a
zero-length clip at its start is the sane reading of "duration nobody wrote
down as positive."

Review by Miga (PR #3212).

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
#3212 (accidentally squash-merged into this branch instead of main) changed
HfCarveSettings from a single `source` + `dynamic` toggle to a `sources`
list with dynamic mode removed outright — the multi-voice UI consumer that
goes with that shape lands in the very next PR, so this branch was left with
a type that no longer matched its own code.

Minimal port, not the multi-voice redesign that PR does properly: the
"Listen to" picker and analyse() treat sources[0] as the one voice this UI
still understands, and every dynamic-mode branch (the automated envelope
lanes, the toggle, the checkbox) is gone along with the field — a carve is
now always the static value the analysis computes, matching what the type
change made permanent. Test suite trimmed the same way: the automation-lane
and toggle tests covered behavior that no longer exists.
# Conflicts:
#	packages/studio/src/components/editor/propertyPanelAudioFxGroup.test.tsx
#	packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx
#	packages/studio/src/components/editor/propertyPanelFxSection.tsx
# Conflicts:
#	packages/studio/src/components/editor/propertyPanelAudioFxGroup.test.tsx
#	packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx
#	packages/studio/src/components/editor/propertyPanelFxSection.tsx
#	skills-manifest.json
#	skills/hyperframes-audio/SKILL.md
#	skills/hyperframes-audio/references/attributes.md
#	skills/hyperframes-audio/scripts/carve.mjs
Base automatically changed from wa-19b-render-fixes to main August 13, 2026 12:23
# Conflicts:
#	plans/audio-automation-lanes/SPEC.md
#	plans/automation-lanes-shared-rows.md
#	plans/automation-time-selection-design.md
@vanceingalls
vanceingalls merged commit f6cf3b2 into main Aug 13, 2026
58 checks passed
@vanceingalls
vanceingalls deleted the wa-19c-worklet-fixes branch August 13, 2026 12:43
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