Skip to content

Commit 044805a

Browse files
authored
fix(mothership): report a paused Copilot workflow whose cancel lost the race to an unreported terminal run (#9293)
1 parent 75f2960 commit 044805a

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎apps/sim/lib/mothership/request/tools/workflow-client-settlement.integration.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,24 @@ describe.runIf(Boolean(redisUrl))('settled client-claimed workflow tools', () =>
436436
})
437437
})
438438

439+
it('delivers a paused execution whose cancel lost the race to a run that ended unreported', async () => {
440+
const { toolCallId, executionId } = await claimedAndPaused()
441+
const waiting = waitForWorkflowToolCompletion({ toolCallId, workflowId, timeoutMs: WAIT_MS })
442+
expect(await PauseResumeManager.beginPausedCancellation(executionId, workflowId)).toBe(true)
443+
// The stale-execution sweep fails the run's log and reports nothing to Copilot.
444+
await setLogStatus(executionId, 'failed')
445+
446+
expect(
447+
await PauseResumeManager.finalizePausedCancellationForTerminalRun(executionId, workflowId, [])
448+
).toBe(true)
449+
450+
expect(await waiting).toMatchObject({
451+
status: 'error',
452+
data: { success: false, workflowId, executionId },
453+
})
454+
expect(await toolRow(toolCallId)).toMatchObject({ status: 'failed', claimedBy: null })
455+
})
456+
439457
it('moves a queued async run to the background when the browser never reports', async () => {
440458
const { toolCallId, executionId } = await claimed({ workflowId, async: true })
441459
const waiting = waitForWorkflowToolCompletion({ toolCallId, workflowId, timeoutMs: WAIT_MS })

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,6 +2995,11 @@ export class PauseResumeManager {
29952995
})
29962996

29972997
await releaseCancelledResumeReservations(transition.claimedResumeEntryIds)
2998+
// The terminal writer may never report it (the stale-execution sweep, a resume worker killed
2999+
// after its log write), which would leave the Copilot tool waiting.
3000+
if (transition.finalized) {
3001+
await reportCopilotToolForSettledPause(executionId, workflowId)
3002+
}
29983003
return transition.finalized
29993004
}
30003005

0 commit comments

Comments
 (0)