Skip to content

Commit

Permalink
fix(app): fix post run tip detection after error recovery (#16860)
Browse files Browse the repository at this point in the history
Closes RQA-3589

It's insufficient to check if a run entered error recovery as the sole condition for whether or not to run the post-run drop tip wizard, because it's possible for a run to proceed through error recovery then encounter a terminal error. In these spots, we must show drop tip wizard.

To fix, determine whether the run just entered error recovery (or not). If it didn't, do the tip detection logic.
  • Loading branch information
mjhuff authored Nov 15, 2024
1 parent c90aaea commit 6d5b3a2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/src/local-resources/commands/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './getCommandTextData'
export * from './lastRunCommandPromptedErrorRecovery'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { RunCommandSummary } from '@opentrons/api-client'

// Whether the last run protocol command prompted Error Recovery.
export function lastRunCommandPromptedErrorRecovery(
summary: RunCommandSummary[]
): boolean {
const lastProtocolCommand = summary.findLast(
command => command.intent !== 'fixit' && command.error != null
)

// All recoverable protocol commands have defined errors.
return lastProtocolCommand?.error?.isDefined ?? false
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import {
useTipAttachmentStatus,
} from '/app/organisms/DropTipWizardFlows'
import { useProtocolDropTipModal } from '../modals'
import { useCloseCurrentRun, useIsRunCurrent } from '/app/resources/runs'
import {
useCloseCurrentRun,
useCurrentRunCommands,
useIsRunCurrent,
} from '/app/resources/runs'
import { isTerminalRunStatus } from '../../utils'
import { lastRunCommandPromptedErrorRecovery } from '/app/local-resources/commands'

import type { RobotType } from '@opentrons/shared-data'
import type { Run, RunStatus } from '@opentrons/api-client'
Expand Down Expand Up @@ -102,6 +107,15 @@ export function useRunHeaderDropTip({
: { showDTWiz: false, dtWizProps: null }
}

const runSummaryNoFixit = useCurrentRunCommands(
{
includeFixitCommands: false,
pageLength: 1,
cursor: null,
},
{ enabled: isTerminalRunStatus(runStatus) }
)

// Manage tip checking
useEffect(() => {
// If a user begins a new run without navigating away from the run page, reset tip status.
Expand All @@ -111,11 +125,14 @@ export function useRunHeaderDropTip({
}
// Only determine tip status when necessary as this can be an expensive operation. Error Recovery handles tips, so don't
// have to do it here if done during Error Recovery.
else if (isTerminalRunStatus(runStatus) && !enteredER) {
else if (
runSummaryNoFixit != null &&
!lastRunCommandPromptedErrorRecovery(runSummaryNoFixit)
) {
void determineTipStatus()
}
}
}, [runStatus, robotType, enteredER])
}, [runStatus, robotType, runSummaryNoFixit])

// TODO(jh, 08-15-24): The enteredER condition is a hack, because errorCommands are only returned when a run is current.
// Ideally the run should not need to be current to view errorCommands.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ function getCommandsExecutedDuringRun(
})
}

const TIP_EXCHANGE_COMMAND_TYPES = ['dropTip', 'dropTipInPlace', 'pickUpTip']
const TIP_EXCHANGE_COMMAND_TYPES = [
'dropTip',
'dropTipInPlace',
'pickUpTip',
'moveToAddressableAreaForDropTip',
]

function checkPipettesForAttachedTips(
commands: RunCommandSummary[],
Expand Down
16 changes: 14 additions & 2 deletions app/src/pages/ODD/RunSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ import {
useRunCreatedAtTimestamp,
useCloseCurrentRun,
EMPTY_TIMESTAMP,
useCurrentRunCommands,
} from '/app/resources/runs'
import {
useTipAttachmentStatus,
handleTipsAttachedModal,
} from '/app/organisms/DropTipWizardFlows'
import { lastRunCommandPromptedErrorRecovery } from '/app/local-resources/commands'

import type { IconName } from '@opentrons/components'
import type { OnDeviceRouteParams } from '/app/App/types'
Expand Down Expand Up @@ -238,11 +240,21 @@ export function RunSummary(): JSX.Element {
})

// Determine tip status on initial render only. Error Recovery always handles tip status, so don't show it twice.
const runSummaryNoFixit = useCurrentRunCommands({
includeFixitCommands: false,
pageLength: 1,
cursor: null,
})
useEffect(() => {
if (isRunCurrent && enteredER === false) {
if (
isRunCurrent &&
runSummaryNoFixit != null &&
!lastRunCommandPromptedErrorRecovery(runSummaryNoFixit)
) {
console.log('HITTING THIS')
void determineTipStatus()
}
}, [isRunCurrent, enteredER])
}, [runSummaryNoFixit, isRunCurrent])

const returnToQuickTransfer = (): void => {
closeCurrentRunIfValid(() => {
Expand Down

0 comments on commit 6d5b3a2

Please sign in to comment.