Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/shared/modules/global/submission-scan-complete.orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ export class SubmissionScanCompleteOrchestrator {
return;
}

// check if workflow runs have already been queued for this submission
const alreadyQueued = await this.workflowQueueHandler.hasQueuedWorkflowRuns(
submissionId,
);

if (alreadyQueued) {
this.logger.log(
`AI workflow runs already queued for submission ${submissionId}. Skipping queueing.`,
);
return;
}
Comment on lines +52 to +62
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a potential race condition between checking for existing workflow runs and queueing new ones. If two scan complete events are processed concurrently for the same submission, both could pass the hasQueuedWorkflowRuns check and proceed to queue workflows, resulting in duplicate workflow runs.

Consider using a database transaction or a unique constraint to prevent duplicate workflow runs, or ensure that the check and queue operations are atomic.

Copilot uses AI. Check for mistakes.

await this.workflowQueueHandler.queueWorkflowRuns(
challenge.workflows,
challenge.id,
Expand Down
12 changes: 12 additions & 0 deletions src/shared/modules/global/workflow-queue.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ export class WorkflowQueueHandler implements OnModuleInit {
});
}

async hasQueuedWorkflowRuns(submissionId: string): Promise<boolean> {
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name hasQueuedWorkflowRuns is misleading because it doesn't actually check if workflow runs are queued. It checks if any workflow runs exist for the submission, regardless of their status. Consider renaming to hasWorkflowRuns or, if the intent is to check for active/pending workflows, rename to hasActiveWorkflowRuns and update the implementation to filter by status.

Copilot uses AI. Check for mistakes.
if (!submissionId) return false;

const existing = await this.prisma.aiWorkflowRun.findFirst({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ performance]
Consider adding an index on the submissionId field in the aiWorkflowRun table if not already present. This could improve the performance of the findFirst query, especially if the table grows large.

where: {
submissionId,
},
});

return !!existing;
}

async handleQueuedWorkflowRun([job]: [Job]) {
this.logger.log(`Processing job ${job.id}`);

Expand Down
Loading