From ae445fa58a02d7a7147860feb85d033972c9ca37 Mon Sep 17 00:00:00 2001 From: yiling Date: Fri, 29 May 2026 20:00:47 +0800 Subject: [PATCH] fix(workflow): remove redundant submit call from executeWait Remove the duplicate 'this.submit(task)' call in 'executeWait' as task submission is already handled automatically upon task creation by the Prisma Client Extension in 'src/db.ts'. --- src/workflow/workflow.test.ts | 48 +++++++++++++++++++++++++++++++++++ src/workflow/workflow.ts | 2 -- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/workflow/workflow.test.ts b/src/workflow/workflow.test.ts index 8e85d866..5df5f406 100644 --- a/src/workflow/workflow.test.ts +++ b/src/workflow/workflow.test.ts @@ -134,4 +134,52 @@ describe('WorkflowService', () => { 'embedding feature is disabled or agent not found', ) }, 15000) + + it('should not double-submit the task when executeWait is called', async () => { + const team = await prisma.team.create({ + data: { name: 'Test Team' }, + }) + const project = await prisma.project.create({ + data: { name: 'Test Project', teamId: team.id }, + }) + const asset = await prisma.asset.create({ + data: { + name: 'test-double.png', + storageKey: { create: { key: 'test/test-double.png' } }, + status: 'uploaded', + type: 'file', + mediaType: 'image/png', + project: { connect: { id: project.id } }, + }, + }) + + const submitSpy = vi.spyOn(workflowService, 'submit') + + const task = await prisma.workflowTask.create({ + data: { + assetId: asset.id, + type: WorkflowTaskType.ai_embedding, + status: WorkflowTaskStatus.pending, + teamId: team.id, + }, + }) + + // Wait briefly for the Prisma extension's async import/submit to fire + await new Promise((resolve) => setTimeout(resolve, 100)) + + expect(submitSpy).toHaveBeenCalledTimes(1) + + // Complete the task in the database so executeWait returns immediately + await prisma.workflowTask.update({ + where: { id: task.id }, + data: { status: 'completed' }, + }) + + await workflowService.executeWait(task) + + // Verify it was not submitted a second time by executeWait + expect(submitSpy).toHaveBeenCalledTimes(1) + + submitSpy.mockRestore() + }) }) diff --git a/src/workflow/workflow.ts b/src/workflow/workflow.ts index a12b794c..954aff98 100644 --- a/src/workflow/workflow.ts +++ b/src/workflow/workflow.ts @@ -21,8 +21,6 @@ export class WorkflowService { } async executeWait(task: WorkflowTask, timeoutMs: number = 30000): Promise { - await this.submit(task) - const start = Date.now() while (Date.now() - start < timeoutMs) { const updatedTask = await prisma.workflowTask.findUnique({