Skip to content

Commit eae294a

Browse files
committed
Add back in the v2 timeout task thing
1 parent 465cd03 commit eae294a

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

apps/webapp/app/services/runs/performRunExecutionV3.server.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ export class PerformRunExecutionV3Service {
229229
});
230230
}
231231

232+
const taskCount = await getTaskCountForRun(this.#prismaClient, run.id);
232233
const tasks = await getCompletedTasksForRun(this.#prismaClient, run.id);
233234

234235
const sourceContext = RunSourceContextSchema.safeParse(run.event.sourceContext);
@@ -428,7 +429,8 @@ export class PerformRunExecutionV3Service {
428429
this.#prismaClient,
429430
run,
430431
input,
431-
durationInMs
432+
durationInMs,
433+
taskCount
432434
);
433435
} else {
434436
return await this.#failRunExecutionWithRetry(
@@ -1075,7 +1077,8 @@ export class PerformRunExecutionV3Service {
10751077
prisma: PrismaClientOrTransaction,
10761078
run: FoundRun,
10771079
input: PerformRunExecutionV3Input,
1078-
durationInMs: number
1080+
durationInMs: number,
1081+
existingTaskCount: number
10791082
) {
10801083
await $transaction(prisma, async (tx) => {
10811084
const executionDuration = run.executionDuration + durationInMs;
@@ -1096,6 +1099,47 @@ export class PerformRunExecutionV3Service {
10961099
return;
10971100
}
10981101

1102+
const newTaskCount = await getTaskCountForRun(tx, run.id);
1103+
1104+
if (newTaskCount === existingTaskCount) {
1105+
const latestTask = await tx.task.findFirst({
1106+
select: {
1107+
id: true,
1108+
name: true,
1109+
status: true,
1110+
displayKey: true,
1111+
},
1112+
where: {
1113+
runId: run.id,
1114+
status: "RUNNING",
1115+
},
1116+
orderBy: {
1117+
createdAt: "desc",
1118+
},
1119+
take: 1,
1120+
});
1121+
1122+
const cause =
1123+
latestTask?.status === "RUNNING"
1124+
? `This is likely caused by task "${
1125+
latestTask.displayKey ?? latestTask.name
1126+
}" execution exceeding the function timeout`
1127+
: "This is likely caused by executing code outside of a task that exceeded the function timeout";
1128+
1129+
await this.#failRunExecution(
1130+
tx,
1131+
run,
1132+
{
1133+
message: `Function timeout detected in ${
1134+
durationInMs / 1000.0
1135+
}s without any task creation. This is unexpected behavior and could lead to an infinite execution error because the run will never finish. ${cause}`,
1136+
},
1137+
"TIMED_OUT",
1138+
durationInMs
1139+
);
1140+
return;
1141+
}
1142+
10991143
await tx.jobRun.update({
11001144
where: {
11011145
id: run.id,
@@ -1217,6 +1261,14 @@ function prepareNoOpTasksBloomFilter(possibleTasks: FoundTask[]): string {
12171261
return filter.serialize();
12181262
}
12191263

1264+
async function getTaskCountForRun(prisma: PrismaClientOrTransaction, runId: string) {
1265+
return await prisma.task.count({
1266+
where: {
1267+
runId,
1268+
},
1269+
});
1270+
}
1271+
12201272
async function getCompletedTasksForRun(prisma: PrismaClientOrTransaction, runId: string) {
12211273
return await prisma.task.findMany({
12221274
where: {

0 commit comments

Comments
 (0)