You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Centralize EEGPrepSession workspace state updates #179
🤖 Some GUI and console paths write EEGPrepSession fields directly instead of using session-owned transitions. That skips validation, history propagation, saved flags, CURRENTSTUDY behavior, and storedisk handling.
Relevant code:
src/eegprep/functions/guifunc/menu_actions.py:1048 - extension dataset state direct write
src/eegprep/functions/guifunc/menu_actions.py:1580 - pop_newset commit direct write
src/eegprep/functions/adminfunc/console.py:359 - console ALLEEG direct write
Post Research + Proposed approach (multi-module refactor → no auto-PR)
Scope is multi-module (>100 lines once helper + 13 call-site rewrites + tests land), so per the agent workflow I am posting analysis for human review before implementation.
Research
The canonical commit path is EEGPrepSession.store_current (session.py#L174-L213) — it routes through eeg_store, normalizes CURRENTSET, appends per-dataset EEG.history, optionally marks saved="yes", appends ALLCOM/LASTCOM once, and fires notify_changed once. Every direct self.session.ALLEEG = … / self.session.EEG = … / self.session.CURRENTSET = … triple bypass skips: eeg_store validation/dataset-shape checks (dict vs list of dicts), _append_current_dataset_history per-dataset EEG.history updates, mark_saved propagation, and CURRENTSET normalization (the GUI sites use a local _currentset_list helper that does not de-duplicate or validate 1-based indices the way normalize_dataset_indices does). Direct STUDY writes also skip set_study's CURRENTSTUDY coupling and history wiring.
apply_dataset_state is the bulk-replace primitive — used when an external producer (extension, pop_newset commit, pop_copyset, console pop_* accept) returns a full (ALLEEG, EEG, CURRENTSET) tuple that should overwrite the session in one shot. It uses normalize_dataset_indices (not GUI's local _currentset_list), so console and GUI converge on the same validation.
2. Extend set_study to accept an explicit CURRENTSTUDY override so console's CURRENTSTUDY = 0/1 assignment and _retrieve_dataset's CURRENTSTUDY = 0 no longer need direct field writes:
3. Replace every direct-write site with apply_dataset_state / set_study / clear_current_selection. Net per-site delta: 4–5 lines → 1 call. The _commit_processed_dataset_from_gui site additionally drops its duplicate add_history(command) (command was already appended before the pop_newset call) by passing command=newset_command to apply_dataset_state once.
4. console.after_execute keeps its per-field detection, but when all of ALLEEG/EEG/CURRENTSET targets are present together (the common case for replayed [ALLEEG EEG CURRENTSET] = pop_newset(…) history), route through apply_dataset_state instead of three independent writes + a separate retrieve call.
5. Tests (extend tests/test_session_contracts.py and tests/test_console_workspace.py):
apply_dataset_state rejects mismatched CURRENTSET / EEG-list lengths, normalizes scalar vs list CURRENTSET, fires notify_changed exactly once (counter on a registered listener), appends LASTCOM/ALLCOM exactly once.
GUI: _apply_extension_result, _commit_processed_dataset_from_gui, _copy_current_dataset each fire one notify + one history entry and produce a console namespace synced via assert_session_synced.
Console: replayed [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, "retrieve", 1) produces the same end state as the GUI _retrieve_dataset path.
Saved-flag propagation: a triple write through apply_dataset_state(..., mark_saved=True) sets EEG["saved"] = "yes" and ALLEEG[i-1]["saved"] = "yes" for every entry in CURRENTSET.
Open questions for reviewer
Helper name: apply_dataset_state vs replace_dataset_state vs broadening store_current with a replace_alleeg=True flag. I lean toward a new method because store_current currently adds/updates one selected dataset in-place via eeg_store, whereas the bypass sites replace the entire ALLEEG with a producer-supplied list. Conflating the two would muddy store_current.
Should apply_dataset_state also accept a mark_saved default of True for the _commit_processed_dataset_from_gui path (post-pop_newset "overwrite" semantics)? EEGLAB marks the committed dataset saved after overwrite; current GUI code does not.
pop_runscript namespace re-import touches STUDY and dataset state together. Acceptable to route through apply_dataset_state + set_study back-to-back (two notifies), or do you want a combined apply_workspace_state(eeg=…, alleeg=…, currentset=…, study=…, currentstudy=…) that fires one notify?
visual_capture.py:380 direct STUDY write is purely a fixture-builder. Leave or fold in?
Once these are settled I will implement on agent/20260610-fix-179.
Activity
claude commentedon Jun 10, 2026
🤖 Plan:
Scope is multi-module (>100 lines once helper + 13 call-site rewrites + tests land), so per the agent workflow I am posting analysis for human review before implementation.
Research
The canonical commit path is
EEGPrepSession.store_current(session.py#L174-L213) — it routes througheeg_store, normalizes CURRENTSET, appends per-datasetEEG.history, optionally markssaved="yes", appends ALLCOM/LASTCOM once, and firesnotify_changedonce. Every directself.session.ALLEEG = …/self.session.EEG = …/self.session.CURRENTSET = …triple bypass skips:eeg_storevalidation/dataset-shape checks (dict vs list of dicts),_append_current_dataset_historyper-datasetEEG.historyupdates,mark_savedpropagation, and CURRENTSET normalization (the GUI sites use a local_currentset_listhelper that does not de-duplicate or validate 1-based indices the waynormalize_dataset_indicesdoes). Direct STUDY writes also skipset_study's CURRENTSTUDY coupling and history wiring.Direct-write sites (all bypass session helpers):
menu_actions.py#L1044-L1062—_apply_extension_resulttriple writemenu_actions.py#L1552-L1584—_commit_processed_dataset_from_guitriple write + double historymenu_actions.py#L1357-L1368—_copy_current_datasettriple writemenu_actions.py#L908-L914—pop_runscriptnamespace re-import (EEG/ALLEEG/CURRENTSET/STUDY)menu_actions.py#L944-L946,#L1534-L1545— STUDY-only writes (BIDS edit, chanplot)menu_actions.py#L1590-L1598—_retrieve_datasetdirect CURRENTSTUDY zeroingconsole.py#L399-L424—accept_pop_resultdataset-state branch triple writeconsole.py#L355-L395—after_executeper-field writes (ALLEEG, CURRENTSET=[], STUDY, CURRENTSTUDY)visual_capture.py#L378-L391— test/demo STUDY+CURRENTSTUDY direct write (acceptable as fixture, optional cleanup)Proposed approach
1. Extend
EEGPrepSessionwith two session-owned helpers. Keepstore_current/retrieve/set_study/delete_currentas-is; add the missing primitive that the bypass sites actually need:apply_dataset_stateis the bulk-replace primitive — used when an external producer (extension,pop_newsetcommit,pop_copyset, consolepop_*accept) returns a full(ALLEEG, EEG, CURRENTSET)tuple that should overwrite the session in one shot. It usesnormalize_dataset_indices(not GUI's local_currentset_list), so console and GUI converge on the same validation.2. Extend
set_studyto accept an explicit CURRENTSTUDY override so console'sCURRENTSTUDY = 0/1assignment and_retrieve_dataset'sCURRENTSTUDY = 0no longer need direct field writes:3. Replace every direct-write site with
apply_dataset_state/set_study/clear_current_selection. Net per-site delta: 4–5 lines → 1 call. The_commit_processed_dataset_from_guisite additionally drops its duplicateadd_history(command)(command was already appended before thepop_newsetcall) by passingcommand=newset_commandtoapply_dataset_stateonce.4.
console.after_executekeeps its per-field detection, but when all of ALLEEG/EEG/CURRENTSET targets are present together (the common case for replayed[ALLEEG EEG CURRENTSET] = pop_newset(…)history), route throughapply_dataset_stateinstead of three independent writes + a separateretrievecall.5. Tests (extend
tests/test_session_contracts.pyandtests/test_console_workspace.py):apply_dataset_staterejects mismatched CURRENTSET / EEG-list lengths, normalizes scalar vs list CURRENTSET, firesnotify_changedexactly once (counter on a registered listener), appends LASTCOM/ALLCOM exactly once._apply_extension_result,_commit_processed_dataset_from_gui,_copy_current_dataseteach fire one notify + one history entry and produce a console namespace synced viaassert_session_synced.[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, "retrieve", 1)produces the same end state as the GUI_retrieve_datasetpath.apply_dataset_state(..., mark_saved=True)setsEEG["saved"] = "yes"andALLEEG[i-1]["saved"] = "yes"for every entry in CURRENTSET.Open questions for reviewer
apply_dataset_statevsreplace_dataset_statevs broadeningstore_currentwith areplace_alleeg=Trueflag. I lean toward a new method becausestore_currentcurrently adds/updates one selected dataset in-place viaeeg_store, whereas the bypass sites replace the entire ALLEEG with a producer-supplied list. Conflating the two would muddystore_current.apply_dataset_statealso accept amark_saveddefault ofTruefor the_commit_processed_dataset_from_guipath (post-pop_newset"overwrite" semantics)? EEGLAB marks the committed dataset saved after overwrite; current GUI code does not.pop_runscriptnamespace re-import touches STUDY and dataset state together. Acceptable to route throughapply_dataset_state+set_studyback-to-back (two notifies), or do you want a combinedapply_workspace_state(eeg=…, alleeg=…, currentset=…, study=…, currentstudy=…)that fires one notify?visual_capture.py:380direct STUDY write is purely a fixture-builder. Leave or fold in?Once these are settled I will implement on
agent/20260610-fix-179.