Skip to content

Commit 181ecbe

Browse files
committed
fix(workflows): cancel runs by execution id
1 parent 89a658b commit 181ecbe

13 files changed

Lines changed: 30 additions & 57 deletions

File tree

apps/sim/app/api/v2/workflows/[workflowId]/runs/[runId]/cancel/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const POST = defineV2JsonRoute({
1313
operation: workflowOperations.cancelRun,
1414
rateLimit: v2RateLimits.publicApi,
1515
errorPolicy: v2WorkflowErrorPolicies.cancelRun,
16-
mapInput: ({ params }) => ({ workflowId: params.workflowId, runId: params.runId }),
16+
mapInput: ({ params }) => ({ runId: params.runId }),
1717
useCase: cancelWorkflowRun,
1818
present: (result) => ({
1919
data: {

apps/sim/app/api/v2/workflows/[workflowId]/runs/[runId]/route.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ describe('v2 run detail and cancel adapters', () => {
359359
})
360360
expect(mocks.cancel).toHaveBeenCalledWith({
361361
principal,
362-
input: { workflowId: 'workflow-1', runId: 'run-1' },
362+
input: { runId: 'run-1' },
363363
request: expect.anything(),
364364
})
365365
expect(v2RouteMocks.operationRate).toHaveBeenCalledTimes(2)
@@ -417,7 +417,7 @@ describe('v2 run detail and cancel adapters', () => {
417417
expect(response.status).toBe(200)
418418
expect(mocks.cancel).toHaveBeenCalledWith({
419419
principal: personalPrincipal,
420-
input: { workflowId: 'workflow-1', runId: 'run-1' },
420+
input: { runId: 'run-1' },
421421
request: expect.anything(),
422422
})
423423
})

apps/sim/app/api/workflows/[id]/executions/[executionId]/cancel/route.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ describe('POST /api/workflows/[id]/executions/[executionId]/cancel', () => {
6464
expect(mocks.cancel).toHaveBeenCalledWith({
6565
principal,
6666
input: {
67-
workflowId: 'workflow-1',
6867
runId: 'execution-1',
6968
abortSignal: expect.any(AbortSignal),
7069
},

apps/sim/app/api/workflows/[id]/executions/[executionId]/cancel/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const POST = defineInternalJsonRoute({
1919
}),
2020
errorPolicy: internalWorkflowErrorPolicies.concealRunAuthorization,
2121
mapInput: ({ params }, { request }) => ({
22-
workflowId: params.id,
2322
runId: params.executionId,
2423
abortSignal: request.signal,
2524
}),

apps/sim/lib/copilot/generated/tool-catalog-v1.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,9 +1629,8 @@ export const CancelWorkflowRun: ToolCatalogEntry = {
16291629
description:
16301630
'Required workflow execution ID returned by run_workflow with async:true or found with query_logs. This identifies a workflow run, not an agent invocation or chat request.',
16311631
},
1632-
workflowId: { type: 'string', description: 'Required workflow ID that owns the execution.' },
16331632
},
1634-
required: ['workflowId', 'executionId'],
1633+
required: ['executionId'],
16351634
},
16361635
requiredPermission: 'write',
16371636
requiresApproval: true,

apps/sim/lib/copilot/generated/tool-schemas-v1.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,12 +1569,8 @@ export const TOOL_RUNTIME_SCHEMAS: Record<string, ToolRuntimeSchemaEntry> = {
15691569
description:
15701570
'Required workflow execution ID returned by run_workflow with async:true or found with query_logs. This identifies a workflow run, not an agent invocation or chat request.',
15711571
},
1572-
workflowId: {
1573-
type: 'string',
1574-
description: 'Required workflow ID that owns the execution.',
1575-
},
15761572
},
1577-
required: ['workflowId', 'executionId'],
1573+
required: ['executionId'],
15781574
},
15791575
resultSchema: undefined,
15801576
},

apps/sim/lib/copilot/tools/handlers/param-types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export interface RunWorkflowParams {
6161
}
6262

6363
export interface CancelWorkflowRunParams {
64-
workflowId: string
6564
/** The workflow execution ID returned by run_workflow or query_logs. */
6665
executionId: string
6766
}

apps/sim/lib/copilot/tools/handlers/workflow/mutations.test.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,16 @@ describe('workflow mutation Copilot adapters', () => {
169169
mocks.executeWorkflowUseCase.mockResolvedValue({
170170
success: true,
171171
executionId: 'execution-1',
172+
workflowId: 'workflow-1',
173+
workspaceId: 'workspace-1',
172174
redisAvailable: true,
173175
durablyRecorded: true,
174176
locallyAborted: false,
175177
pausedCancelled: false,
176178
reason: 'recorded',
177179
})
178180

179-
const result = await executeCancelWorkflowRun(
180-
{ workflowId: 'workflow-1', executionId: 'execution-1' },
181-
context
182-
)
181+
const result = await executeCancelWorkflowRun({ executionId: 'execution-1' }, context)
183182

184183
expect(result).toEqual({
185184
success: true,
@@ -198,9 +197,7 @@ describe('workflow mutation Copilot adapters', () => {
198197
operation: expect.objectContaining({ id: 'workflows.runs.cancel' }),
199198
}),
200199
{
201-
workflowId: 'workflow-1',
202200
runId: 'execution-1',
203-
assertedWorkspaceId: 'workspace-1',
204201
}
205202
)
206203
})
@@ -215,10 +212,7 @@ describe('workflow mutation Copilot adapters', () => {
215212
})
216213
)
217214

218-
const result = await executeCancelWorkflowRun(
219-
{ workflowId: 'workflow-1', executionId: 'execution-1' },
220-
context
221-
)
215+
const result = await executeCancelWorkflowRun({ executionId: 'execution-1' }, context)
222216

223217
expect(result).toEqual({
224218
success: false,
@@ -227,25 +221,12 @@ describe('workflow mutation Copilot adapters', () => {
227221
})
228222

229223
it('requires an execution ID before attempting workflow-run cancellation', async () => {
230-
const result = await executeCancelWorkflowRun(
231-
{ workflowId: 'workflow-1' } as CancelWorkflowRunParams,
232-
context
233-
)
224+
const result = await executeCancelWorkflowRun({} as CancelWorkflowRunParams, context)
234225

235226
expect(result).toEqual({ success: false, error: 'executionId is required' })
236227
expect(mocks.executeWorkflowUseCase).not.toHaveBeenCalled()
237228
})
238229

239-
it('requires a workflow ID even when the execution context contains one', async () => {
240-
const result = await executeCancelWorkflowRun(
241-
{ executionId: 'execution-1' } as CancelWorkflowRunParams,
242-
context
243-
)
244-
245-
expect(result).toEqual({ success: false, error: 'workflowId is required' })
246-
expect(mocks.executeWorkflowUseCase).not.toHaveBeenCalled()
247-
})
248-
249230
it.each([
250231
{
251232
label: 'until',

apps/sim/lib/copilot/tools/handlers/workflow/mutations.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,6 @@ export async function executeCancelWorkflowRun(
289289
context: ExecutionContext
290290
): Promise<ToolCallResult> {
291291
try {
292-
const workflowId = params.workflowId
293-
if (!workflowId) {
294-
return { success: false, error: 'workflowId is required' }
295-
}
296292
const executionId = resolveInputFromExecutionId(params.executionId)
297293
if (!executionId) {
298294
return { success: false, error: 'executionId is required' }
@@ -303,16 +299,14 @@ export async function executeCancelWorkflowRun(
303299
'Request aborted before workflow run cancellation could be applied.'
304300
)
305301
const result = await executeCopilotWorkflowUseCase(context, cancelWorkflowRun, {
306-
workflowId,
307302
runId: executionId,
308-
assertedWorkspaceId: context.workspaceId,
309303
...(context.abortSignal ? { abortSignal: context.abortSignal } : {}),
310304
})
311305

312306
return {
313307
success: result.success,
314308
output: {
315-
workflowId,
309+
workflowId: result.workflowId,
316310
executionId: result.executionId,
317311
durablyRecorded: result.durablyRecorded,
318312
locallyAborted: result.locallyAborted,

apps/sim/lib/webhooks/slack-custom-ingress.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ describe('handleSlackAgentSessionStopped', () => {
9292
await handleSlackAgentSessionStopped('credential-1', { kind: 'stop' })
9393

9494
expect(mocks.cancel).toHaveBeenCalledTimes(2)
95+
expect(mocks.cancel).toHaveBeenNthCalledWith(1, {
96+
executionId: 'execution-1',
97+
workflowId: 'workflow-1',
98+
attributedUserId: 'user-1',
99+
workspaceId: 'workspace-1',
100+
})
101+
expect(mocks.cancel).toHaveBeenNthCalledWith(2, {
102+
executionId: 'execution-2',
103+
workflowId: 'workflow-2',
104+
attributedUserId: 'user-2',
105+
workspaceId: 'workspace-1',
106+
})
95107
expect(mocks.unregister).toHaveBeenCalledTimes(2)
96108
expect(mocks.setStatus).toHaveBeenCalledWith(
97109
'xoxb-test',

0 commit comments

Comments
 (0)