Skip to content

[clean_rawdata] Document the short-calibration return and the one-row fit crash - #667

Merged
suraj-ranganath merged 3 commits into
developfrom
cursor/fix-clean-rawdata-fuzz-663-664-bdb7
Nov 28, 2026
Merged

suraj-ranganath merged 3 commits into
developfrom
cursor/fix-clean-rawdata-fuzz-663-664-bdb7

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Two pop_clean_rawdata crops diverge for different reasons. Neither is the flat-channel repair (#649) or the zero fit width (#655).

On the 1024-sample crop starting at sample 1034, channel cleaning leaves 26 channels and the calibration section is 28 samples, so asr_calibrate.m line 190 errors. clean_artifacts.m lines 270-275 then return that 26 by 1024 array before window removal (clean_windows.m is never reached). EEGPrep skips the burst and still removes windows, keeping 551 samples. The harness classifies that pair as a documented difference when the oracle equals the channel-cleaned recording, clean_asr raises ASRCalibrationError on it, and EEGPrep equals the same call with BurstCriterion off.

On the crop starting at sample 1183, burst rejection leaves 5 windows. fit_eeg_distribution.m descends the default width grid, and at width 1 histc of the one-row slice is a row while logq(1:end-1,:) is empty, so line 126 raises MATLAB:bsxfun:arrayDimensionsMustMatch from clean_windows.m line 106 and clean_artifacts.m line 320. The nested copy in asr_calibrate.m transposes that row at line 397 and does not hit the bsxfun. clean_windows now raises ValueError naming clean_windows, the rounded width, and WindowCriterion 'off'. The harness accepts that pair only when the identifier, the fit_eeg_distribution and clean_windows stack, and the window count agree.

test_channel_cleaned_short_calibration_return_is_not_a_divergence and test_final_window_row_histogram_is_not_a_divergence replay both crops. A wrong identifier, a mismatched window count, and an oracle that is still the original array still diverge. Tolerances are unchanged. The MATLAB reference suite was not run.

Fixes #663
Fixes #664

Open in Web Open in Cursor 

…n return

clean_windows raises when a fit width rounds to 1, which is the bsxfun crash in fit_eeg_distribution.m:126. The fuzz harness records that crash, and the clean_artifacts early return after a 28-sample calibration, as documented differences.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 23, 2026 03:07

@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 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 1m 13s —— View job


Code review

  • Overall assessment: Looks good. I checked the clean_windows error path and message, both new harness classifiers (_channel_cleaned_asr_return_detail, _final_window_row_histogram_is_known), where they sit in evaluate_case, and the negative cases in the new tests (wrong identifier, wrong window count, oracle that returns the original array).
  • Highest-risk area: tests/fuzz/harness.py _channel_cleaned_asr_return_detail. It accepts a case when no caught error was recorded at all (_caught_is_calibration returns True). It is still safe because it also requires three things: EEGPrep's clean_asr raises ASRCalibrationError on the channel-cleaned recording, the oracle equals that recording, and the Python result equals the run with the burst stage off.
  • Merge recommendation: Safe to merge.

Blocking

None.

Important

None.

Nits

  • tests/fuzz/harness.py:1880 _final_window_row_histogram_is_known: the call _clean_windows_count(..., 1.0, 0.66) repeats _CLEAN_WINDOW_OVERLAP (harness.py:433) as a bare literal. Use the constant so the two cannot drift apart. An inline suggestion is posted.
  • tests/fuzz/harness.py _channel_cleaned_asr_return_detail docstring: "The calibration section for the 2026-11-20 crop is 28 samples" describes one fuzz case inside a general classifier. That fact belongs in the docstring of test_channel_cleaned_short_calibration_return_is_not_a_divergence, where it is already stated. Drop the sentence here.

Test gaps

None. Both crops are replayed, and each new classifier has a negative case that still diverges.

EEGLAB parity notes

  • The only runtime change is the ValueError text in clean_windows.py. The trigger condition and the numbers are unchanged, and the new message follows the existing asr_calibrate.py:42 pattern ("Use a longer recording or set BurstCriterion='off'"). This PR therefore arguably does not need the AGENTS.md MATLAB reference run. If maintainers count any edit under plugins/clean_rawdata/ as a core-function change, the PR body should say why the run was skipped instead of only "was not run".
  • I could not check the cited .m line numbers in this checkout because the vendored src/eegprep/eeglab/ tree is not present: fit_eeg_distribution.m:126, asr_calibrate.m:190/397 and clean_artifacts.m:270-275/320.

Not done

  • I did not run the tests. The sandbox did not approve the uv run pytest command.
  • This review is posted here, in the tracking comment, not as a separate gh pr comment, because writing the body file outside the workspace was not approved.

· Branch: cursor/fix-clean-rawdata-fuzz-663-664-bdb7

Comment thread tests/fuzz/harness.py Outdated
prepared = _pop_clean_rawdata_variant(eeg, params, WindowCriterion="off")
except Exception:
return False
count = _clean_windows_count(int(prepared["pnts"]), float(prepared["srate"]), 1.0, 0.66)

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.

Nit: 0.66 repeats _CLEAN_WINDOW_OVERLAP (

_FIT_WIDTH_STEP = 0.01
_CLEAN_WINDOW_OVERLAP = 0.66
_ASR_REF_WNDLEN = 1.0
). Use the constant so the two can't drift apart.

Suggested change
count = _clean_windows_count(int(prepared["pnts"]), float(prepared["srate"]), 1.0, 0.66)
count = _clean_windows_count(int(prepared["pnts"]), float(prepared["srate"]), 1.0, _CLEAN_WINDOW_OVERLAP)

@arnodelorme

Copy link
Copy Markdown
Collaborator

I verified the MATLAB line references against sccn/eeglab's plugins/clean_rawdata tree and ran the new unit and fuzz-harness tests locally:

  • EEGLAB .m line reference verification:
    • fit_eeg_distribution.m line 126 is indeed kl = sum(bsxfun(@times,p,bsxfun(@minus,log(p),logq(1:end-1,:)))) + log(m);, where histc(H, [0:nbins-1, Inf]) on a 1-row H (m == 1 with multiple columns) returns a row vector so logq(1:end-1,:) is empty (0x11) and bsxfun raises MATLAB:bsxfun:arrayDimensionsMustMatch.
    • asr_calibrate.m line 190 is if S < N (raising 'No enough reference data...'), and line 397 in its local copy of fit_eeg_distribution is if size(logq,1) == 1, logq = logq'; end.
    • clean_artifacts.m lines 270 to 275 catch the Euclidean clean_asr calibration error and return the channel-cleaned EEG before line 320 (EEG = clean_windows(EEG,window_crit,window_crit_tolerances);).
  • Pytest verification: Ran pytest tests/test_clean_windows.py tests/test_fuzz_harness.py -k "too_few_windows or short_calibration or final_window_row" in the local environment; all 3 tests pass.
  • Minor nits: As noted in the earlier automated comment, _final_window_row_histogram_is_known in tests/fuzz/harness.py passes 0.66 as a literal instead of _CLEAN_WINDOW_OVERLAP, and the crop-specific sentence in _channel_cleaned_asr_return_detail's docstring is already covered in the test docstring. Neither is blocking.
  • Recommendation: Ready to merge.

— orchestrator

cursoragent and others added 2 commits November 27, 2026 00:51
…awdata-fuzz-663-664-bdb7

Co-authored-by: Suraj Ranganath <[email protected]>

# Conflicts:
#	docs/source/changelog.rst
@suraj-ranganath
suraj-ranganath merged commit aa81d9a into develop Nov 28, 2026
12 checks passed
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.

[fuzz][exception-mismatch] exception-mismatch:ValueError/MatlabExecutionError in pop_clean_rawdata [fuzz][shape] shape in pop_clean_rawdata

3 participants