diff --git a/.changeset/metal-steaks-try.md b/.changeset/metal-steaks-try.md new file mode 100644 index 0000000000..0ed0962b50 --- /dev/null +++ b/.changeset/metal-steaks-try.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/sdk": patch +--- + +fix(sdk): batch triggerAndWait variants now return correct run.taskIdentifier instead of unknown diff --git a/packages/trigger-sdk/src/v3/shared.ts b/packages/trigger-sdk/src/v3/shared.ts index 7b7fa1b979..c03732c12e 100644 --- a/packages/trigger-sdk/src/v3/shared.ts +++ b/packages/trigger-sdk/src/v3/shared.ts @@ -936,7 +936,7 @@ export async function batchTriggerByIdAndWait( ctx, }); - const runs = await handleBatchTaskRunExecutionResultV2(result.items); + const runs = await handleBatchTaskRunExecutionResultV2(result.items, response.taskIdentifiers); return { id: result.id, @@ -980,7 +980,7 @@ export async function batchTriggerByIdAndWait( ctx, }); - const runs = await handleBatchTaskRunExecutionResultV2(result.items); + const runs = await handleBatchTaskRunExecutionResultV2(result.items, response.taskIdentifiers); return { id: result.id, @@ -1457,7 +1457,7 @@ export async function batchTriggerAndWaitTasks { +): Promise<{ id: string; runCount: number; publicAccessToken: string; taskIdentifiers: string[] }> { let batch: Awaited> | undefined; try { @@ -1588,6 +1588,7 @@ async function executeBatchTwoPhase( id: batch.id, runCount: batch.runCount, publicAccessToken: batch.publicAccessToken, + taskIdentifiers: items.map((item) => item.task), }; } @@ -1703,7 +1704,7 @@ async function executeBatchTwoPhaseStreaming( spanParentAsLink?: boolean; }, requestOptions?: TriggerApiRequestOptions -): Promise<{ id: string; runCount: number; publicAccessToken: string }> { +): Promise<{ id: string; runCount: number; publicAccessToken: string; taskIdentifiers: string[] }> { // For streaming, we need to buffer items to get the count first // This is because createBatch requires runCount upfront // In the future, we could add a streaming-first endpoint that doesn't require this @@ -2676,7 +2677,8 @@ async function handleBatchTaskRunExecutionResult + items: Array, + taskIdentifiers?: string[] ): Promise> { const someObjectStoreOutputs = items.some( (item) => item.ok && item.outputType === "application/store" @@ -2684,8 +2686,11 @@ async function handleBatchTaskRunExecutionResultV2( if (!someObjectStoreOutputs) { const results = await Promise.all( - items.map(async (item) => { - return await handleTaskRunExecutionResult(item, item.taskIdentifier ?? "unknown"); + items.map(async (item, index) => { + return await handleTaskRunExecutionResult( + item, + item.taskIdentifier ?? taskIdentifiers?.[index] ?? "unknown" + ); }) ); @@ -2696,8 +2701,11 @@ async function handleBatchTaskRunExecutionResultV2( "store.downloadPayloads", async (span) => { const results = await Promise.all( - items.map(async (item) => { - return await handleTaskRunExecutionResult(item, item.taskIdentifier ?? "unknown"); + items.map(async (item, index) => { + return await handleTaskRunExecutionResult( + item, + item.taskIdentifier ?? taskIdentifiers?.[index] ?? "unknown" + ); }) );