Skip to content

Commit ff62a09

Browse files
author
Deploy Bot
committed
fix: taskIdentifier shows unknown in batch.triggerAndWait results (#2942)
1 parent b221719 commit ff62a09

File tree

4 files changed

+63
-28
lines changed

4 files changed

+63
-28
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@trigger.dev/core": patch
3+
"run-engine": patch
4+
---
5+
6+
fix: taskIdentifier shows "unknown" in batch.triggerAndWait and batch.triggerByTaskAndWait results
7+
8+
When using `batch.triggerAndWait()` or `batch.triggerByTaskAndWait()`, the `run.taskIdentifier` in the results was showing as "unknown" instead of the actual task identifier (e.g., "generate-audio" or "generate-scene").
9+
10+
This fix:
11+
- Adds `taskIdentifier` field to the `completedByTaskRun` schema in `runEngine.ts`
12+
- Updates `executionSnapshotSystem.ts` to include `taskIdentifier` when fetching waitpoints by joining with the TaskRun table
13+
- Updates `sharedRuntimeManager.ts` to pass through `taskIdentifier` in the execution result
14+
15+
Fixes #2942

internal-packages/run-engine/src/engine/systems/executionSnapshotSystem.ts

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import { SystemResources } from "./systems.js";
1616
/** Chunk size for fetching waitpoints to avoid NAPI string conversion limits */
1717
const WAITPOINT_CHUNK_SIZE = 100;
1818

19+
/** Waitpoint with optional completedByTaskRun info including taskIdentifier */
20+
type WaitpointWithTaskRun = Waitpoint & {
21+
completedByTaskRun: { taskIdentifier: string } | null;
22+
};
23+
1924
export type ExecutionSnapshotSystemOptions = {
2025
resources: SystemResources;
2126
heartbeatTimeouts: HeartbeatTimeouts;
@@ -57,7 +62,7 @@ function enhanceExecutionSnapshot(
5762
*/
5863
function enhanceExecutionSnapshotWithWaitpoints(
5964
snapshot: ExecutionSnapshotWithCheckpoint,
60-
waitpoints: Waitpoint[],
65+
waitpoints: WaitpointWithTaskRun[] | Waitpoint[],
6166
completedWaitpointOrder: string[]
6267
): EnhancedExecutionSnapshot {
6368
return {
@@ -78,6 +83,11 @@ function enhanceExecutionSnapshotWithWaitpoints(
7883
indexes.push(undefined);
7984
}
8085

86+
// Extract taskIdentifier from completedByTaskRun if available
87+
const taskIdentifier = 'completedByTaskRun' in w && w.completedByTaskRun
88+
? w.completedByTaskRun.taskIdentifier
89+
: undefined;
90+
8191
return indexes.map((index) => {
8292
return {
8393
id: w.id,
@@ -89,22 +99,23 @@ function enhanceExecutionSnapshotWithWaitpoints(
8999
w.userProvidedIdempotencyKey && !w.inactiveIdempotencyKey ? w.idempotencyKey : undefined,
90100
completedByTaskRun: w.completedByTaskRunId
91101
? {
92-
id: w.completedByTaskRunId,
93-
friendlyId: RunId.toFriendlyId(w.completedByTaskRunId),
94-
batch: snapshot.batchId
95-
? {
96-
id: snapshot.batchId,
97-
friendlyId: BatchId.toFriendlyId(snapshot.batchId),
98-
}
99-
: undefined,
100-
}
102+
id: w.completedByTaskRunId,
103+
friendlyId: RunId.toFriendlyId(w.completedByTaskRunId),
104+
taskIdentifier,
105+
batch: snapshot.batchId
106+
? {
107+
id: snapshot.batchId,
108+
friendlyId: BatchId.toFriendlyId(snapshot.batchId),
109+
}
110+
: undefined,
111+
}
101112
: undefined,
102113
completedAfter: w.completedAfter ?? undefined,
103114
completedByBatch: w.completedByBatchId
104115
? {
105-
id: w.completedByBatchId,
106-
friendlyId: BatchId.toFriendlyId(w.completedByBatchId),
107-
}
116+
id: w.completedByBatchId,
117+
friendlyId: BatchId.toFriendlyId(w.completedByBatchId),
118+
}
108119
: undefined,
109120
output: w.output ?? undefined,
110121
outputType: w.outputType,
@@ -137,14 +148,19 @@ async function getSnapshotWaitpointIds(
137148
async function fetchWaitpointsInChunks(
138149
prisma: PrismaClientOrTransaction,
139150
waitpointIds: string[]
140-
): Promise<Waitpoint[]> {
151+
): Promise<WaitpointWithTaskRun[]> {
141152
if (waitpointIds.length === 0) return [];
142153

143-
const allWaitpoints: Waitpoint[] = [];
154+
const allWaitpoints: WaitpointWithTaskRun[] = [];
144155
for (let i = 0; i < waitpointIds.length; i += WAITPOINT_CHUNK_SIZE) {
145156
const chunk = waitpointIds.slice(i, i + WAITPOINT_CHUNK_SIZE);
146157
const waitpoints = await prisma.waitpoint.findMany({
147158
where: { id: { in: chunk } },
159+
include: {
160+
completedByTaskRun: {
161+
select: { taskIdentifier: true },
162+
},
163+
},
148164
});
149165
allWaitpoints.push(...waitpoints);
150166
}
@@ -233,19 +249,19 @@ export function executionDataFromSnapshot(snapshot: EnhancedExecutionSnapshot):
233249
},
234250
batch: snapshot.batchId
235251
? {
236-
id: snapshot.batchId,
237-
friendlyId: BatchId.toFriendlyId(snapshot.batchId),
238-
}
252+
id: snapshot.batchId,
253+
friendlyId: BatchId.toFriendlyId(snapshot.batchId),
254+
}
239255
: undefined,
240256
checkpoint: snapshot.checkpoint
241257
? {
242-
id: snapshot.checkpoint.id,
243-
friendlyId: snapshot.checkpoint.friendlyId,
244-
type: snapshot.checkpoint.type,
245-
location: snapshot.checkpoint.location,
246-
imageRef: snapshot.checkpoint.imageRef,
247-
reason: snapshot.checkpoint.reason ?? undefined,
248-
}
258+
id: snapshot.checkpoint.id,
259+
friendlyId: snapshot.checkpoint.friendlyId,
260+
type: snapshot.checkpoint.type,
261+
location: snapshot.checkpoint.location,
262+
imageRef: snapshot.checkpoint.imageRef,
263+
reason: snapshot.checkpoint.reason ?? undefined,
264+
}
249265
: undefined,
250266
completedWaitpoints: snapshot.completedWaitpoints,
251267
};

packages/core/src/v3/runtime/sharedRuntimeManager.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,19 @@ export class SharedRuntimeManager implements RuntimeManager {
293293
return {
294294
ok: false,
295295
id: waitpoint.completedByTaskRun.friendlyId,
296+
taskIdentifier: waitpoint.completedByTaskRun.taskIdentifier,
296297
error: waitpoint.output
297298
? JSON.parse(waitpoint.output)
298299
: {
299-
type: "STRING_ERROR",
300-
message: "Missing error output",
301-
},
300+
type: "STRING_ERROR",
301+
message: "Missing error output",
302+
},
302303
} satisfies TaskRunFailedExecutionResult;
303304
} else {
304305
return {
305306
ok: true,
306307
id: waitpoint.completedByTaskRun.friendlyId,
308+
taskIdentifier: waitpoint.completedByTaskRun.taskIdentifier,
307309
output: waitpoint.output,
308310
outputType: waitpoint.outputType ?? "application/json",
309311
} satisfies TaskRunSuccessfulExecutionResult;

packages/core/src/v3/schemas/runEngine.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export const CompletedWaitpoint = z.object({
8181
.object({
8282
id: z.string(),
8383
friendlyId: z.string(),
84+
/** The task identifier of the completing run */
85+
taskIdentifier: z.string().optional(),
8486
/** If the run has an associated batch */
8587
batch: z
8688
.object({

0 commit comments

Comments
 (0)