Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(runs): bulk retry and archive no longer fail when filtering by failed step (#15909)

Bartosz Majewski2750f3cff249
diff --git a/packages/server/api/src/app/flows/flow-run/flow-run-service.ts b/packages/server/api/src/app/flows/flow-run/flow-run-service.ts
index 307901efcbd..eee7257abe0 100644
--- a/packages/server/api/src/app/flows/flow-run/flow-run-service.ts
+++ b/packages/server/api/src/app/flows/flow-run/flow-run-service.ts
@@ -656,7 +656,7 @@ async function filterFlowRunsAndApplyFilters(
}
if (params.failedStepName) {
- query = query.andWhere('flow_run.failedStepName = :failedStepName', {
+ query = query.andWhere('flow_run."failedStep"->>\'name\' = :failedStepName', {
failedStepName: params.failedStepName,
})
}
diff --git a/packages/server/api/test/integration/ce/flows/flow-run/bulk-retry-flow-run.test.ts b/packages/server/api/test/integration/ce/flows/flow-run/bulk-retry-flow-run.test.ts
index 47a29170e0a..c1c2e8f1397 100644
--- a/packages/server/api/test/integration/ce/flows/flow-run/bulk-retry-flow-run.test.ts
+++ b/packages/server/api/test/integration/ce/flows/flow-run/bulk-retry-flow-run.test.ts
@@ -140,6 +140,39 @@ describe('Bulk retry flow runs (POST /v1/flow-runs/retry)', () => {
expect(await countRunsForProject(otherProject.id)).toBe(1)
expect(await readStatus(otherRun.id)).toBe(FlowRunStatus.FAILED)
})
+
+ it('scopes retry to the failedStepName filter', async () => {
+ const projectId = ctx.project.id
+ const { flow: matching } = await createFailedRun({ projectId, failedStepName: 'step_1' })
+ const { flow: other } = await createFailedRun({ projectId, failedStepName: 'step_2' })
+
+ const response = await ctx.post('/v1/flow-runs/retry', {
+ projectId,
+ strategy: FlowRetryStrategy.ON_LATEST_VERSION,
+ failedStepName: 'step_1',
+ })
+
+ expect(response.statusCode).toBe(200)
+ await waitForRunCountForFlow({ flowId: matching.id, expected: 2 })
+ expect(await countRunsForFlow(other.id)).toBe(1)
+ })
+})
+
+describe('Bulk archive flow runs (POST /v1/flow-runs/archive)', () => {
+ it('scopes archive to the failedStepName filter', async () => {
+ const projectId = ctx.project.id
+ const { run: matching } = await createFailedRun({ projectId, failedStepName: 'step_1' })
+ const { run: other } = await createFailedRun({ projectId, failedStepName: 'step_2' })
+
+ const response = await ctx.post('/v1/flow-runs/archive', {
+ projectId,
+ failedStepName: 'step_1',
+ })
+
+ expect(response.statusCode).toBe(200)
+ expect(await readArchivedAt(matching.id)).not.toBeNull()
+ expect(await readArchivedAt(other.id)).toBeNull()
+ })
})
const DAY_MS = 24 * 60 * 60 * 1000
@@ -148,10 +181,12 @@ async function createFailedRun({
projectId,
createdAt,
status = FlowRunStatus.FAILED,
+ failedStepName,
}: {
projectId: string
createdAt?: string
status?: FlowRunStatus
+ failedStepName?: string
}): Promise<{ flow: { id: string }, flowVersion: { id: string }, run: { id: string } }> {
const flow = createMockFlow({ projectId })
await db.save('flow', flow)
@@ -169,7 +204,10 @@ async function createFailedRun({
status,
environment: RunEnvironment.PRODUCTION,
})
- await db.save('flow_run', run)
+ await db.save('flow_run', {
+ ...run,
+ failedStep: failedStepName ? { name: failedStepName, displayName: failedStepName } : undefined,
+ })
if (createdAt) {
await databaseConnection().query(
@@ -194,6 +232,11 @@ async function readStatus(runId: string): Promise<FlowRunStatus> {
return row.status
}
+async function readArchivedAt(runId: string): Promise<string | null> {
+ const row = await db.findOneByOrFail<{ archivedAt: string | null }>('flow_run', { id: runId })
+ return row.archivedAt
+}
+
async function waitForCount({
read,
expected,