From 6e3c0d1827524ec55d68abc20235583e0321439c Mon Sep 17 00:00:00 2001 From: TamarZanzouri Date: Wed, 1 May 2024 14:51:19 -0400 Subject: [PATCH] fix(api): stop-requested hanging on stop when awaiting-recovery (#15066) --- .../protocol_engine/state/commands.py | 3 ++ .../state/test_command_store_old.py | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/api/src/opentrons/protocol_engine/state/commands.py b/api/src/opentrons/protocol_engine/state/commands.py index f9d7643b728..7500b16d631 100644 --- a/api/src/opentrons/protocol_engine/state/commands.py +++ b/api/src/opentrons/protocol_engine/state/commands.py @@ -362,6 +362,9 @@ def handle_action(self, action: Action) -> None: # noqa: C901 elif isinstance(action, StopAction): if not self._state.run_result: + if self._state.queue_status == QueueStatus.AWAITING_RECOVERY: + self._state.recovery_target_command_id = None + self._state.queue_status = QueueStatus.PAUSED if action.from_estop: self._state.stopped_by_estop = True diff --git a/api/tests/opentrons/protocol_engine/state/test_command_store_old.py b/api/tests/opentrons/protocol_engine/state/test_command_store_old.py index 60cdf27838f..7f376a0b019 100644 --- a/api/tests/opentrons/protocol_engine/state/test_command_store_old.py +++ b/api/tests/opentrons/protocol_engine/state/test_command_store_old.py @@ -638,6 +638,41 @@ def test_command_store_handles_stop_action( assert subject.state.command_history.get_setup_queue_ids() == OrderedSet() +def test_command_store_handles_stop_action_when_awaiting_recovery() -> None: + """It should mark the engine as non-gracefully stopped on StopAction.""" + subject = CommandStore(is_door_open=False, config=_make_config()) + + subject.handle_action( + PlayAction( + requested_at=datetime(year=2021, month=1, day=1), deck_configuration=[] + ) + ) + + subject.state.queue_status = QueueStatus.AWAITING_RECOVERY + + subject.handle_action(StopAction()) + + assert subject.state == CommandState( + command_history=CommandHistory(), + queue_status=QueueStatus.PAUSED, + run_result=RunResult.STOPPED, + run_completed_at=None, + is_door_blocking=False, + run_error=None, + finish_error=None, + failed_command=None, + command_error_recovery_types={}, + recovery_target_command_id=None, + run_started_at=datetime(year=2021, month=1, day=1), + latest_protocol_command_hash=None, + stopped_by_estop=False, + ) + assert subject.state.command_history.get_running_command() is None + assert subject.state.command_history.get_all_ids() == [] + assert subject.state.command_history.get_queue_ids() == OrderedSet() + assert subject.state.command_history.get_setup_queue_ids() == OrderedSet() + + def test_command_store_cannot_restart_after_should_stop() -> None: """It should reject a play action after finish.""" subject = CommandStore(is_door_open=False, config=_make_config())