Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): Fix improper transitioning run status in protocol runs #14454

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8271,6 +8271,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -8373,6 +8374,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -8475,6 +8477,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -8577,6 +8580,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -8679,6 +8683,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -8781,6 +8786,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -8883,6 +8889,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -8985,6 +8992,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -9087,6 +9095,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -9189,6 +9198,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -9291,6 +9301,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -9393,6 +9404,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -9641,6 +9653,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": false,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -10316,6 +10329,7 @@
"addressableAreaName": "movableTrashB3",
"alternateDropLocation": false,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10514,6 +10514,7 @@
"addressableAreaName": "movableTrashC1",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -10758,6 +10759,7 @@
"addressableAreaName": "movableTrashD1",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,7 @@
"addressableAreaName": "movableTrashC3",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11102,6 +11102,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": false,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -11137,6 +11138,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": false,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -11216,6 +11218,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": false,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -11295,6 +11298,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": false,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -11374,6 +11378,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": false,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -11453,6 +11458,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": false,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -11532,6 +11538,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": false,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -11561,6 +11568,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -14985,6 +14993,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -15186,6 +15195,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -15263,6 +15273,7 @@
"addressableAreaName": "fixedTrash",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12283,6 +12283,7 @@
"addressableAreaName": "movableTrashC1",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -12527,6 +12528,7 @@
"addressableAreaName": "movableTrashD1",
"alternateDropLocation": true,
"forceDirect": false,
"ignoreTipConfiguration": true,
"offset": {
"x": 0.0,
"y": 0.0,
Expand Down
8 changes: 5 additions & 3 deletions app/src/organisms/RunTimeControl/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ export function useRunStatus(
refetchInterval: DEFAULT_STATUS_REFETCH_INTERVAL,
enabled:
lastRunStatus.current == null ||
!([RUN_STATUS_FAILED, RUN_STATUS_SUCCEEDED] as RunStatus[]).includes(
lastRunStatus.current
),
!([
RUN_STATUS_FAILED,
RUN_STATUS_SUCCEEDED,
RUN_STATUS_STOP_REQUESTED,
] as RunStatus[]).includes(lastRunStatus.current),
onSuccess: data => (lastRunStatus.current = data?.data?.status ?? null),
...options,
})
Expand Down
2 changes: 1 addition & 1 deletion app/src/resources/runs/useNotifyRunQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function useNotifyRunQuery<TError = Error>(
const { isNotifyError } = useNotifyService({
topic: `robot-server/runs/${runId}` as NotifyTopic,
refetchUsingHTTP: () => setRefetchUsingHTTP(true),
options,
options: { ...options, enabled: options.enabled && runId != null },
})

const isNotifyEnabled = !isNotifyError && !options?.forceHttpPolling
Expand Down
30 changes: 17 additions & 13 deletions app/src/resources/useNotifyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,37 @@ export function useNotifyService<TData, TError = Error>({
const host = useHost()
const isNotifyError = React.useRef(false)
const doTrackEvent = useTrackEvent()
const { enabled, refetchInterval, forceHttpPolling } = options
const isRefetchEnabled =
refetchInterval !== undefined && refetchInterval !== false
const { enabled, staleTime, forceHttpPolling } = options
const hostname = host?.hostname ?? null

React.useEffect(() => {
// Always fetch on initial mount.
refetchUsingHTTP()
if (!forceHttpPolling && isRefetchEnabled && enabled !== false) {
const hostname = host?.hostname ?? null
if (
!forceHttpPolling &&
enabled !== false &&
hostname != null &&
staleTime !== Infinity
) {
const eventEmitter = appShellListener(hostname, topic)

eventEmitter.on('data', onDataListener)

if (hostname != null) {
dispatch(notifySubscribeAction(hostname, topic))
} else {
console.error('NotifyService expected hostname, received null.')
}
dispatch(notifySubscribeAction(hostname, topic))

return () => {
eventEmitter.off('data', onDataListener)
if (hostname != null) {
dispatch(notifyUnsubscribeAction(hostname, topic))
}
}
} else {
if (hostname == null) {
console.error(
'NotifyService expected hostname, received null for topic:',
topic
)
}
}
}, [topic])
}, [topic, host])

return { isNotifyError: isNotifyError.current }

Expand Down
4 changes: 4 additions & 0 deletions react-api-client/src/runs/useAllRunsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export type UseAllRunsQueryOptions = UseQueryOptions<
Array<string | HostConfig>
>

/**
* @property {HostConfig | null | undefined} hostOverride:
* When using all runs query outside of the host context provider, we must specify the host manually.
*/
export function useAllRunsQuery(
params: GetRunsParams = {},
options: UseAllRunsQueryOptions = {},
Expand Down
11 changes: 5 additions & 6 deletions robot-server/robot_server/runs/run_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ async def create(
EngineConflictError: There is a currently active run that cannot
be superceded by this new run.
"""
await self._runs_publisher.begin_polling_engine_store(
get_current_command=self.get_current_command,
get_state_summary=self._get_state_summary,
run_id=run_id,
)
prev_run_id = self._engine_store.current_run_id
if prev_run_id is not None:
prev_run_result = await self._engine_store.clear()
Expand All @@ -120,7 +125,6 @@ async def create(
summary=prev_run_result.state_summary,
commands=prev_run_result.commands,
)

state_summary = await self._engine_store.create(
run_id=run_id,
labware_offsets=labware_offsets,
Expand All @@ -132,11 +136,6 @@ async def create(
created_at=created_at,
protocol_id=protocol.protocol_id if protocol is not None else None,
)
await self._runs_publisher.begin_polling_engine_store(
get_current_command=self.get_current_command,
get_state_summary=self._get_state_summary,
run_id=run_id,
)

return _build_run(
run_resource=run_resource,
Expand Down
1 change: 1 addition & 0 deletions robot-server/robot_server/runs/run_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ def remove(self, run_id: str) -> None:
raise RunNotFoundError(run_id)

self._clear_caches()
self._runs_publisher.publish_runs(run_id=run_id)

def _run_exists(
self, run_id: str, connection: sqlalchemy.engine.Connection
Expand Down
Loading
Loading