Skip to content

Increase v4 visibility timeouts & don't try continue finished runs #1978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 24, 2025
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
5 changes: 5 additions & 0 deletions internal-packages/run-engine/src/engine/statuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export function isCheckpointable(status: TaskRunExecutionStatus): boolean {
return checkpointableStatuses.includes(status);
}

export function isFinishedOrPendingFinished(status: TaskRunExecutionStatus): boolean {
const finishedStatuses: TaskRunExecutionStatus[] = ["FINISHED", "PENDING_CANCEL"];
return finishedStatuses.includes(status);
}

export function isFinalRunStatus(status: TaskRunStatus): boolean {
const finalStatuses: TaskRunStatus[] = [
"CANCELED",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "@trigger.dev/database";
import { nanoid } from "nanoid";
import { sendNotificationToWorker } from "../eventBus.js";
import { isExecuting } from "../statuses.js";
import { isExecuting, isFinishedOrPendingFinished } from "../statuses.js";
import { EnqueueSystem } from "./enqueueSystem.js";
import { ExecutionSnapshotSystem, getLatestExecutionSnapshot } from "./executionSnapshotSystem.js";
import { SystemResources } from "./systems.js";
Expand Down Expand Up @@ -512,6 +512,14 @@ export class WaitpointSystem {
await this.$.runLock.lock([runId], 5000, async () => {
const snapshot = await getLatestExecutionSnapshot(this.$.prisma, runId);

if (isFinishedOrPendingFinished(snapshot.executionStatus)) {
this.$.logger.debug(`#continueRunIfUnblocked: run is finished, skipping`, {
runId,
snapshot,
});
return;
}

//run is still executing, send a message to the worker
if (isExecuting(snapshot.executionStatus)) {
const result = await this.$.runQueue.reacquireConcurrency(
Expand Down Expand Up @@ -573,6 +581,11 @@ export class WaitpointSystem {
} else {
if (snapshot.executionStatus !== "RUN_CREATED" && !snapshot.checkpointId) {
// TODO: We're screwed, should probably fail the run immediately
this.$.logger.error(`#continueRunIfUnblocked: run has no checkpoint`, {
runId: run.id,
snapshot,
blockingWaitpoints,
});
throw new Error(`#continueRunIfUnblocked: run has no checkpoint: ${run.id}`);
}

Expand Down
16 changes: 8 additions & 8 deletions internal-packages/run-engine/src/engine/workerCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,51 @@ export const workerCatalog = {
waitpointId: z.string(),
error: z.string().optional(),
}),
visibilityTimeoutMs: 5000,
visibilityTimeoutMs: 30_000,
},
heartbeatSnapshot: {
schema: z.object({
runId: z.string(),
snapshotId: z.string(),
}),
visibilityTimeoutMs: 5000,
visibilityTimeoutMs: 30_000,
},
expireRun: {
schema: z.object({
runId: z.string(),
}),
visibilityTimeoutMs: 5000,
visibilityTimeoutMs: 30_000,
},
cancelRun: {
schema: z.object({
runId: z.string(),
completedAt: z.coerce.date(),
reason: z.string().optional(),
}),
visibilityTimeoutMs: 5000,
visibilityTimeoutMs: 30_000,
},
queueRunsPendingVersion: {
schema: z.object({
backgroundWorkerId: z.string(),
}),
visibilityTimeoutMs: 5000,
visibilityTimeoutMs: 60_000,
},
tryCompleteBatch: {
schema: z.object({
batchId: z.string(),
}),
visibilityTimeoutMs: 10_000,
visibilityTimeoutMs: 30_000,
},
continueRunIfUnblocked: {
schema: z.object({
runId: z.string(),
}),
visibilityTimeoutMs: 10_000,
visibilityTimeoutMs: 30_000,
},
enqueueDelayedRun: {
schema: z.object({
runId: z.string(),
}),
visibilityTimeoutMs: 10_000,
visibilityTimeoutMs: 30_000,
},
};