Skip to content
Merged
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
7 changes: 7 additions & 0 deletions apps/sim/executor/utils/subflow-node-id-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/lib/workflows/executor/human-in-the-loop-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -3920,7 +3921,7 @@ export class PauseResumeManager {
return ''
}

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

return normalized || id
}
Expand Down
12 changes: 12 additions & 0 deletions apps/sim/lib/workflows/executor/pause-block-names.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
9 changes: 6 additions & 3 deletions apps/sim/lib/workflows/executor/pause-block-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PausePoint, 'blockId' | 'contextId' | 'blockName'>

/** 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<PausePoint, 'blockId' | 'contextId'>): string {
return stripCloneSuffixes(point.blockId ?? point.contextId)
return stripCloneSuffixes(stripLoopDigest(point.blockId ?? point.contextId))
}

/**
Expand Down
Loading