Skip to content

Round-1 review fixes for #386: runtime and tests - #632

Merged
neuromechanist merged 18 commits into
epic/324-pyodide-browserfrom
agent/20261117-fix386b-runtime
Nov 17, 2026
Merged

neuromechanist merged 18 commits into
epic/324-pyodide-browserfrom
agent/20261117-fix386b-runtime

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Fixes the round-1 review items of #386 that live in runtime code, the browser bridge and their tests; the CI, release, dependency and documentation items are in a separate pull request.

  • F7: the runica dgemm test no longer leaks its backend into later tests (its patches live in a MonkeyPatch.context() that is undone before the reload), and the new test_runica_backend_callable_matches_its_label fails if the leak returns.
  • F14: test_runica_blas_backend_matches_numpy_backend now compares all four runica training loops (bias on and off, logistic and extended) at the same tolerances.
  • F8: the bridge sets ort.env.wasm.numThreads (default 1, overridable with the numThreads option) before its first session instead of a session option that onnxruntime-web ignores; measured with the real library, the thread count was 4 on a 10-core machine before and is 1 now.
  • F20: the bridge exposes modelBytes, and the Python adapter compares its SHA-256 with the packaged iclabel_int8.onnx on every call and raises RuntimeError naming both digests when they differ.
  • F15: the adapter raises RuntimeError when the bridge returns a NaN or infinite probability, which eeg_icflag would otherwise keep silently.
  • F3 (harness part): the harness pins python-picard==0.8.2, the uv.lock version, and a test checks the pin against uv.lock and the extra's range.
  • F16: pop_iclabel and pop_iclabel_async report a missing ONNX Runtime before the version dialog, and the subprocess test covers both pop functions.
  • F17: a test covers the dispatch_gui_async fall-through for a non-ICLabel action, and a MATLAB-gated test compares iclabel_async(engine='matlab') with iclabel.
  • F18: the psutil-free ASR message names MaxMem as well as maxmem, and tests cover the too-low budget fallback of asr_process and asr_process_r without psutil.
  • F19: the freshness token is tested over structured, unicode, bytes, bool, datetime64, timedelta64, zero-dimensional, byte-swapped, zero-size and strided structured arrays, and a test pins the documented repr limitation for sparse matrices.
  • F21: pop_writeeeg probes pyedflib before creating the output directory, and the test asserts that no directory is left behind.
  • F22: ransac.py is byte-identical to develop again (the get_eeglab shim was a leftover; importing runica loads the EEGLAB bridge but not mne), the matching AGENTS.md carve-out is gone, and the test that pinned the shim is deleted.
  • F24: classifications record network, the packaged file that ran (iclabel.onnx natively, iclabel_int8.onnx in the browser), next to version; the engine path removes a stale network, and a saved dataset keeps it. This adds a field to saved .set files that MATLAB EEGLAB ignores, so reverting the single "Record which ICLabel network ran" commit drops it.
  • F25: a dataset's own history records the EEGLAB form EEG = pop_iclabel(EEG, 'default');, while ALLCOM and LASTCOM keep the await form that await eegh(n) replays.
  • F26: a command added to the dataset history while an asynchronous ICLabel runs is now kept, in the GUI and the console; a console result stored as a new dataset keeps its own history.
  • F12 (AGENTS.md line): uv sync --group dev is the documented command, because the dev group carries ONNX Runtime.

F27 is declined as a false positive: the console captures the token when the coroutine is created, so user code can run between creating it and awaiting it on native platforms too, and test_console_pop_iclabel_async_captures_the_selection_when_called (native, no gate) passes; if the token were built only under Emscripten, dataset 1's labeled result would be stored as a new dataset 3 and CURRENTSET would jump to it (the test fails with DID NOT RAISE), and ConsolePopFunction wraps every coroutine pop_*, including extension ones that can really yield on native platforms, so no cheaper correct generic design exists (the cost is two hash passes, as the token's docstring says).

F7 reproduction on the base with pytest 9.0.3: after test_runica_runs_its_training_products_through_dgemm_on_emscripten, a probe printed platform=darwin BACKEND=numpy.matmul callable=_blas_matmul; alone it printed _numpy_matmul.

Tested: ruff check . (All checks passed!), ruff format --check . (966 files already formatted), ./pre-commit.py --changed-from origin/epic/324-pyodide-browser (OK), and ty check (9 diagnostics, all unresolved imports of torch, onnx and pamica from extras that are not installed; none in a changed file).

