Skip to content

Commit 6e3c0d1

Browse files
fix(api): stop-requested hanging on stop when awaiting-recovery (#15066)
1 parent 4635d72 commit 6e3c0d1

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

api/src/opentrons/protocol_engine/state/commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ def handle_action(self, action: Action) -> None: # noqa: C901
362362

363363
elif isinstance(action, StopAction):
364364
if not self._state.run_result:
365+
if self._state.queue_status == QueueStatus.AWAITING_RECOVERY:
366+
self._state.recovery_target_command_id = None
367+
365368
self._state.queue_status = QueueStatus.PAUSED
366369
if action.from_estop:
367370
self._state.stopped_by_estop = True

api/tests/opentrons/protocol_engine/state/test_command_store_old.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,41 @@ def test_command_store_handles_stop_action(
638638
assert subject.state.command_history.get_setup_queue_ids() == OrderedSet()
639639

640640

641+
def test_command_store_handles_stop_action_when_awaiting_recovery() -> None:
642+
"""It should mark the engine as non-gracefully stopped on StopAction."""
643+
subject = CommandStore(is_door_open=False, config=_make_config())
644+
645+
subject.handle_action(
646+
PlayAction(
647+
requested_at=datetime(year=2021, month=1, day=1), deck_configuration=[]
648+
)
649+
)
650+
651+
subject.state.queue_status = QueueStatus.AWAITING_RECOVERY
652+
653+
subject.handle_action(StopAction())
654+
655+
assert subject.state == CommandState(
656+
command_history=CommandHistory(),
657+
queue_status=QueueStatus.PAUSED,
658+
run_result=RunResult.STOPPED,
659+
run_completed_at=None,
660+
is_door_blocking=False,
661+
run_error=None,
662+
finish_error=None,
663+
failed_command=None,
664+
command_error_recovery_types={},
665+
recovery_target_command_id=None,
666+
run_started_at=datetime(year=2021, month=1, day=1),
667+
latest_protocol_command_hash=None,
668+
stopped_by_estop=False,
669+
)
670+
assert subject.state.command_history.get_running_command() is None
671+
assert subject.state.command_history.get_all_ids() == []
672+
assert subject.state.command_history.get_queue_ids() == OrderedSet()
673+
assert subject.state.command_history.get_setup_queue_ids() == OrderedSet()
674+
675+
641676
def test_command_store_cannot_restart_after_should_stop() -> None:
642677
"""It should reject a play action after finish."""
643678
subject = CommandStore(is_door_open=False, config=_make_config())

0 commit comments

Comments
 (0)