From bf6f89636a5b3823ee5ca688d382515ed3ce7b94 Mon Sep 17 00:00:00 2001 From: x01dc Date: Fri, 18 Sep 2026 09:19:41 +0200 Subject: [PATCH] feat(flomni,lamni): clear tomo queue and reset progress on account change The account-change check already offered to reset scan parameters to defaults for a new experiment; extend it to also clear the tomo queue and reset acquisition progress, so a new account doesn't inherit leftover queued jobs or in-progress state from the previous account. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_0132KBoxsovfcMNRGJhS1Pbw --- .../bec_ipython_client/plugins/LamNI/lamni.py | 17 ++++++++++++----- .../bec_ipython_client/plugins/flomni/flomni.py | 15 +++++++++++---- .../test_lamni_account_change_reset.py | 10 ++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py index 226cd42b..785c02e4 100644 --- a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py +++ b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py @@ -273,15 +273,20 @@ class LamNI(TomoQueueMixin, LamNIAlignmentMixin, LamNIOpticsMixin, LamniGuiTools self._webpage_gen.start(force=True) def _maybe_reset_params_on_account_change(self) -> None: - """Offer a tomo-parameter reset when the active account has changed. + """Offer a tomo-parameter/queue/progress reset when the active + account has changed. Called at BEC session start. The account for which defaults were last applied is stored in the global var ``defaults_applied_for_account`` so it survives client restarts. Only a genuine change of account triggers the (interactive) reset; the same account is a silent no-op, so restarting a client within the same experiment never disturbs tuned - parameters. Mirrors Flomni._maybe_reset_params_on_account_change() - exactly. + parameters, the tomo queue, or in-progress acquisition state. Mirrors + Flomni._maybe_reset_params_on_account_change() exactly. + + On a confirmed reset, this also clears the tomo queue and resets tomo + acquisition progress (via tomo_queue_clear()/tomo_progress_reset()), + since both are leftover state from the previous account/experiment. """ bec = builtins.__dict__.get("bec") try: @@ -298,11 +303,13 @@ class LamNI(TomoQueueMixin, LamNIAlignmentMixin, LamNIOpticsMixin, LamniGuiTools if self.OMNYTools.yesno( f"New account '{account}' detected (previous: '{last_account}').\n" - "Reset tomo parameters to defaults for the new experiment?", + "Reset tomo parameters to defaults, clear the tomo queue, and " + "reset tomo acquisition progress for the new experiment?", "y", ): self._set_default_tomo_params() - print(f"Tomo parameters reset to defaults for account '{account}'.") + self.tomo_queue_clear() + self.tomo_progress_reset() self.client.set_global_var("defaults_applied_for_account", account) def _set_default_tomo_params(self) -> None: diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py index 933fbcb5..519d1bf7 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py @@ -1820,14 +1820,19 @@ class Flomni( self._webpage_gen.start(force=True) def _maybe_reset_params_on_account_change(self) -> None: - """Offer a tomo-parameter reset when the active account has changed. + """Offer a tomo-parameter/queue/progress reset when the active + account has changed. Called at BEC session start. The account for which defaults were last applied is stored in the global var ``defaults_applied_for_account`` so it survives client restarts. Only a genuine change of account triggers the (interactive) reset; the same account is a silent no-op, so restarting a client within the same experiment never disturbs tuned - parameters. + parameters, the tomo queue, or in-progress acquisition state. + + On a confirmed reset, this also clears the tomo queue and resets tomo + acquisition progress (via tomo_queue_clear()/tomo_progress_reset()), + since both are leftover state from the previous account/experiment. """ bec = builtins.__dict__.get("bec") try: @@ -1844,11 +1849,13 @@ class Flomni( if self.OMNYTools.yesno( f"New account '{account}' detected (previous: '{last_account}').\n" - "Reset tomo parameters to defaults for the new experiment?", + "Reset tomo parameters to defaults, clear the tomo queue, and " + "reset tomo acquisition progress for the new experiment?", "y", ): self._set_default_tomo_params() - print(f"Tomo parameters reset to defaults for account '{account}'.") + self.tomo_queue_clear() + self.tomo_progress_reset() self.client.set_global_var("defaults_applied_for_account", account) def _set_default_tomo_params(self) -> None: diff --git a/tests/tests_bec_ipython_client/test_lamni_account_change_reset.py b/tests/tests_bec_ipython_client/test_lamni_account_change_reset.py index fe2ce65d..85a6dc42 100644 --- a/tests/tests_bec_ipython_client/test_lamni_account_change_reset.py +++ b/tests/tests_bec_ipython_client/test_lamni_account_change_reset.py @@ -11,6 +11,7 @@ import types import csaxs_bec.bec_ipython_client.plugins.LamNI.lamni as lamni_module from csaxs_bec.bec_ipython_client.plugins.LamNI.lamni import LamNI, _ProgressProxy +from csaxs_bec.bec_ipython_client.plugins.OMNY_shared.tomo_queue_mixin import _TomoQueueProxy class FakeClient: @@ -55,6 +56,7 @@ def make_lamni(answer=True): obj = object.__new__(LamNI) obj.client = FakeClient() obj._progress_proxy = _ProgressProxy(obj.client) + obj._tomo_queue_proxy = _TomoQueueProxy(obj.client) obj.OMNYTools = FakeOMNYTools(answer=answer) obj.reconstructor = types.SimpleNamespace(folder_name=None) return obj @@ -87,6 +89,8 @@ def test_prompts_and_resets_on_new_account_when_confirmed(monkeypatch): lamni.client.set_global_var("defaults_applied_for_account", "e11111") lamni.tomo_shellstep = 99.0 lamni.tomo_circfov = 123.0 + lamni._tomo_queue_proxy.append({"label": "leftover job", "params": {}, "status": "pending"}) + lamni._progress_proxy.update(projection=42, angle=90.0) monkeypatch.setitem(builtins.__dict__, "bec", type("Bec", (), {"active_account": "e22222"})()) lamni._maybe_reset_params_on_account_change() @@ -97,18 +101,24 @@ def test_prompts_and_resets_on_new_account_when_confirmed(monkeypatch): assert lamni.tomo_shellstep == 1 assert lamni.tomo_circfov == 0.0 assert lamni.client.get_global_var("defaults_applied_for_account") == "e22222" + assert lamni._tomo_queue_proxy.as_list() == [] + assert lamni._progress_proxy.as_dict() == _ProgressProxy._DEFAULTS def test_records_account_without_resetting_when_declined(monkeypatch): lamni = make_lamni(answer=False) lamni.client.set_global_var("defaults_applied_for_account", "e11111") lamni.tomo_shellstep = 99.0 + lamni._tomo_queue_proxy.append({"label": "leftover job", "params": {}, "status": "pending"}) + lamni._progress_proxy.update(projection=42, angle=90.0) monkeypatch.setitem(builtins.__dict__, "bec", type("Bec", (), {"active_account": "e22222"})()) lamni._maybe_reset_params_on_account_change() assert lamni.tomo_shellstep == 99.0 assert lamni.client.get_global_var("defaults_applied_for_account") == "e22222" + assert len(lamni._tomo_queue_proxy.as_list()) == 1 + assert lamni._progress_proxy["projection"] == 42 def test_set_default_tomo_params_matches_getter_fallbacks():