Tested: 13 test files (runica, ransac, ICLabel, Pyodide harness, optional extras, session contracts, GUI ICLabel, console, main window, help, public API) end with 300 passed, 3 skipped, 1 deselected, 198 warnings for the first seven and 85 passed, 3 deselected, 146 subtests passed for the other six.

Tested: the local Pyodide harness end to end (wheel built from this branch, real Pyodide 0.29.5 and onnxruntime-web 1.30.0 under Node.js) ran iclabel_parity.py, and compare_iclabel.py exited 0 with "allclose": true and "max_absolute_difference": 4.5299530029296875e-06.

Review round 2 added separate commits: the bridge creates its session from a copy of the model (a transferred buffer would detach modelBytes and fail the next digest check) and keeps a thread count the host already set; the adapter fails closed on a modelBytes that is not a byte buffer; eeglab_history_command rewrites only one single-line statement; the ONNX Runtime check order of pop_iclabel and the scope of the 0.01346 bound are documented.

Every code fix has a test that fails without it; each was checked by reverting the fix.

Not run: Tests (pull requests into the epic run no test.yml; they run on #386 after this merges), the MATLAB-gated F17 case, the EEGLAB reference workflow.

Refs #386

Card FIX-386b of the NEMAR portable-compute program.

@claude claude Bot 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.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @neuromechanist's task in 1m 30s —— View job


Code review

  • Overall assessment: Looks good. I checked the runtime fixes against the changed call sites. I found no correctness, parity or AGENTS.md problems that meet the bar for a finding.
  • Highest-risk area: Copying history into async results (EEGPrepSession.carry_current_history, used in ConsolePopFunction and MenuActionDispatcher). I traced it and found no problem.
  • Merge recommendation: Safe to merge into epic/324-pyodide-browser.

Blocking

None.

Important

None.

Nits

None.

Test gaps

None.

EEGLAB parity notes

None. The new etc.ic_classification.ICLabel.network field is additive. MATLAB EEGLAB ignores it, _run_eeglab_engine removes a stale copy, and pop_runica already drops all of ic_classification. The dataset history now gets the replayable EEG = pop_iclabel(EEG, 'default'); form, which matches what EEGLAB itself would record.

What I checked

  • F26 history carry-over:
    • eegh adds to a dataset's history by updating the dataset object it is given, so _first_call_eeg_argument(...) is session.EEG still holds after a console eegh runs during the await.
    • history is a string, so computed["history"] = existing["history"] shares no state that could change later.
    • Results stored as a new dataset keep their own history.
    • A list result whose length doesn't match the selection is returned unchanged.
  • F25 eeglab_history_command:
    • It only rewrites a single X = await pop_*_async(...); statement.
    • A ; outside quotes in the arguments, which would mean more than one statement, leaves the command untouched.
    • The rewrite happens only in _append_current_dataset_history, so ALLCOM/LASTCOM keep the await form.
  • F16: Both pop functions check for ONNX Runtime before the dialog opens. pop_iclabel(None) still returns None. The async variant skips the check under Emscripten, where the web bridge runs the network instead.
  • F20/F15:
    • On a JsProxy, getattr(bridge, "modelBytes", None) returns None for a missing attribute, so an old bridge gets the host-contract ImportError.
    • The bridge's model is hashed on every call against iclabel_int8.onnx read through importlib.resources. That works without the EEGLAB checkout.
    • The finite check runs after the size check.
  • F24: iclabel_net_onnx → iclabel_net_onnx_web is a light import with no cycle. NETWORK_FILE resolves to iclabel_int8.onnx only under Emscripten.
  • F21: _require_pyedflib runs before mkdir, and GDF output still doesn't need pyedflib.
  • F22: ransac.py now imports get_eeglab at the top. The AGENTS.md carve-out and the test that pinned it are both removed.
  • F7/F14: MonkeyPatch.context() is undone before the finally reloads. The new label/callable test catches a leaked dgemm callable. The bias × extended parametrization covers all four runica training loops at unchanged tolerances.
  • F3/F12: python-picard==0.8.2 matches uv.lock (line 2451) and the extra's >=0.8,<0.9 range. The dev group in pyproject.toml lists onnxruntime>=1.20, so the AGENTS.md change is accurate.

As the PR body says, the MATLAB-gated test_async_engine_matches_sync and the EEGLAB reference workflow were not run. They are needed on #386 before that PR merges, because #386 changes core ICLabel code.

@neuromechanist
neuromechanist merged commit 3fa42bc into epic/324-pyodide-browser Nov 17, 2026
@neuromechanist
neuromechanist deleted the agent/20261117-fix386b-runtime branch November 17, 2026 21:53
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