Skip to content

feat!: add partial configuration patches and patch events - #122

Open
google-labs-stitch[bot] wants to merge 10 commits into
mainfrom
stitch/add-partial-config-patches-jm0-7f8be01d-288e-47bb-a4ce-5d2b73d7089a
Open

google-labs-stitch[bot] wants to merge 10 commits into
mainfrom
stitch/add-partial-config-patches-jm0-7f8be01d-288e-47bb-a4ce-5d2b73d7089a

Conversation

@google-labs-stitch

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

Copy link
Copy Markdown
Contributor

Summary

This change adds partial configuration patch types, Processor::patch_config, Tunelet.patchConfig, and ControlEvent::Patch so Rust and WebAssembly callers can update selected fields without a full configuration copy.

  • Define Copy, Default, and #[non_exhaustive] patch structs (ProcessorConfigPatch, PunchConfigPatch, WarmConfigPatch, ResynthesisConfigPatch, PitchConfigPatch, CorrectionConfigPatch including humanize and flex_tune, FormantConfigPatch, HarmonyConfigPatch, AlienConfigPatch, and ReverbConfigPatch), export them from src/lib.rs, and re-export their generated TypeScript interfaces from src/index.ts via export * from "../pkg/tunelet.js".
  • Reuse the shared pub(crate) fn validate_* range and finiteness helpers across *Config::validate and *ConfigPatch::validate.
  • Derive optional camelCase Wasm serialization and TypeScript declarations (#[serde(default, rename_all = "camelCase")] and #[tsify(optional, type = "... | undefined")]) on all ten patch structs for exactOptionalPropertyTypes: true compatibility, and normalize patch and ControlEvent JSDoc comments in scripts/normalize-jsdoc.mjs.
  • Add Processor::patch_config and Tunelet.patchConfig to merge supplied fields onto a stack copy of ProcessorConfig, validate touched stages and pitch frequency order (min_frequency_hz < max_frequency_hz), and apply the result through Processor::apply_config.
  • Add ControlEvent::Patch(ProcessorConfigPatch) alongside ControlEvent::Parameter(ParameterControl) on #[non_exhaustive] ControlEvent, register "patch" in the cached EventKeys Wasm event decoder across i16 and Float32 process* calls, and advance the stack ProcessorConfig copy in ValidatedEvents::new / validate_in_sequence so block preflight validates single-bound pitch patches against active or earlier-event bounds before any state, output buffer, or drain changes.
  • Keep config(), setConfig(), defaultConfig(), Processor::apply_config, Resynthesis::apply_config, and all existing ControlEvent variants unchanged so fixed-point PCM and Float32 output stay bit-exact.
  • Document patchConfig, ProcessorConfigPatch, and ControlEvent::Patch alongside ControlEvent::Parameter in README.md and rustdoc, and extend scripts/verify-pack.mjs with runtime and --exactOptionalPropertyTypes undefined coverage across all ten *ConfigPatch interfaces.

Verification

  • Passed cargo fmt --check, cargo clippy --locked --lib -- -D warnings, RUSTFLAGS="-D warnings" cargo build --locked --release, RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps, cargo package --locked, and MSRV 1.88 builds.
  • Passed npm run check:wasm, npm run verify:pack, and npm run verify:pack -- --ignore-scripts.
  • Verified external-crate #[non_exhaustive] patch construction via Default::default(), identical Error::InvalidConfig results across shared validate_* helpers, bit-identical PCM, Float32, feedback, telemetry, formant envelope, and drain output across patch_config / ControlEvent::Patch / ControlEvent::Parameter and set_config / ControlEvent::Configure, empty {} drain cancellation, undefined patch property preservation, and atomic preflight rejection on invalid fields and unordered pitch bounds.
  • Benchmarked Wasm boundary calls:
    • config() + setConfig(cfg): 383 Wasm-to-JS calls, 8 UTF-8 malloc calls (37.576 us median)
    • setConfig(cachedConfig): 251 Wasm-to-JS calls, 8 UTF-8 malloc calls (21.773 us median)
    • patchConfig({ outputGain: 0.9 }): 20 Wasm-to-JS calls, 0 UTF-8 malloc calls (2.070 us median)
    • patchConfig({ resynthesis: { dryMix: 0.2 } }): 66 Wasm-to-JS calls, 0 UTF-8 malloc calls (6.124 us median)
    • ControlEvent::Patch({ resynthesis: { dryMix: 0.2 } }): 89 Wasm-to-JS calls, 0 UTF-8 malloc calls (9.205 us median) vs 209 calls and 7 malloc calls (19.397 us median) for ControlEvent::Resynthesis

Automated PR initiated by user @byteland-app via Stitch Loop.

- Define Copy and Default patch structs for ProcessorConfig and stages
- Derive optional camelCase Wasm types and TypeScript declarations
- Add Processor::patch_config and Tunelet.patchConfig methods
- Add ControlEvent::Patch and track pitch bounds in event preflight
- Export all ten patch types from src/lib.rs and src/index.ts
- Document patch controls in README.md and check them in verify-pack
@byteland-app

Copy link
Copy Markdown
Contributor

Review: Preferred over #64, #66, and #72 for partial configuration updates (18x faster Wasm patchConfig, strict atomic event validation, non-breaking in TS). Please refine before merge:

  1. Deduplicate range checks by sharing validate_* helpers between *Config and *ConfigPatch (coordinating with feat(events)!: add scalar parameter control events #61).
  2. Because ControlEvent is not #[non_exhaustive], adding ControlEvent::Patch is a Rust breaking change — coordinate with feat(events)!: add scalar parameter control events #61 in the 0.4.0 breaking window and consider #[non_exhaustive] on ControlEvent.

- Decode patch events in EventKeys and decode_control_event.
- Pass the active configuration to decode_events.
- Keep SyncInitInput and patch types in scripts/verify-pack.mjs.
- Extract pub(crate) validate_* helpers for all stage fields.
- Call the shared helpers from *Config::validate and *ConfigPatch.
- Share PitchConfigPatch::validate_fields in validate and apply_to.
- Align PunchConfigPatch rustdoc terms with PunchConfig.
- Add #[non_exhaustive] to ControlEvent for the 0.4.0 release.

BREAKING CHANGE: ControlEvent adds Patch and is #[non_exhaustive].
@google-labs-stitch google-labs-stitch Bot changed the title feat: add partial configuration patches and patch events feat!: add partial configuration patches and patch events Nov 25, 2026
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed both items and merged main (0.3.3):

  1. Shared validate_* helpers: Extracted pub(crate) fn validate_* helpers across punch, warm, alien, reverb, pitch, formant, harmony, and resynthesis (matching #61's helper names, signatures, and rustdoc comments, alongside config::validate_output_gain) and reused them in both *Config::validate and *ConfigPatch::validate (plus shared PitchConfigPatch::validate_fields in validate and apply_to).
  2. 0.4.0 breaking window and #[non_exhaustive]: Added #[non_exhaustive] to ControlEvent (25e0ca5) and marked the commit and PR title with ! (BREAKING CHANGE:) to coordinate with #61 for the 0.4.0 release window.
  3. Sync with main (0.3.3): Resolved conflicts with #99 and #118 (51af208), adding "patch" to the cached EventKeys Wasm event decoder (0 UTF-8 malloc calls for ControlEvent::Patch) and keeping unscoped + scoped archive checks in scripts/verify-pack.mjs.

@byteland-app

Copy link
Copy Markdown
Contributor

Round 2 review: Approved for the 0.4.0 breaking window — partial config patches, atomic sequential event validation, and shared validate_* helpers look solid. Please rebase onto updated main (after #123 and #135) and coordinate with #61 on ControlEvent::Parameter in validate_in_sequence.

- Merge main 0.3.4 with ControlActivity and the Wasm scripts.
- Export ControlActivity next to the configuration patches.
- Check patchConfig, ControlActivity and patch events in verify-pack.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed in d133778:

  1. Synced onto updated main (0.3.4, 720690b, including fix(wasm): sanitize TypeScript declarations and Wasm exports #123 and feat: add control activity queries #135):
    • Merged main into this branch (fast-forward merge commit required by branch push settings) and resolved conflicts in src/config.rs, src/lib.rs, src/processor.rs, src/wasm.rs, README.md, and scripts/verify-pack.mjs.
    • Exported ControlActivity alongside the ten *ConfigPatch types, kept controlActivity() in README.md and WasmProcessor, and verified sanitized pkg/tunelet.d.ts declarations (postbuild-wasm.mjs), harmony.voices: undefined, HTTP/URL loaders, and all four --exactOptionalPropertyTypes consumer tsc profiles (node, es2023, dom, webworker) alongside patchConfig and ControlEvent::Patch across both npm tarballs, plus MSRV 1.88.
  2. Coordinated validate_in_sequence in src/events.rs with feat(events)!: add scalar parameter control events #61 (ControlEvent::Parameter):

@byteland-app

Copy link
Copy Markdown
Contributor

Round 3 review: Core patch logic, atomic sequential validation, and #61 alignment look solid, but one TypeScript issue needs a fix before 0.4.0:

- Add humanize and flex_tune to CorrectionConfigPatch
- Share validate_humanize and validate_flex_tune in src/resynthesis.rs
- Pass the active configuration to decode_events in Float32 Wasm calls
- Normalize patch and ControlEvent JSDoc links in normalize-jsdoc.mjs
- Keep patchConfig in the TypeScript table and rules in README.md
- Check patchConfig JSDoc and Float32 patch events in verify-pack.mjs
- Add `| undefined` to all optional `tsify` types on patch structs.
- Check `undefined` patch fields in `scripts/verify-pack.mjs`.
- Document `undefined` patch fields in `README.md`.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed in 39050a7 and a4170f2:

  1. Added | undefined to all optional tsify field types across all 10 *ConfigPatch structs (a4170f2):
    • Annotated every optional field in ProcessorConfigPatch, PunchConfigPatch, WarmConfigPatch, ResynthesisConfigPatch, PitchConfigPatch, CorrectionConfigPatch (including humanize and flex_tune), FormantConfigPatch, HarmonyConfigPatch (including [number, number, number, number] | undefined), AlienConfigPatch, and ReverbConfigPatch with tsify(optional, type = "<TsType> | undefined").
    • Documented in README.md that absent or undefined patch fields keep their active values on the processor.
  2. Added --exactOptionalPropertyTypes and runtime undefined coverage in scripts/verify-pack.mjs (a4170f2):
    • Tested explicit undefined literals and number | undefined variables across every field of all 10 *ConfigPatch interfaces under all four --exactOptionalPropertyTypes consumer tsc profiles (node, es2023, dom, webworker).
    • Verified at runtime across both tunelet and @bytelandtechnology/tunelet archives that patchConfig and { type: "patch", value } with undefined stage, scalar, tuple, NoteMask, and bigint fields preserve the active processor configuration.
  3. Synced with updated main (0850e25, after #45, #107, and #117) (39050a7):
    • Merged main (fast-forward merge commit required by branch push settings), added humanize and flex_tune plus shared validate_humanize / validate_flex_tune helpers to CorrectionConfigPatch, passed self.processor.config() to decode_events in all four #117 Float32 Wasm process* methods, and mapped all patch doc tokens in scripts/normalize-jsdoc.mjs.

@byteland-app

Copy link
Copy Markdown
Contributor

Review: Core patch validation, atomic sequential preflight, and exactOptionalPropertyTypes handling look solid. Three items before merge:

  1. Add #[non_exhaustive] to all 10 *ConfigPatch structs: Every *Config struct in tunelet is #[non_exhaustive] so adding a new configuration field stays a minor-version addition in Rust. Because *ConfigPatch mirrors *Config fields 1:1, leaving the patch structs exhaustive would make any future config field addition a Rust breaking change. Please mark ProcessorConfigPatch and all 9 stage/sub-stage patch structs #[non_exhaustive].
  2. Minor cleanup (src/index.ts): Remove the redundant export type { ...Patch } re-export block (already exported by export * from "../pkg/tunelet.js").
  3. Sync onto updated main (build(cargo): bump the cargo group with 2 updates #139, ci: deny compiler and rustdoc warnings in scripts and docs #131, feat!: add pitch fields to Telemetry and trim Wasm voice slices #104, feat(events)!: add scalar parameter control events #61): Reuse feat(events)!: add scalar parameter control events #61's shared validate_* helpers, #[non_exhaustive] ControlEvent, and ValidatedEvents::new / validate_in_sequence, and wire ControlEvent::Patch alongside ControlEvent::Parameter. (We plan to merge feat!: add partial configuration patches and patch events #122 after the remaining 0.4.0 config-adding PRs land so *ConfigPatch covers every 0.4.0 field.)

- Reuse the validation helpers from main in all patch types
- Combine ControlEvent::Patch and ControlEvent::Parameter in events
- Decode patch and parameter events in the Wasm event decoder
- Document patch and scalar parameter controls in README.md
- Check patch, parameter and telemetry types in verify-pack.mjs
- Add #[non_exhaustive] to ProcessorConfigPatch in src/config.rs
- Add #[non_exhaustive] to all nine stage and sub-stage patch types
- Remove the redundant export list of patch types from src/index.ts
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed in c2b8b5d, 6808f3d, and 938dc31:

  1. Marked all 10 *ConfigPatch structs #[non_exhaustive] (6808f3d): Added #[non_exhaustive] to ProcessorConfigPatch, PunchConfigPatch, WarmConfigPatch, ResynthesisConfigPatch, PitchConfigPatch, CorrectionConfigPatch, FormantConfigPatch, HarmonyConfigPatch, AlienConfigPatch, and ReverbConfigPatch so future configuration field additions stay minor-version compatible in Rust.
  2. Removed redundant TypeScript re-exports (938dc31): Removed the duplicate export type { ...Patch } block from src/index.ts, relying on export * from "../pkg/tunelet.js" (verified across all four --exactOptionalPropertyTypes tsc profiles in scripts/verify-pack.mjs).
  3. Synced onto updated main (8880205, including #139, #131, #104, and #61) (c2b8b5d): Reused #61's shared validate_* helpers, #[non_exhaustive] ControlEvent, and ValidatedEvents::new / validate_in_sequence, wiring ControlEvent::Patch alongside ControlEvent::Parameter across Rust, the cached EventKeys Wasm decoder, README.md, and scripts/verify-pack.mjs.

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