Skip to content

Commit e46bc84

Browse files
authored
improvement(resume): resolve a pause point's block from its loop-scoped context id (#10119)
1 parent f7d1210 commit e46bc84

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎apps/sim/executor/utils/subflow-node-id-codec.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ export function normalizeLookupId(id: string): string {
247247
return id.replace(BRANCH.SUFFIX_GLOBAL, '').replace(LOOP_DIGEST.STRIP, '')
248248
}
249249

250+
/**
251+
* Strips loop digests (`_loopN`) from an ID, e.g. a pause context ID scoped to a loop iteration.
252+
*/
253+
export function stripLoopDigest(id: string): string {
254+
return id.replace(LOOP_DIGEST.STRIP, '')
255+
}
256+
250257
/**
251258
* Returns the leading branch subscript (`₍N₎`) of a node ID, or '' when absent.
252259
*/

‎apps/sim/lib/workflows/executor/human-in-the-loop-manager.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import type {
8181
import { hasExecutionResult } from '@/executor/utils/errors'
8282
import { filterOutputForLog } from '@/executor/utils/output-filter'
8383
import { projectResolvedSecretDiagnosticError } from '@/executor/utils/resolved-secret-content-projection'
84+
import { stripLoopDigest } from '@/executor/utils/subflow-node-id-codec'
8485
import type { SerializedConnection } from '@/serializer/types'
8586

8687
/**
@@ -3920,7 +3921,7 @@ export class PauseResumeManager {
39203921
return ''
39213922
}
39223923

3923-
const normalized = id.replace(/_loop\d+/g, '')
3924+
const normalized = stripLoopDigest(id)
39243925

39253926
return normalized || id
39263927
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { pauseBaseBlockId } from '@/lib/workflows/executor/pause-block-names'
3+
4+
describe('pauseBaseBlockId', () => {
5+
it.each([
6+
['a loop iteration', 'approval_loop2', 'approval'],
7+
['a parallel branch inside a loop', 'approval₍1₎_loop2', 'approval'],
8+
['a cloned subflow branch inside a loop', 'approval__obranch-3₍0₎_loop4', 'approval'],
9+
])('resolves the workflow block of a point keyed only by %s context', (_, contextId, base) => {
10+
expect(pauseBaseBlockId({ contextId })).toBe(base)
11+
})
12+
})

‎apps/sim/lib/workflows/executor/pause-block-names.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { db } from '@sim/db'
22
import { workflowDeploymentVersion, workflowExecutionLogs } from '@sim/db/schema'
33
import { and, eq, sql } from 'drizzle-orm'
44
import type { PausePoint } from '@/executor/types'
5-
import { stripCloneSuffixes } from '@/executor/utils/subflow-node-id-codec'
5+
import { stripCloneSuffixes, stripLoopDigest } from '@/executor/utils/subflow-node-id-codec'
66

77
type NameablePausePoint = Pick<PausePoint, 'blockId' | 'contextId' | 'blockName'>
88

9-
/** The workflow block a pause point waits on, without any parallel branch or subflow clone suffix. */
9+
/**
10+
* The workflow block a pause point waits on, without any loop iteration, parallel branch, or
11+
* subflow clone suffix. The loop digest goes first: a context ID ends in it (`block₍N₎_loopK`).
12+
*/
1013
export function pauseBaseBlockId(point: Pick<PausePoint, 'blockId' | 'contextId'>): string {
11-
return stripCloneSuffixes(point.blockId ?? point.contextId)
14+
return stripCloneSuffixes(stripLoopDigest(point.blockId ?? point.contextId))
1215
}
1316

1417
/**

0 commit comments

Comments
 (0)