Skip to content

Commit 94e28e7

Browse files
fix(api): prefer terminal logs over stale resumes
1 parent c903ba1 commit 94e28e7

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

apps/sim/lib/workflows/executor/execution-status.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,40 @@ describe('getWorkflowExecutionStatus queue projection', () => {
159159
expect(mockGetJob).not.toHaveBeenCalled()
160160
})
161161

162+
it('does not let an orphaned pending resume mask a terminal log', async () => {
163+
queueTableRows(schemaMock.workflowExecutionLogs, [
164+
{
165+
executionId: 'execution-1',
166+
workflowId: 'workflow-1',
167+
workspaceId: 'workspace-1',
168+
status: 'completed',
169+
level: 'info',
170+
trigger: 'api',
171+
startedAt: new Date('2026-08-05T12:00:00.000Z'),
172+
endedAt: new Date('2026-08-05T12:00:01.000Z'),
173+
totalDurationMs: 1000,
174+
executionData: null,
175+
costTotal: null,
176+
},
177+
])
178+
queueTableRows(schemaMock.resumeQueue, [
179+
{
180+
id: 'resume-entry-2',
181+
status: 'pending',
182+
queuedAt: new Date('2026-08-05T12:00:02.000Z'),
183+
claimedAt: null,
184+
},
185+
])
186+
187+
const status = await getWorkflowExecutionStatus(input)
188+
189+
expect(status).toMatchObject({
190+
executionId: 'execution-1',
191+
status: 'completed',
192+
})
193+
expect(mockGetJob).not.toHaveBeenCalled()
194+
})
195+
162196
it('returns completed queue output when requested', async () => {
163197
mockGetJob.mockResolvedValueOnce({
164198
status: 'completed',

apps/sim/lib/workflows/executor/execution-status.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,13 @@ export async function getWorkflowExecutionStatus(
172172
.orderBy(sql`case when ${resumeQueue.status} = 'claimed' then 0 else 1 end`)
173173
.limit(1)
174174

175+
const hasTerminalLog =
176+
logRow?.status === 'completed' || logRow?.status === 'failed' || logRow?.status === 'cancelled'
177+
const projectedResume = hasTerminalLog ? undefined : activeResume
178+
175179
const queueJobIds = [
176-
...(activeResume?.status === 'claimed'
177-
? [`${RESUME_EXECUTION_JOB_ID_PREFIX}${activeResume.id}`]
180+
...(projectedResume?.status === 'claimed'
181+
? [`${RESUME_EXECUTION_JOB_ID_PREFIX}${projectedResume.id}`]
178182
: []),
179183
...(!logRow ? [`${WORKFLOW_EXECUTION_JOB_ID_PREFIX}${executionId}`] : []),
180184
]
@@ -188,8 +192,8 @@ export async function getWorkflowExecutionStatus(
188192
}
189193
}
190194

191-
if (activeResume) {
192-
const startedAt = activeResume.claimedAt ?? activeResume.queuedAt
195+
if (projectedResume) {
196+
const startedAt = projectedResume.claimedAt ?? projectedResume.queuedAt
193197
return {
194198
executionId,
195199
workflowId,

0 commit comments

Comments
 (0)