diff --git a/apps/sim/executor/utils/subflow-node-id-codec.ts b/apps/sim/executor/utils/subflow-node-id-codec.ts index 4a62d3d89d3..cba4d83a6d3 100644 --- a/apps/sim/executor/utils/subflow-node-id-codec.ts +++ b/apps/sim/executor/utils/subflow-node-id-codec.ts @@ -247,6 +247,13 @@ export function normalizeLookupId(id: string): string { return id.replace(BRANCH.SUFFIX_GLOBAL, '').replace(LOOP_DIGEST.STRIP, '') } +/** + * Strips loop digests (`_loopN`) from an ID, e.g. a pause context ID scoped to a loop iteration. + */ +export function stripLoopDigest(id: string): string { + return id.replace(LOOP_DIGEST.STRIP, '') +} + /** * Returns the leading branch subscript (`₍N₎`) of a node ID, or '' when absent. */ diff --git a/apps/sim/lib/workflows/executor/human-in-the-loop-manager.ts b/apps/sim/lib/workflows/executor/human-in-the-loop-manager.ts index 8ae64fe6d77..25ee2b67fbe 100644 --- a/apps/sim/lib/workflows/executor/human-in-the-loop-manager.ts +++ b/apps/sim/lib/workflows/executor/human-in-the-loop-manager.ts @@ -81,6 +81,7 @@ import type { import { hasExecutionResult } from '@/executor/utils/errors' import { filterOutputForLog } from '@/executor/utils/output-filter' import { projectResolvedSecretDiagnosticError } from '@/executor/utils/resolved-secret-content-projection' +import { stripLoopDigest } from '@/executor/utils/subflow-node-id-codec' import type { SerializedConnection } from '@/serializer/types' /** @@ -3920,7 +3921,7 @@ export class PauseResumeManager { return '' } - const normalized = id.replace(/_loop\d+/g, '') + const normalized = stripLoopDigest(id) return normalized || id } diff --git a/apps/sim/lib/workflows/executor/pause-block-names.test.ts b/apps/sim/lib/workflows/executor/pause-block-names.test.ts new file mode 100644 index 00000000000..8ad2965ea0d --- /dev/null +++ b/apps/sim/lib/workflows/executor/pause-block-names.test.ts @@ -0,0 +1,12 @@ +import { describe, expect, it } from 'vitest' +import { pauseBaseBlockId } from '@/lib/workflows/executor/pause-block-names' + +describe('pauseBaseBlockId', () => { + it.each([ + ['a loop iteration', 'approval_loop2', 'approval'], + ['a parallel branch inside a loop', 'approval₍1₎_loop2', 'approval'], + ['a cloned subflow branch inside a loop', 'approval__obranch-3₍0₎_loop4', 'approval'], + ])('resolves the workflow block of a point keyed only by %s context', (_, contextId, base) => { + expect(pauseBaseBlockId({ contextId })).toBe(base) + }) +}) diff --git a/apps/sim/lib/workflows/executor/pause-block-names.ts b/apps/sim/lib/workflows/executor/pause-block-names.ts index ea9bf3b2734..9af0ece71a6 100644 --- a/apps/sim/lib/workflows/executor/pause-block-names.ts +++ b/apps/sim/lib/workflows/executor/pause-block-names.ts @@ -2,13 +2,16 @@ import { db } from '@sim/db' import { workflowDeploymentVersion, workflowExecutionLogs } from '@sim/db/schema' import { and, eq, sql } from 'drizzle-orm' import type { PausePoint } from '@/executor/types' -import { stripCloneSuffixes } from '@/executor/utils/subflow-node-id-codec' +import { stripCloneSuffixes, stripLoopDigest } from '@/executor/utils/subflow-node-id-codec' type NameablePausePoint = Pick -/** The workflow block a pause point waits on, without any parallel branch or subflow clone suffix. */ +/** + * The workflow block a pause point waits on, without any loop iteration, parallel branch, or + * subflow clone suffix. The loop digest goes first: a context ID ends in it (`block₍N₎_loopK`). + */ export function pauseBaseBlockId(point: Pick): string { - return stripCloneSuffixes(point.blockId ?? point.contextId) + return stripCloneSuffixes(stripLoopDigest(point.blockId ?? point.contextId)) } /**