Skip to content

Ask NEMAR's model for one condition per events call - #489

Merged
neuromechanist merged 2 commits into
developfrom
fix/nemar-erp-events-per-condition
Sep 24, 2026
Merged

neuromechanist merged 2 commits into
developfrom
fix/nemar-erp-events-per-condition

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Found in the production check on nemar.org/dataset/nm000132 right after 0.8.14 went live.

What went wrong

Asked for an ERP image of faces and scrambled faces at PO8 in sub-001's N170 recording:

  • The model called nemar_get_events with where: {"trial_type": ["stimulus"]}, which returned all 320 stimuli (faces, cars, scrambled faces, scrambled cars).
  • It then sorted those rows into two conditions while copying their sample_index values into the code. The face list began with 410, a response event, and the run reported 282 face and 280 scrambled-face epochs for a recording that has 80 of each.
  • The difference came out as about 0.6 µV, against about 4 µV in the worked example.
  • It also wrapped the prompt's FFT filter in a function and rewrote its slice to start at 0, which shifts every sample taps // 2 later.
  • In the spectrum before it, it excluded EOG channels by exact name (HEOG, VEOG), which matched none of ERP CORE's HEOG_left, HEOG_right, VEOG_lower, and reported "33 EEG channels".

The prompt allowed all of this. Its example asked for both conditions in one call (["face", "scrambled_face"]) and said only "put the indices into the code as a list literal per condition".

The change

  • One condition per call: where: {"event_type": ["face"]}, then a second call for scrambled_face. total_count counts after where, so it is that condition's count. The prompt says never to sort one call's mixed rows by hand.
  • An assert on each list's length against that call's total_count, shown as code, so a copying slip stops the run instead of averaging the wrong epochs.
  • Keep the filter's slice as written when wrapping it in a function.
  • Non-EEG channels by substring: EOG, ECG, EKG, EMG anywhere in the label, with ERP CORE's labels named, and the model says how many EEG channels remain.

Tests

  • pytest tests/test_assistants/test_nemar_runtime.py tests/test_assistants/test_nemar_mcp_wiring.py: 43 passed, including two new pins for these instructions
  • bun frontend/test-data-lane.js: 93 passed (the ERP filter block is still found and still filters)
  • ruff clean

A model's behavior cannot be unit-tested; the check is the same question on test.nemar.org once develop serves this, then on nemar.org after a patch release.

Refs #497.

On nemar.org with 0.8.14 a model asked for all 320 stimulus events of nm000132 sub-001 N170 in one get_events call, sorted them into faces and scrambled faces while copying sample indices into code, and averaged 282 'faces' (the recording has 80) for a 0.6 uV difference where the worked example measures about 4 uV. It also rewrote the filter's slice to start at 0 and excluded EOG channels by exact name, which matched none of ERP CORE's HEOG_left, HEOG_right, VEOG_lower.

The prompt now asks for one condition per call, the code asserts each list's length against that call's total_count, the filter's slice is to be kept as written, and non-EEG channels are matched by substring.

Tested: pytest test_nemar_runtime and test_nemar_mcp_wiring 43 passed (two new prompt pins); bun frontend/test-data-lane.js 93/93; ruff clean.
Review of #489: a condition longer than get_events' limit (1000 by default) comes back truncated while total_count counts all of it, so the assert would fire and a model might match it to the short list. The prompt now says to raise limit or page with offset while truncated is true. The fallback that told the model to sort an unfiltered answer by hand, contradicting the new rule, now says to report that the filter was ignored. The prompt pins compare whitespace-collapsed text and now cover the EOG/ECG/EKG/EMG list itself.

Tested: pytest test_nemar_runtime and test_nemar_mcp_wiring 43 passed; narrowing the list to EOG, and dropping the truncated sentence, each fail a pin; bun frontend/test-data-lane.js 93/93; ruff clean.
@neuromechanist

Copy link
Copy Markdown
Member Author

Review response

One Sonnet review, which also checked the prompt against the live server: nemar_get_events with where: {"event_type": ["face"]} on nm000132 sub-001 N170 returns total_count: 80 and a first sample_index of 5291, as the prompt's example says. Fixed in the latest commit:

  • A condition longer than limit is truncated. total_count counts every row after where, while events stops at limit (1000 by default, 5000 at most), so the assert would fire for a reason its comment does not name, and a model might "fix" it by matching the short list. The prompt now says to call again with a larger limit, or page with offset, while truncated is true.
  • The EOG pin did not pin the list. It now asserts `EOG`, `ECG`, `EKG` or `EMG`; narrowing the list to EOG fails it, as does dropping the truncated sentence.
  • The fallback for a server without columns_summary told the model to take every row and sort it, the opposite of the new rule. It now says that rows that are not all the asked condition mean the filter was ignored, and to say so.
  • Literal pins break on a reflow. They now compare whitespace-collapsed text; a real rewording still fails them, which is the house style for these pins.

pytest tests/test_assistants/test_nemar_runtime.py tests/test_assistants/test_nemar_mcp_wiring.py: 43 passed; bun frontend/test-data-lane.js: 93 passed.

@neuromechanist
neuromechanist merged commit 6f4b992 into develop Sep 24, 2026
10 checks passed
@neuromechanist
neuromechanist deleted the fix/nemar-erp-events-per-condition branch September 24, 2026 21:48
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