Repository navigation
[History] Save session history from ALLCOM and write Python for .py scripts - #797
Conversation
There was a problem hiding this comment.
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.
…ipts The GUI joined ALLCOM into one string, so pop_saveh recorded EEG.history as the source of session history. pop_saveh now translates commands for .py files, and pop_loadset accepts filename/filepath keywords so translated history replays. Part of #785
652b580 to
fdb703a
Compare
arnodelorme
left a comment
There was a problem hiding this comment.
This review was written by an AI assistant during a nightly check, not by Arno.
Code review
- Overall assessment: Needs changes.
- Highest-risk area:
pop_savehsession versus dataset history framing and source detection (src/eegprep/functions/popfunc/pop_saveh.py,src/eegprep/functions/guifunc/menu_actions.py). - Merge recommendation: Needs changes.
Blocking
-
Blocking (
src/eegprep/functions/guifunc/menu_actions.py,src/eegprep/functions/popfunc/pop_saveh.py): MATLAB.msession history files drop EEGLAB startup/redraw lines and emit Python syntax, breaking CI.- References:
eegprep/src/eegprep/functions/guifunc/menu_actions.py
Lines 1105 to 1112 in fdb703a
eegprep/src/eegprep/functions/popfunc/pop_saveh.py
Lines 15 to 18 in fdb703a
eegprep/src/eegprep/functions/popfunc/pop_saveh.py
Lines 34 to 50 in fdb703a
eegprep/tests/test_file_menu_audit_673.py
Lines 256 to 260 in fdb703a
- Why it matters: Removing the MATLAB session wrapper in
menu_actions._save_historywhile keepingSESSION_REDRAW = "eegprep.eeglab();"inpop_savehcauses.msession history scripts to omit[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;and end with Python'seegprep.eeglab();instead of EEGLAB'seeglab redraw;(pop_saveh.mline 77).eegprep.eeglab();is invalid in MATLAB, and this directly breakstests/test_stream11_datasets.py::test_f27_exported_session_history_is_matlab_scriptacross CI. - Suggested fix: Separate the Python and MATLAB session wrappers inside
pop_saveh. Whenis_sessionandis_python, emitPYTHON_IMPORTS,PYTHON_EMPTY_WORKSPACE, translatedsession_commands, and"eegprep.eeglab()". Whenis_sessionand notis_python, emit"[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;", rawsession_commands, and"eeglab redraw;". Update the.massertion intests/test_file_menu_audit_673.py,src/eegprep/resources/help/pop_saveh.md, anddocs/source/user_guide/gui_console_session.rstaccordingly.
- References:
-
Blocking (
src/eegprep/functions/popfunc/pop_saveh.py,src/eegprep/functions/popfunc/pop_loadset.py): Empty or character-arrayEEG["history"]is misclassified asALLCOMsession history.- References:
eegprep/src/eegprep/functions/popfunc/pop_saveh.py
Lines 27 to 36 in fdb703a
eegprep/src/eegprep/functions/popfunc/pop_saveh.py
Lines 50 to 73 in fdb703a
eegprep/src/eegprep/functions/popfunc/pop_loadset.py
Lines 21 to 23 in fdb703a
- Why it matters: In EEGLAB (
pop_saveh.mlines 72 and 84), onlyiscell(allcoms)is session history (ALLCOM), while MATLAB character arrays (''orcharmatrices) areEEG.history. Becausepop_loadsetomits"history"fromTEXT_FIELDS, loading a.setfile with an emptyEEG.historyproducesnp.empty((0, 0), dtype="<U1")(andeeg_histskipspop_loadseton load)._history_commandsreturns[]forallcoms.size == 0and a list forallcoms.dtype.kind in "SU", sois_sessionbecomesTruefor dataset history. Saving dataset history on such a dataset recordspop_saveh(ALLCOM, ...), writesALLEEG, EEG, CURRENTSET, ALLCOM = [], {}, 0, [](overwriting the caller's startingEEGwith{}on replay), and appends the session redraw. - Suggested fix: Restrict
_history_commandstolistandis_cell(allcoms)only, convert non-session inputs with_history_textfromeegprep.functions.adminfunc.eeg_hist(so empty arrays and 2D char matrices become clean text rather than"[]"), and include"history"inpop_loadset.TEXT_FIELDS.
- References:
Important
-
Important (
src/eegprep/functions/popfunc/pop_saveh.py):_python_lineleaves trailing MATLAB%comments untranslated, producing invalid Python onsample_data/eeglab_data.set.- References:
eegprep/src/eegprep/functions/popfunc/pop_saveh.py
Lines 55 to 60 in fdb703a
eegprep/tests/test_file_menu_audit_673.py
Lines 237 to 246 in fdb703a
- Why it matters:
_python_lineonly checkstext.startswith("%"). When a history line has a trailing comment after a semicolon, such asEEG.etc.eeglabvers = 'development head'; % this tracks...insample_data/eeglab_data.set,_console_python_commandsplits on;and leaves; % ...in the output. Saving dataset history ofsample_data/eeglab_data.setto.pyfailsast.parsewithSyntaxError(masked in the new test because line 238 clearsloaded["history"] = ""). - Suggested fix: In
_python_line, split any%comment outside quoted strings before calling_console_python_commandon the code part, then append# ...(or return# ...alone when the translated code part is empty).
- References:
-
Important (
src/eegprep/functions/popfunc/pop_loadset.py): Pre-merge MATLAB reference suite run is still required.- Reference:
eegprep/src/eegprep/functions/popfunc/pop_loadset.py
Lines 164 to 173 in fdb703a
- Why it matters: Per
AGENTS.md, PRs modifying corepop_*implementations must run.github/workflows/eeglab-reference.yml(or the local--eeglab-backend=matlabreference suite) on the final branch and record the results in the PR description before merge, as noted in the PR body. - Suggested fix: Run the MATLAB reference workflow once the blocking fixes above land and add the run summary to the PR body.
- Reference:
Nits
None.
Test gaps
tests/test_file_menu_audit_673.py(test_saved_session_and_dataset_history_name_their_source_and_replay):- Assert that
.msession history contains[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;andeeglab redraw;and does not containeegprep.eeglab(). - Add coverage for saving dataset history immediately after loading a
.setfile whoseEEG.historyis empty (''in MATLAB), verifyingpop_saveh(EEG.history, ...)is recorded and no session workspace reset or redraw is written. - Add coverage for saving
.pyhistory containing an inline MATLAB%comment after;(or directly savingsample_data/eeglab_data.set's loadedEEG["history"]to.pyand parsing withast.parse).
- Assert that
tests/test_pop_loadset.py:- Add a direct unit test calling
pop_loadset(filename=..., filepath=...)with keyword arguments only.
- Add a direct unit test calling
EEGLAB parity notes
- In EEGLAB (
pop_saveh.mlines 72 through 88),ALLCOMis distinguished strictly byiscell(allcoms)and ends.msession scripts witheeglab redraw;, whereasEEG.historyis a character array written without a redraw line.
Tests run
Ran in a detached worktree at fdb703a854f18190634db497ce7c160a46a887d6:
pytest tests/test_file_menu_audit_673.py -k "saveh or saved_session or runscript" tests/test_pop_loadset.py tests/test_stream11_datasets.py -k "saveh or saved_session or runscript or loadset or f27": 37 passed, 1 failed (tests/test_stream11_datasets.py::test_f27_exported_session_history_is_matlab_script).pytest tests/test_eegh.py tests/test_gui_main_window.py -k "saveh or history or runscript": all selected non-ICLabel tests passed (16 passed intest_eegh.py, 5 passed intest_gui_main_window.py).
…-785 # Conflicts: # docs/source/changelog.rst
…ataset history A session .m script starts with the eeglab call and ends with eeglab redraw; only a session .py script ends with eegprep.eeglab(). Only a list or a cell is session history (iscell in pop_saveh.m), so an empty or character-array EEG.history is saved as dataset history. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
This comment was written by an AI assistant (Claude Fable) at Arno's request, not by Arno. Summary. The two blocking bugs of the review above are fixed in commit dd8e3b5, and develop is merged into the branch (the only conflict was the changelog, both entries are kept). I reviewed the whole pull request again and did not merge it: one finding of the first review is still true, and the MATLAB reference run is not finished. What changed
The change is 15 lines added and 11 removed in What remains before a merge
Tests run on the Mac, and details of the second reviewRun in a separate worktree at dd8e3b5, Python 3.11:
Tests changed, only to prove the two fixes:
Second review, other points checked:
— orchestrator |
|
Review (Claude Fable): needs more work
DetailsWhat I ran (head
What is needed
CI and reference run
Parity with
Not blocking, for a later issue
Other open pull requests No code conflict with #857, #848, #841, #836, #835, #850 or #858, which touch the same files. Each shows only the changelog conflict that comes from develop. — orchestrator review |
…-785 # Conflicts: # docs/source/changelog.rst
# Conflicts: # docs/source/changelog.rst
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Code reviewIndependent review by OpenAI Codex (model gpt-6.1-terra, high reasoning effort, read-only sandbox), asked for by Arno, on commit 67436b1. Its verdict was "needs changes". The one blocking finding is fixed in c85b689. Four important findings are left open on purpose and explained below. What this push changed. Develop is merged into the branch (the changelog keeps both entries). It is a merge and not a rebase, because a rebase of a pushed branch needs a forced push and the pull request is squash merged anyway. The shared converter Findings of Codex and what was done
Codex also noted that a session Tests and checks
EEGLAB reference run (rule of pull request #860)
The commits 5547eee and c85b689 carry a — orchestrator |
# Conflicts: # docs/source/changelog.rst
A session .py script sets ALLCOM to the recorded commands and ends with
eegprep.eeglab('redraw', workspace=globals()). The history converter reads
a line Python cannot parse as MATLAB: % starts a comment and a quote after
a name, a closing bracket, a dot or a transpose is a transpose.
A session .py script updates the main window on screen and opens a new one only when there is none, sets LASTCOM to its last command so File > Run script adds no duplicate to ALLCOM, and defines STUDY and CURRENTSTUDY. The history converter copies double-quoted strings as written, reads a backslash in a MATLAB string as an ordinary character and leaves Python comments alone.
EEGLAB records the pop_newset line with a blank at its end. The session compared it with the stripped LASTCOM in several places, so a replayed session could add that command to ALLCOM a second time.
A line with a keyword argument or a ['name'] index was typed as Python:
its strings are left as written, escapes included. A # comment is split
off and kept, as a MATLAB % comment is. An empty EEG ({} or []) given to
the session, by the redraw line or by Run script, leaves eeg_emptyset().
# Conflicts: # docs/source/changelog.rst
A # comment on the header of an if or for block is no longer split off, which left a header Python cannot parse alone. An empty NumPy array of any shape counts as no dataset.
|
🤖 ## Code review Independent review by Google Gemini (model Gemini 4 Carbon, medium effort, through agy, with no right to write), in four passes on today's change. Its last verdict, on the final head 52a5ecc, is "good to merge", with nothing blocking and nothing else found. The first pass, on commit afb9f3c, said "needs changes" with three blocking findings. The second, on commit b23ecba, said "needs changes" with two blocking findings, one of them caused by my first answer. All five are fixed. What is left concerns Python typed by hand in the console, not the history that EEGLAB or the First pass, on afb9f3c (the fix of findings 2 to 5 of the earlier review)
Second pass, on b23ecba
Third pass, on 8c83da5: "good to merge", nothing blocking
Fourth pass, on the final head 52a5ecc (the last commit only): "good to merge", no finding Gemini ran its own inputs of the third pass again. The cell of several lines with a comment on its first line gives the same result as on develop, a comment on one line and a Checks run today
— orchestrator |
|
🤖 I merged this pull request into develop, at Arno's request. Why. Arno answered the review of November 29 with "Yes, fix", "2. Do not empty ALLCOM", "3. Fix", "4. Fix" and "5. Fix", under his standing instruction to merge once the fixes are in and another AI has checked them. Why it was good to merge.
One difference from EEGLAB, which Arno asked for. After running a saved session file, EEGLAB ends with an empty What stays open. The limits of the converter for Python typed by hand in the console are in History converter: Python console lines with escapes or triple quotes, left from #797. The issue of this function, pop_saveh (File > History scripts > Save dataset or session history script): graphical and numerical parity with EEGLAB, stays open by its own rule until Arno finds the window and the saved files close enough, and has a note on what this pull request did. — orchestrator |
File > History scripts > Save session history script now saves
ALLCOM, and a.pyfile holds Python that runs. Replaying a saved session.pyfile keeps its history and shows its datasets in the main window. A.mfile is written exactly as before.One real session in EEGLAB (MATLAB R2025b): load
sample_data/eeglab_data.set, re-reference to average, resample to 64 Hz, save the session history, run the saved file. The same six commands were then saved by EEGPrep as.pyand run with Python.ALLCOM.mfile.pyfile.pyfileOne difference from EEGLAB, asked for by Arno ("Do not empty ALLCOM"). EEGLAB itself ends with an empty
ALLCOMafter it runs a saved session file: the first line[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;returns an empty history, and the replayed commands do not calleegh. EEGPrep now keeps the six commands. This concerns the history list only. No dataset and no number differ.The saved session
.pyfile, before and nowBefore (c85b689):
Now (8c83da5):
The session
.mfile is the same before and now, and has the layout of the file EEGLAB saves:What changed today, for the four findings of the review
The findings are numbered as in the review comment of November 29.
ALLCOM.pop_savehwritesALLCOM = [...]with the commands as they were recorded, in place ofALLCOM = []. After the replayALLCOMequals the saved history, in a new Python process and through File > History scripts > Run script.eegprep.eeglab('redraw', workspace=globals()). It readsALLEEG,EEG,CURRENTSET,ALLCOM,STUDYandCURRENTSTUDYfrom the script, aseeglab redrawreads the MATLAB workspace. The main window on screen is updated, and a new one opens only when there is none. So the script run twice, run from File > History scripts > Run script or run in the console always leaves one window, with the datasets of the script. Before, Run script on a session file left two windows open.ALLCOMandEEG.historyhold both. The rule: a line that Python can parse is not MATLAB, so its%is left alone andx = 7 % 3stays a modulo. Any other line is MATLAB, and its first%outside a string starts a comment.EEG = pop_reref( EEG, []) % average referencebecomesEEG = pop_reref(EEG, ref=[]) # average reference. Limit: a comment that makes the whole line valid Python is not seen.x = 1 % note(one word) stays as it is, since nothing in the text tells it from a modulo.x = 1 % a noteis translated.x = A'; % notebecomesx = A' # note. Limit: the transpose itself is not translated to NumPy, so that statement is still not Python and Run script names its line.The rule is in the shared converter
_console_python_command(adminfunc/console.py), so it also serves File > History scripts > Run script and the console.What the first review by Gemini found on that change, and what commits b23ecba and 38ad63f fix
The review is in the comment "Code review" below. Its findings, in its own numbers:
EEG["setname"] = "don't"came out with a quote too many. A double-quoted string now keeps its text. A#comment is kept..pyfile added a second copy of the lastpop_newsetline toALLCOM. Two causes in shared code: the script leftLASTCOMon an earlier command, so it now setsLASTCOM = ALLCOM[-1]before the redraw, and EEGLAB records thepop_newsetline with a blank at its end, so the session now keeps and compares the last command without trailing blanks. After Run scriptALLCOMholds the six commands and thepop_runscriptline, nothing twice.'C:\data\'ends at its quote and the;and the comment after it are seen..pyfile definesSTUDYandCURRENTSTUDY, and the redraw reads them.x = r' * s';, two transposes of which the first follows a variable namedr,b,foru, is also a valid Python prefixed string, so it is read as Python. No EEGLAB history line has this form.eeg_emptyset, not{}.One more limit of the rule: a MATLAB double-quoted string with a doubled quote inside, in a line that Python also parses, is read as Python. EEGLAB writes its history with single quotes.
What the second review by Gemini found, and what commit 8c83da5 fixes
filepath='C:\\'. The rule is now: a line that Python parses and that has a keyword argument (filename='a.set') or a['name']index was typed as Python, and its strings are left as written, escapes included. Any other line that Python parses keeps the reading it has on develop, where a single-quoted string is a MATLAB string, so EEGLAB history with a Windows folder such as'C:\data\new'keeps its backslashes. Limit: a Python line with neither, such asprint('a\nb'), is still read as on develop, with the backslash kept as a character.{}and not the empty dataset. The session now treatsEEG = [],{}or an empty array as no dataset, wherever it comes from.#comment was dropped, and its text could stop the conversion (x = 1 # [1:0:5]). It is now split off and written back as it is, as a MATLAB%comment is.LASTCOMkept the blank at the end of thepop_newsetline.EEGis on develop. Running the file withpop_runscript, with Run script or with Python is not concerned.#comment and the escaped backslash.Both ALLCOM lists
The session in EEGLAB before saving (oldest first):
ALLCOMin EEGLAB after running the saved file: empty (0 entries).ALLCOMin EEGPrep after running the saved.pyfile (6 entries):The first line of the EEGLAB session,
[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;, is the one EEGPrep writes itself at the top of a.mfile and replaces by the empty workspace line in a.pyfile.The saved dataset history of the sample file
On develop a
.pyfile held MATLAB text. Now:The dataset
.mfile is byte for byte the file develop writes.Verification
pop_saveh,pop_runscript,eeghoreeglab(). On the final head 8c83da5, the 1,107 tests of the GUI, console, history, dataset and study files passed and 10 were skipped. The skips need the MATLAB Engine for Python.tests/test_pop_runica_pamica.pywas left out because thepamicamodule is not installed there. Ruff andpre-commit.pypass.test_session_script_run_again_redraws_the_open_window_and_keeps_allcomis new: it runs a session.pyfile, runs it again alone and through Run script, and checks one window, no command twice inALLCOM, and the empty dataset after an empty session. It fails without today's commits.test_saved_session_and_dataset_history_name_their_source_and_replaynow runs the whole session.pyfile, last line included, and checks the data, thatALLCOMequals the recorded commands and that the window shows the 3 channels of the replayed dataset.test_console_python_command_tells_matlab_history_from_python_inputholds the five lines of findings 4 and 5, and now the double-quoted string, the escaped quote, the escaped backslash, the#comment and the Windows folder.EEGLAB reference run (rule of pull request #860)
pop_loadsetandpop_savehare core functions, so the run is still the required evidence.The limits left for later are in issue #877.
Part of #785