diff --git a/internal-packages/run-engine/src/engine/systems/waitpointSystem.ts b/internal-packages/run-engine/src/engine/systems/waitpointSystem.ts index 4ebbd55779..181a6fe277 100644 --- a/internal-packages/run-engine/src/engine/systems/waitpointSystem.ts +++ b/internal-packages/run-engine/src/engine/systems/waitpointSystem.ts @@ -79,8 +79,8 @@ export class WaitpointSystem { }; }): Promise { // 1. Complete the Waitpoint (if not completed) - let [waitpointError, waitpoint] = await tryCatch( - this.$.prisma.waitpoint.update({ + const [updateError, updateResult] = await tryCatch( + this.$.prisma.waitpoint.updateMany({ where: { id, status: "PENDING" }, data: { status: "COMPLETED", @@ -92,29 +92,32 @@ export class WaitpointSystem { }) ); - if (waitpointError) { - if ( - waitpointError instanceof Prisma.PrismaClientKnownRequestError && - waitpointError.code === "P2025" - ) { - waitpoint = await this.$.prisma.waitpoint.findFirst({ - where: { id }, - }); - } else { - this.$.logger.log("completeWaitpoint: error updating waitpoint:", { waitpointError }); - throw waitpointError; - } + if (updateError) { + this.$.logger.error("completeWaitpoint: error updating waitpoint:", { updateError }); + throw updateError; } + if (updateResult.count === 0) { + this.$.logger.info( + "completeWaitpoint: attempted to complete a waitpoint that is not PENDING", + { waitpointId: id } + ); + } + + const waitpoint = await this.$.prisma.waitpoint.findFirst({ + where: { id }, + }); + if (!waitpoint) { - throw new Error(`Waitpoint ${id} not found`); + this.$.logger.error("completeWaitpoint: waitpoint not found", { waitpointId: id }); + throw new Error("Waitpoint not found"); } if (waitpoint.status !== "COMPLETED") { this.$.logger.error(`completeWaitpoint: waitpoint is not completed`, { waitpointId: id, }); - throw new Error(`Waitpoint ${id} is not completed`); + throw new Error("Waitpoint not completed"); } // 2. Find the TaskRuns blocked by this waitpoint