Skip to content

Commit

Permalink
fix(api): Fix certain failed runs showing a stale recovery target (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring authored Oct 29, 2024
1 parent 272c4b6 commit b27a22c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/src/opentrons/protocol_engine/state/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ def _handle_resume_from_recovery_action(
def _handle_stop_action(self, action: StopAction) -> None:
if not self._state.run_result:
self._state.recovery_target = None

self._state.queue_status = QueueStatus.PAUSED

if action.from_estop:
self._state.stopped_by_estop = True
self._state.run_result = RunResult.FAILED
Expand All @@ -460,7 +460,9 @@ def _handle_stop_action(self, action: StopAction) -> None:

def _handle_finish_action(self, action: FinishAction) -> None:
if not self._state.run_result:
self._state.recovery_target = None
self._state.queue_status = QueueStatus.PAUSED

if action.set_run_status:
self._state.run_result = (
RunResult.SUCCEEDED
Expand Down
52 changes: 52 additions & 0 deletions api/tests/opentrons/protocol_engine/state/test_command_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,58 @@ def test_recovery_target_tracking() -> None:
assert subject_view.get_has_entered_recovery_mode() is True


@pytest.mark.parametrize(
"ending_action",
[
actions.StopAction(from_estop=False),
actions.StopAction(from_estop=True),
actions.FinishAction(set_run_status=False),
actions.FinishAction(
set_run_status=True,
error_details=actions.FinishErrorDetails(
error=Exception("blimey"),
error_id="error-id",
created_at=datetime.now(),
),
),
],
)
def test_recovery_target_clears_when_run_ends(ending_action: actions.Action) -> None:
"""There should never be an error recovery target when the run is done."""
subject = CommandStore(
config=_make_config(),
error_recovery_policy=_placeholder_error_recovery_policy,
is_door_open=False,
)
subject_view = CommandView(subject.state)

# Setup: Put the run in error recovery mode.
queue = actions.QueueCommandAction(
"c1",
created_at=datetime.now(),
request=commands.CommentCreate(params=commands.CommentParams(message="")),
request_hash=None,
)
subject.handle_action(queue)
run = actions.RunCommandAction(command_id="c1", started_at=datetime.now())
subject.handle_action(run)
fail = actions.FailCommandAction(
command_id="c1",
error_id="c1-error",
failed_at=datetime.now(),
error=PythonException(RuntimeError()),
notes=[],
type=ErrorRecoveryType.WAIT_FOR_RECOVERY,
running_command=subject_view.get("c1"),
)
subject.handle_action(fail)

# Test: Assert that the ending action clears the recovery target.
assert subject_view.get_recovery_target() is not None
subject.handle_action(ending_action)
assert subject_view.get_recovery_target() is None


def test_final_state_after_estop() -> None:
"""Test the final state of the run after it's E-stopped."""
subject = CommandStore(
Expand Down

0 comments on commit b27a22c

Please sign in to comment.