Repository navigation
Description
Context
tests/test_eeglab_hybrid.py::test_matlab_tutorial_figures_retain_their_plot_target_between_calls fails in the MATLAB batch reference environment on develop independently of the stream PRs.
Evidence was read from [email protected] (jamming), under /home/suraj3/eegprep-bench/logs/:
| Run | Evidence | Observed parent / requested figure |
|---|---|---|
Develop, 1bdd1a28353a4dfd51ffacd7b327443836de7f29 |
s11_ref/rerun_hybrid_develop.log |
1 / 2; 1 failed in 5.11 s |
S11, 8a02dd79a23cd1cb62dc4d9e84b2df94a94620fb, isolated |
s11_ref/rerun_hybrid_tip.log |
1 / 2; 1 failed in 5.11 s |
S9, 74519da7804f9b6dd5e2923918e805fcc4d782d4, full hybrid shard |
s9_ref/hybrid.pytest.log, s9_ref/junit_hybrid.xml |
1 / 2 |
| S11, full hybrid shard | s11_ref/hybrid.pytest.log, s11_ref/junit_hybrid.xml |
2 / 4 |
s11_ref/loose_ends3.out:109 records the develop SHA for the isolated run. Both isolated reruns used fresh batch servers, as shown by s11_ref/run_s11_loose_ends3.sh. The launcher used an R2025b preference directory with DISPLAY, WAYLAND_DISPLAY, and XAUTHORITY unset.
The S5 hybrid log at 585a4463d7afa45e4d6434336d2f714a33024a04 records this test passing (s5_ref/hybrid.pytest.log:149). The isolated 1 / 2 failure repeats in the supplied reruns; the broader evidence also shows sensitivity to execution context and figure state.
Reference pins: EEGLAB d0963be9d81acc5b66e84f8d3d7c89e3ce127cc4, eeglab_tests fec88f9ffe7c225eb1de8924db8b6a3e0d53a4d9. Local source inspection used 64e8d2fe6eb903945407c00f11f610a7552fe42c; the failing test and tutorial-figure helper are unchanged from 1bdd1a28. No MATLAB session was started during this investigation.
Repro steps
- Use develop and the pinned reference checkouts. Match the recorded headless batch environment, with
EEGPREP_MATLAB_BATCH_DIRpointing to its configured server directory. - For a future reproduction on jamming, hold
flock ~/eegprep-bench/matlab.lockfor the entire MATLAB session and test execution, with one MATLAB session at a time. The existingrun_s11_loose_ends3.shdocuments the original environment and server setup. - In that configured environment, run the isolated command recorded by the script:
uv run --no-sync pytest -vv \
--eeglab-backend=matlab \
--eeglab-root="$HOME/eegprep-bench/eeglab" \
--eeglab-suite-root="$HOME/eegprep-bench/eeglab_tests" \
--timeout=1200 --timeout-method=signal -p no:cacheprovider \
tests/test_eeglab_hybrid.py::test_matlab_tutorial_figures_retain_their_plot_target_between_callsThe test temporarily sets DefaultFigureVisible to on. For each of four figures, it sends separate requests to create a figure, plot two points, retrieve gca, and retrieve that axes object's Parent. It asserts equality with the newly created figure handle, then closes figures and restores visibility in finally.
Observed
The isolated develop log reports eeglab_matlab_engine = <tests.matlab_batch_engine.BatchEngine ...> and fails at tests/test_eeglab_hybrid.py:683:
> np.testing.assert_array_equal(parent, figure)
E AssertionError:
E Arrays are not equal
E Mismatched elements: 1 / 1 (100%)
E Max absolute difference among violations: 1.
E Max relative difference among violations: 0.5
E ACTUAL: array([[1.]])
E DESIRED: array([[2.]])
The requested figure and subsequently inspected current axes disagree. The assertion alone cannot establish whether plot used the wrong figure or whether the current figure changed between plotting and the later gca request.
Expected
Across the separate calls, each new tutorial figure retains its intended plotting target. Its plotted axes have that figure as their parent, and gca refers to those axes. All four comparisons pass exactly, while cleanup restores the original figure visibility.
Likely root cause
The reference harness relies on implicit MATLAB graphics state surviving independent requests. Delayed figure activation or graphics callbacks can change groot.CurrentFigure after the helper returns. The headless batch server processes intervening waits, and later plot and gca calls have no explicit target.
Relevant code paths, with line numbers at 64e8d2fe:
tests/test_eeglab_hybrid.py:673-686: figure creation, plotting, current-axes query, parent assertion, and cleanup.tests/eeglab_tests/backend.py:179-202->tests/matlab/eegprep_test_call.m:1-14: eachcall_matlabis a separate transport request that invokes the requested MATLAB function.tests/matlab/eegprep_test_tutorial_figure.m:3-6: callsfigure,drawnow, andset(groot, 'CurrentFigure', figure_handle)before returning the numeric handle. This only establishes the current figure at that instant.tests/matlab/eegprep_test_gui_handle.m:3: returnsdouble(feval(function_name, varargin{:})), so thegcarequest reads whichever figure is current then.tests/matlab/eegprep_batch_engine_serve.m:11-24andtests/matlab_batch_engine.py:186-191: serverpause(0.01)and client request waits separate the graphics operations.tests/test_tutorial_eeglab_tests.py:106-110: tutorial reference cases also use this MATLAB figure helper.
This points to the MATLAB reference harness and graphics lifecycle. The failing path invokes MATLAB figure, plot, gca, and get through EEGPrep's test helpers; no EEGPrep Qt dialog is involved. Graphics callbacks are a hypothesis from source and logs. Instrument CurrentFigure before and after each request and inspect the actual plotted line's axes/figure ancestry to establish exactly when the target changes. Compare visible and hidden figures and batch versus native Engine execution when a reference session is available.
Definition of done
- Identify the precise state transition that changes the intended figure or current axes, with evidence from the recorded headless batch configuration.
- Repair the helper or transport state handling so tutorial plotting retains its target across separate calls. Keep the exact handle assertion and the visible-figure scenario.
- Pass the exact isolated node repeatedly from fresh sessions, then pass it in the complete hybrid shard and relevant tutorial reference tests.
- Preserve
test_matlab_reference_figures_stay_off_desktop, restoreDefaultFigureVisible, and leave no figures behind after success or failure. - Record MATLAB version, transport, display configuration, reference pins, and test results. Preserve all numerical tolerances.
Activity
claude commentedon Nov 8, 2026
🤖 Plan:
No PR: the definition of done requires MATLAB evidence from the jamming batch environment, which this runner cannot produce. Analysis for a human below.
Research
In the isolated run the first figure created by the test is number 2, so figure 1 was still alive when
eegprep_test_tutorial_figureran. The only figure created earlier in that fresh session is thefigure_visibilityprobe the test itself calls first, which closes its figure viaonCleanupaftervarargoutis assigned. In every recorded failure the plot lands on an older figure (1/2 isolated, 2/4 in the S11 shard), i.e. the axes ancestry follows a lingering earlier figure, not the requested one. Hypothesis: under headless R2025b (noDISPLAY), the probe's close is not finalized (or a deferred activation of figure 1 fires) after the helper'sset(groot,'CurrentFigure',h), and the next untargetedplot/gcarequest picks figure 1.Relevant code
tests/test_eeglab_hybrid.py#L672-L686- probe call, then figure/plot/gca/Parent looptests/matlab/eegprep_test_transport.m#L49-L52- probe figure closed byonCleanuptests/matlab/eegprep_test_tutorial_figure.m-figure; drawnow; set CurrentFigure, no axestests/matlab/eegprep_batch_engine_serve.m#L11-L24-pause(0.01)lets queued graphics events run between requeststests/test_tutorial_eeglab_tests.py#L106-L110- tutorial tests share the helperProposed Fix
double(groot.CurrentFigure),double(findall(groot,'Type','figure'))'and, afterplot,ancestor(h,'figure')of the returned line. Run once with the probe call removed to test the lingering-figure-1 hypothesis directly.delete(figure_handle); drawnow;explicitly before returning instead of relying ononCleanup, so no stale figure survives into the next request.Keep the exact
parent == figureassertion and theDefaultFigureVisible='on'scenario;close all forceplus the visibility restore infinallyalready cover cleanup.Open question: if instrumentation shows
CurrentFigureflipping during the server'spause(deferred activation rather than a lingering figure), step 3 alone may not suffice and the batch server shoulddrawnowafter each request before writing the response.