11import { db } from '@sim/db'
22import { pausedExecutions , workflow } from '@sim/db/schema'
3- import { and , eq , inArray , isNull , sql } from 'drizzle-orm'
3+ import { and , eq , inArray , isNull } from 'drizzle-orm'
44import {
55 type CursorKey ,
66 encodeKeyset ,
@@ -14,7 +14,7 @@ import {
1414 resumeKeyset ,
1515 textKey ,
1616} from '@/lib/api/list-query'
17- import { PAUSE_POINT_ROWS } from '@/lib/workflows/executor/pause-point-sql'
17+ import { somePausePointMatches } from '@/lib/workflows/executor/pause-point-sql'
1818
1919/** A paused run of an active workflow, with the raw `pause_points` its detail is built from. */
2020interface WorkspacePausedRunRow {
@@ -32,12 +32,15 @@ const PAUSED_RUN_KEYS: readonly KeysetKey<WorkspacePausedRunRow>[] = [
3232 textKey ( pausedExecutions . id , ( row ) => row . id ) ,
3333]
3434
35- /** Whether `point.value` is a pause point still waiting on a human, with `mapPausePoints`' defaults. */
36- const POINT_WAITS_ON_HUMAN = sql `coalesce(point.value ->> 'pauseKind', 'human') <> 'time'
37- and coalesce(point.value ->> 'resumeStatus', 'paused') = 'paused'`
35+ /**
36+ * A pause point still waiting on a human, with `mapPausePoints`' defaults: a missing or null
37+ * `pauseKind` reads `human` and a missing or null `resumeStatus` reads `paused`.
38+ */
39+ const POINT_WAITS_ON_HUMAN =
40+ '!(@.pauseKind.type() == "string" && @.pauseKind == "time") && (!exists(@.resumeStatus) || @.resumeStatus == null || (@.resumeStatus.type() == "string" && @.resumeStatus == "paused"))'
3841
3942/** A paused run with a pause point still waiting on a human. */
40- const WAITS_ON_HUMAN = sql `exists (select 1 from ${ PAUSE_POINT_ROWS } where ${ POINT_WAITS_ON_HUMAN } )`
43+ const WAITS_ON_HUMAN = somePausePointMatches ( POINT_WAITS_ON_HUMAN )
4144
4245/** The cursor that resumes the list after `row`. */
4346export function pausedRunCursorKeys ( row : WorkspacePausedRunRow ) : CursorKey [ ] {
0 commit comments