From cef4d700ae0dac21f24f37ed5e3515427e141560 Mon Sep 17 00:00:00 2001 From: Dan Sutton Date: Fri, 21 Aug 2026 13:26:28 +0100 Subject: [PATCH] refactor(run-engine): move the run block-state read behind the coordinator --- .../src/engine/systems/waitpointSystem.ts | 15 +-------------- .../legacyPostgresCoordinator.ts | 19 ++++++++++++++++++- .../src/engine/waitpointCoordinator/types.ts | 16 +++++++++++++++- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/internal-packages/run-engine/src/engine/systems/waitpointSystem.ts b/internal-packages/run-engine/src/engine/systems/waitpointSystem.ts index d43e811c6..752dbe90d 100644 --- a/internal-packages/run-engine/src/engine/systems/waitpointSystem.ts +++ b/internal-packages/run-engine/src/engine/systems/waitpointSystem.ts @@ -683,20 +683,7 @@ export class WaitpointSystem { return await this.$.runLock.lock("continueRunIfUnblocked", [runId], async () => { // 1. Get the any blocking waitpoints - const blockingWaitpoints = await this.$.runStore.findManyTaskRunWaitpoints( - { - where: { taskRunId: runId }, - select: { - id: true, - batchId: true, - batchIndex: true, - waitpoint: { - select: { id: true, status: true, type: true, completedAfter: true }, - }, - }, - }, - this.$.prisma - ); + const blockingWaitpoints = await this.coordinator.readRunBlockState(runId); // 2. There are blockers still, so do nothing if (blockingWaitpoints.some((w) => w.waitpoint.status !== "COMPLETED")) { diff --git a/internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts b/internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts index b2e6aadb2..b7ca49f15 100644 --- a/internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts +++ b/internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts @@ -2,7 +2,7 @@ import type { RunStore } from "@internal/run-store"; import type { Logger } from "@trigger.dev/core/logger"; import type { PrismaClient } from "@trigger.dev/database"; import { boundedIn } from "@trigger.dev/database"; -import type { ClearRunBlockStateParams, WaitpointCoordinator } from "./types.js"; +import type { ClearRunBlockStateParams, RunBlockEdge, WaitpointCoordinator } from "./types.js"; export type LegacyPostgresWaitpointCoordinatorOptions = { runStore: RunStore; @@ -48,4 +48,21 @@ export class LegacyPostgresWaitpointCoordinator implements WaitpointCoordinator // passed through: a routing store strips it, and a single store joins it. return this.runStore.deleteManyTaskRunWaitpoints({ where: { taskRunId: runId } }, tx); } + + async readRunBlockState(runId: string): Promise { + return this.runStore.findManyTaskRunWaitpoints( + { + where: { taskRunId: runId }, + select: { + id: true, + batchId: true, + batchIndex: true, + waitpoint: { + select: { id: true, status: true, type: true, completedAfter: true }, + }, + }, + }, + this.prisma + ); + } } diff --git a/internal-packages/run-engine/src/engine/waitpointCoordinator/types.ts b/internal-packages/run-engine/src/engine/waitpointCoordinator/types.ts index 8db4b986b..f4c630638 100644 --- a/internal-packages/run-engine/src/engine/waitpointCoordinator/types.ts +++ b/internal-packages/run-engine/src/engine/waitpointCoordinator/types.ts @@ -1,4 +1,4 @@ -import type { PrismaClientOrTransaction } from "@trigger.dev/database"; +import type { PrismaClientOrTransaction, Waitpoint } from "@trigger.dev/database"; /** * The waitpoint and edge state operations that `WaitpointSystem` delegates. @@ -14,6 +14,7 @@ import type { PrismaClientOrTransaction } from "@trigger.dev/database"; */ export type WaitpointCoordinator = { clearRunBlockState(params: ClearRunBlockStateParams): Promise<{ count: number }>; + readRunBlockState(runId: string): Promise; }; export type ClearRunBlockStateParams = { @@ -26,3 +27,16 @@ export type ClearRunBlockStateParams = { */ tx?: PrismaClientOrTransaction; }; + +/** + * One block edge, with the fields the unblock decision reads. + * + * `batchId` is read by no logic. It rides inside two `logger.debug` payloads + * (`waitpointSystem.ts:702-705` and `:936-939`), so removing it changes log output. + */ +export type RunBlockEdge = { + id: string; + batchId: string | null; + batchIndex: number | null; + waitpoint: Pick; +};