Skip to content

Tradelock feedback#1

Open
nickgeoca wants to merge 2 commits intomainfrom
tradelock-feedback
Open

Tradelock feedback#1
nickgeoca wants to merge 2 commits intomainfrom
tradelock-feedback

Conversation

@nickgeoca
Copy link
Copy Markdown
Contributor

Summary

  • Adds AlphaBumpDetector, AlphaPeakModel, CalmnessModel wrapper classes and band_powers_relative() over the raw wasm-bindgen output
  • process() now returns NotReady | <Reading> instead of bare undefinedNotReady carries samplesNeeded so callers always know why they got no result
  • Sample progress exposed via .samplesBuffered / .samplesNeeded
  • WASM result objects freed automatically in try/finally — callers never handle heap-allocated results
  • Raw WASM classes still re-exported, so fully non-breaking

Motivation

Feedback from a downstream consumer (tradelock) who had to build their own accumulator on top because process() gave no signal on why it returned undefined, and hit silent memory leaks from unfreed result objects.

Test plan

  • pnpm test passes in packages/eeg-web
  • Verify NotReady path returns correct samplesNeeded
  • Verify warm path returns plain JS reading object (no .free() needed)

Want me to swap in the actual downstream link or adjust the tone?

The raw wasm-bindgen output has three usability problems that every
consumer ends up working around on their own:

1. process() returns bare undefined while the model is warming up,
   with no way to distinguish "buffering" from an error or to know
   how many more samples are needed.

2. min_samples() exists but there is no way to query progress toward
   it — callers have to track sample counts externally.

3. Every process() call returns a heap-allocated WASM result object.
   Forgetting .free() leaks silently; FinalizationRegistry is
   registered but non-deterministic.

This commit adds three wrapper classes (AlphaBumpDetector,
AlphaPeakModel, CalmnessModel) and a band_powers_relative() helper
that fix all three issues:

- process() returns NotReady | <Reading> — a discriminated union
  where NotReady carries samplesNeeded so callers always know why
  they got no result.
- .samplesBuffered and .samplesNeeded are tracked automatically.
- WASM result objects are extracted into plain JS objects and freed
  in a try/finally, so callers never touch heap-allocated results.

The raw WASM classes are still re-exported from index.ts for
low-level access, so this is fully non-breaking.
- Extend eeg_wasm mock with WASM model/result classes
- Add models.test.ts covering NotReady discriminated union, sample
  tracking, reset, Symbol.dispose, and band_powers_relative
- Export models from index.ts
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