Skip to content

fix(wasm): format JS error paths and guard Tunelet lifecycle - #63

Open
google-labs-stitch[bot] wants to merge 12 commits into
mainfrom
stitch/format-wasm-errors-and-guard-lifecycle-jm1-254c1af5-c0b8-4d32-96a7-89815a3dc096
Open

google-labs-stitch[bot] wants to merge 12 commits into
mainfrom
stitch/format-wasm-errors-and-guard-lifecycle-jm1-254c1af5-c0b8-4d32-96a7-89815a3dc096

Conversation

@google-labs-stitch

@google-labs-stitch google-labs-stitch Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Format dotted configuration and timed-event field paths in src/wasm.rs as camelCase JavaScript property paths (resynthesis.choirDetune, punch.gainDb, resynthesis.correction.flexTune, resynthesis.pitch.minFrequencyHz / resynthesis.pitch.maxFrequencyHz, outputGain) across Int16, Float32 / in-place Float32, and #61 ParameterControl calls without changing native Rust Error, ConfigProblem or EventProblem variants.
  • Preserve #104's Telemetry serializer and #61's ParameterControl decoding in src/wasm.rs, replace internal Rust module and wrapper paths in tsify and stage-event deserialization errors (tunelet::wasm::BlockEvents -> TimedEvent[], tunelet::<module>::<Type> -> <Type>, including ControlActivity from #135), and align Wasm parameter names (sampleRate, maxBlockFrames, maxFrequencyHz) with the camelCase documentation.
  • Preserve TuneletAudioViews (#117), the documented loadTunelet() and initSync() idempotency contract, and #123 file: URL string / cross-realm handling in src/index.ts while guarding pre-initialization defaultConfig() / new Tunelet(...) calls, forwarding all Tunelet members (including controlActivity() from #135 and Float32 methods and pointer getters from #117), making free() and [Symbol.dispose]() idempotent, throwing a clear Error on post-free() method or getter access, and keeping src/index.ts JSDoc clean for #107.
  • Add runtime assertions in scripts/verify-pack.mjs for pre-initialization errors, camelCase Wasm error paths (including #61 ParameterControl events and Float32 / in-place Float32 calls), stripped Rust type paths, idempotent free() / [Symbol.dispose]() calls, and post-disposal errors across getters and methods.

Verification

  • cargo fmt --check
  • cargo rustc --locked --lib --release -- -D warnings
  • RUSTFLAGS="-D warnings" cargo build --locked --release
  • cargo clippy --locked --lib -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps
  • cargo +1.88 build --locked --lib and cargo +1.88 build --locked --lib --target wasm32-unknown-unknown --features wasm
  • cargo package --locked
  • npm run check:wasm
  • npm run verify:pack and npm run verify:pack -- --ignore-scripts

- Store the rejected value in the range and finiteness errors.
- Add an exact size problem for the zero block limit.
- Store both pitch bounds in the unordered frequency error.
- Add the voice index to the harmony interval errors.
- Store the offsets and the frame count in the event errors.
- Add MidiProblem for invalid MIDI bytes and fields.
- Carry MidiProblem in the MIDI errors and event errors.
- Add the buffer name to the buffer length checks.
- Include the rejected rate and block limit in constructor errors.
- Format dotted configuration paths as camelCase in JavaScript errors.
- Replace internal Rust type paths with public TypeScript names.
- Emit clean camelCase TSDoc without raw rustdoc links.
- Reject defaultConfig and Tunelet calls before initialization.
- Reject loadTunelet and initSync calls with a different Wasm source.
- Clear the initialization state after a load error.
- Make free and Symbol.dispose safe to call more than one time.
- Reject method and property calls on a disposed Tunelet instance.
- Document the lifecycle rules in the README.
- Merge the latest commits from main into the feature branch.
- Update the harmony_gain documentation for Rust and TypeScript.
- Merge the latest commits from main into the feature branch.
- Keep the buffer names in the length checks.
- Map the Processor::check_block errors in the Wasm processor.
- Initialize Wasm asynchronously from a Node.js file URL.
- Merge the latest commits from main into the feature branch.
- Keep the Wasm doc comments in src/wasm.rs without self-references.
- Keep the Wasm error translation and the lifecycle guards.
- Merge the latest commits from main into the feature branch.
- Keep the Wasm doc attributes in src/effects/reverb.rs.
- Keep the Wasm doc attributes in src/resynthesis.rs.
@byteland-app

Copy link
Copy Markdown
Contributor

Review: Formatting Wasm error paths as camelCase, cleaning internal type names, and guarding Tunelet lifecycle (idempotent free / Symbol.dispose) solve real pain points. However, this PR bundles invasive breaking changes to Rust Error variants, alters the documented loadTunelet() idempotency contract, and duplicates cfg_attr docs across 10 files. Please split out a non-breaking PR for Wasm error formatting and lightweight lifecycle guards first.

- Merge the latest main branch
- Restore the native Rust Error variants and the shared doc comments
- Format dotted configuration paths as camelCase in Wasm errors
- Replace internal Rust type paths with public TypeScript names
- Keep the documented loadTunelet idempotency contract
- Reject defaultConfig and Tunelet calls before initialization
- Make free and Symbol.dispose safe for duplicate calls
- Reject method and property calls after Tunelet disposal
@google-labs-stitch google-labs-stitch Bot changed the title feat!: format Wasm boundary errors and guard Tunelet lifecycle fix(wasm): format JS error paths and guard Tunelet lifecycle Nov 25, 2026
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed in 55c7ac2 (also synced with main v0.3.3 and updated the PR title to non-breaking fix(wasm)):

  • Restored native Rust Error variants: Reverted all changes to src/error.rs, src/lib.rs, and native validation callers so Error, ConfigProblem, and EventProblem match main with zero breaking API changes.
  • Removed duplicated cfg_attr docs: Restored the shared rustdoc comments across all 10 Rust configuration/event/feedback modules so only src/wasm.rs and src/index.ts are modified against main.
  • Preserved loadTunelet() idempotency: Restored the documented initialization ??= ... contract in src/index.ts (and kept README.md unchanged) so concurrent and subsequent loadTunelet() / initSync() calls reuse the initialized exports regardless of arguments while clearing cached state on failure.
  • Kept Wasm error formatting & lightweight lifecycle guards: Retained camelCase field-path formatting (wasm_error, including ValidatedEvents::new in decode_events), internal Rust type-path cleanup (ts_error / decode_stage), pre-initialization guards on defaultConfig() / new Tunelet(...) (compatible with tunelet/wasm), and a lightweight WeakMap-backed Tunelet wrapper with idempotent free() / [Symbol.dispose]() and post-disposal errors.

@byteland-app

Copy link
Copy Markdown
Contributor

Round 2 review: Approved — shrinking this to a non-breaking Wasm error formatter and Tunelet lifecycle guard in src/index.ts + src/wasm.rs is much cleaner. Please rebase onto updated main after #30, #123, and #135 with two small updates:

  1. Forward controlActivity() (from feat: add control activity queries #135) on the Tunelet wrapper class in src/index.ts (and note we will also need forwarding once feat: expose Float32 buffers in Wasm for in-place audio #117 lands).
  2. In src/index.ts JSDoc, replace '1..=4294967295' with '1 to 4294967295 (inclusive)' so it passes fix(npm): normalize JSDoc comments at the package boundary #107's JSDoc cleanliness checks.

- Merge the latest commits from main into the feature branch.
- Forward controlActivity on the Tunelet class in src/index.ts.
- Replace the Rust range syntax in src/index.ts JSDoc comments.
- Format envelope_key and control_activity errors in src/wasm.rs.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed in ebf58ef (synced onto latest main v0.3.4 with #30, #123, and #135 — note: fast-forward merge commit used because force-push is disabled in this environment):

  1. Forwarded controlActivity(): Added controlActivity(): ControlActivity (and re-exported ControlActivity in the module JSDoc/type imports) on the Tunelet wrapper in src/index.ts (and routed WasmProcessor::control_activity through ts_error and WasmProcessor::formant_envelope's envelope_key check from #30 through wasm_error in src/wasm.rs, while preserving #123's resolveFileUrl handling). Also noted that once #117 lands, its Float32 methods and pointer getters will need forwarding on the Tunelet wrapper as well.
  2. Cleaned JSDoc range syntax for #107: Replaced in 1..=4294967295 with from 1 to 4294967295 (inclusive) in src/index.ts JSDoc and verified dist/index.d.ts and dist/index.js against #107's JSDoc cleanliness checks alongside npm run verify:pack.

@byteland-app

Copy link
Copy Markdown
Contributor

Round 3 review: Approved — non-breaking Wasm error formatting and Tunelet lifecycle guard look great. Please rebase onto updated main after #117 and #107, forwarding the new f32/in-place methods and pointer getters from #117 on the Tunelet wrapper class (and keeping TuneletAudioViews compatible with the wrapped Tunelet).

- Forward the Float32 methods and pointer getters on Tunelet
- Format Float32 Wasm errors with camelCase property paths
- Keep TuneletAudioViews and the normalized JSDoc comments
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed in 6ae58c3 (synced onto latest main 0850e25 including #107, #117, and #45 — fast-forward merge commit used since force-push is disabled in this environment):

  • Forwarded #117 Float32 methods and pointer getters on Tunelet: Added inputF32Ptr, leftF32Ptr, and rightF32Ptr getters and processF32, processMonoF32, processF32InPlace, processMonoF32InPlace, drainF32, drainMonoF32, drainF32InPlace, and drainMonoF32InPlace methods on the Tunelet wrapper in src/index.ts, with disposal checks after free().
  • Preserved TuneletAudioViews compatibility: Kept TuneletAudioViews from #117 bound against the wrapped Tunelet (and structurally compatible with tunelet/wasm's Tunelet since the wrapper uses a module-scoped WeakMap rather than private class fields).
  • Formatted Float32 Wasm errors & verified #107 JSDoc normalization: Routed all Float32 and in-place Float32 process/drain/frame validation calls in src/wasm.rs through wasm_error so config and event paths (including flexTune / humanize from #45) use camelCase, and verified all JSDoc comments across dist/ and pkg/ pass #107's verifyNormalizedJsDoc checks in npm run verify:pack.

@byteland-app

Copy link
Copy Markdown
Contributor

Review: camelCase Wasm error formatting, Rust type-path stripping, and WeakMap-backed Tunelet lifecycle guards look solid.

Please sync onto updated main (#139, #131, #104, #61) so src/wasm.rs preserves #104's Telemetry serializer and #61's ParameterControl decoding (formatting any new error paths through wasm_error / ts_error), and add runtime assertions in scripts/verify-pack.mjs covering pre-init errors, idempotent free(), post-disposal errors, and camelCase Wasm error messages.

Note: Once #119 merges, the Tunelet / defaultConfig / initSync wrapper will need to live in src/shared.ts so dist/browser.js, dist/node.js, and dist/index.js remain equivalent.

- Keep the Telemetry serializer and ParameterControl decoding
- Format ParameterControl validation errors with camelCase paths
- Check pre-initialization errors for defaultConfig and Tunelet
- Check camelCase Wasm error paths and clean TypeScript names
- Check duplicate free calls and post-free errors
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed in 3ea33a3 and 4b2ff45 (synced onto latest main 8880205 with #139, #131, #104, and #61):

  • Synced src/wasm.rs with #104 and #61: Preserved serialize_telemetry / JsTelemetry in telemetry() and take_telemetry() from #104 and ParameterControl event decoding from #61, routing ValidatedEvents::new(buffer, frames, config) through wasm_error so scalar parameter validation errors report camelCase JavaScript property paths.
  • Added runtime assertions in scripts/verify-pack.mjs: Added checks in verifyRuntimeImport covering pre-init errors (defaultConfig() and new Tunelet(...) before loadTunelet() and initSync()), camelCase Wasm error messages (constructor, setConfig, unordered pitch bounds, stage config events, and #61 ParameterControl events across Int16 and Float32 / in-place Float32 calls), stripped tunelet:: type paths, idempotent free() / [Symbol.dispose]() calls, and post-disposal errors across all getters and methods.
  • Noted on #119: once #119 merges, we will move the Tunelet / defaultConfig / initSync wrapper into src/shared.ts so dist/browser.js, dist/node.js, and dist/index.js remain equivalent.

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.

1 participant