Skip to content

Commit 8574e6c

Browse files
authored
fix(hitl): fix condition blocks after hitl (#2967)
1 parent 9c3e663 commit 8574e6c

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

apps/sim/executor/handlers/condition/condition-handler.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ export class ConditionBlockHandler implements BlockHandler {
8585

8686
const sourceBlockId = ctx.workflow?.connections.find((conn) => conn.target === block.id)?.source
8787
const evalContext = this.buildEvaluationContext(ctx, sourceBlockId)
88-
const sourceOutput = sourceBlockId ? ctx.blockStates.get(sourceBlockId)?.output : null
88+
const rawSourceOutput = sourceBlockId ? ctx.blockStates.get(sourceBlockId)?.output : null
89+
90+
// Filter out _pauseMetadata from source output to prevent the engine from
91+
// thinking this block is pausing (it was already resumed by the HITL block)
92+
const sourceOutput = this.filterPauseMetadata(rawSourceOutput)
8993

9094
const outgoingConnections = ctx.workflow?.connections.filter((conn) => conn.source === block.id)
9195

@@ -125,6 +129,14 @@ export class ConditionBlockHandler implements BlockHandler {
125129
}
126130
}
127131

132+
private filterPauseMetadata(output: any): any {
133+
if (!output || typeof output !== 'object') {
134+
return output
135+
}
136+
const { _pauseMetadata, ...rest } = output
137+
return rest
138+
}
139+
128140
private parseConditions(input: any): Array<{ id: string; title: string; value: string }> {
129141
try {
130142
const conditions = Array.isArray(input) ? input : JSON.parse(input || '[]')

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,32 @@ export class PauseResumeManager {
567567

568568
stateCopy.blockStates[stateBlockKey] = pauseBlockState
569569

570+
// Update the block log entry with the merged output so logs show the submission data
571+
if (Array.isArray(stateCopy.blockLogs)) {
572+
const blockLogIndex = stateCopy.blockLogs.findIndex(
573+
(log: { blockId: string }) =>
574+
log.blockId === stateBlockKey ||
575+
log.blockId === pauseBlockId ||
576+
log.blockId === contextId
577+
)
578+
if (blockLogIndex !== -1) {
579+
// Filter output for logging (exclude internal fields and response)
580+
const filteredOutput: Record<string, unknown> = {}
581+
for (const [key, value] of Object.entries(mergedOutput)) {
582+
if (key.startsWith('_')) continue
583+
if (key === 'response') continue
584+
filteredOutput[key] = value
585+
}
586+
stateCopy.blockLogs[blockLogIndex] = {
587+
...stateCopy.blockLogs[blockLogIndex],
588+
blockId: stateBlockKey,
589+
output: filteredOutput,
590+
durationMs: pauseDurationMs,
591+
endedAt: new Date().toISOString(),
592+
}
593+
}
594+
}
595+
570596
if (Array.isArray(stateCopy.executedBlocks)) {
571597
const filtered = stateCopy.executedBlocks.filter(
572598
(id: string) => id !== pauseBlockId && id !== contextId

0 commit comments

Comments
 (0)