@@ -936,7 +936,7 @@ export async function batchTriggerByIdAndWait<TTask extends AnyTask>(
936936 ctx,
937937 } ) ;
938938
939- const runs = await handleBatchTaskRunExecutionResultV2 ( result . items ) ;
939+ const runs = await handleBatchTaskRunExecutionResultV2 ( result . items , response . taskIdentifiers ) ;
940940
941941 return {
942942 id : result . id ,
@@ -980,7 +980,7 @@ export async function batchTriggerByIdAndWait<TTask extends AnyTask>(
980980 ctx,
981981 } ) ;
982982
983- const runs = await handleBatchTaskRunExecutionResultV2 ( result . items ) ;
983+ const runs = await handleBatchTaskRunExecutionResultV2 ( result . items , response . taskIdentifiers ) ;
984984
985985 return {
986986 id : result . id ,
@@ -1457,7 +1457,7 @@ export async function batchTriggerAndWaitTasks<TTasks extends readonly AnyTask[]
14571457 ctx,
14581458 } ) ;
14591459
1460- const runs = await handleBatchTaskRunExecutionResultV2 ( result . items ) ;
1460+ const runs = await handleBatchTaskRunExecutionResultV2 ( result . items , response . taskIdentifiers ) ;
14611461
14621462 return {
14631463 id : result . id ,
@@ -1504,7 +1504,7 @@ export async function batchTriggerAndWaitTasks<TTasks extends readonly AnyTask[]
15041504 ctx,
15051505 } ) ;
15061506
1507- const runs = await handleBatchTaskRunExecutionResultV2 ( result . items ) ;
1507+ const runs = await handleBatchTaskRunExecutionResultV2 ( result . items , response . taskIdentifiers ) ;
15081508
15091509 return {
15101510 id : result . id ,
@@ -1545,7 +1545,7 @@ async function executeBatchTwoPhase(
15451545 spanParentAsLink ?: boolean ;
15461546 } ,
15471547 requestOptions ?: TriggerApiRequestOptions
1548- ) : Promise < { id : string ; runCount : number ; publicAccessToken : string } > {
1548+ ) : Promise < { id : string ; runCount : number ; publicAccessToken : string ; taskIdentifiers : string [ ] } > {
15491549 let batch : Awaited < ReturnType < typeof apiClient . createBatch > > | undefined ;
15501550
15511551 try {
@@ -1588,6 +1588,7 @@ async function executeBatchTwoPhase(
15881588 id : batch . id ,
15891589 runCount : batch . runCount ,
15901590 publicAccessToken : batch . publicAccessToken ,
1591+ taskIdentifiers : items . map ( ( item ) => item . task ) ,
15911592 } ;
15921593}
15931594
@@ -1703,7 +1704,7 @@ async function executeBatchTwoPhaseStreaming(
17031704 spanParentAsLink ?: boolean ;
17041705 } ,
17051706 requestOptions ?: TriggerApiRequestOptions
1706- ) : Promise < { id : string ; runCount : number ; publicAccessToken : string } > {
1707+ ) : Promise < { id : string ; runCount : number ; publicAccessToken : string ; taskIdentifiers : string [ ] } > {
17071708 // For streaming, we need to buffer items to get the count first
17081709 // This is because createBatch requires runCount upfront
17091710 // In the future, we could add a streaming-first endpoint that doesn't require this
@@ -2676,16 +2677,20 @@ async function handleBatchTaskRunExecutionResult<TIdentifier extends string, TOu
26762677}
26772678
26782679async function handleBatchTaskRunExecutionResultV2 (
2679- items : Array < TaskRunExecutionResult >
2680+ items : Array < TaskRunExecutionResult > ,
2681+ taskIdentifiers ?: string [ ]
26802682) : Promise < Array < AnyTaskRunResult > > {
26812683 const someObjectStoreOutputs = items . some (
26822684 ( item ) => item . ok && item . outputType === "application/store"
26832685 ) ;
26842686
26852687 if ( ! someObjectStoreOutputs ) {
26862688 const results = await Promise . all (
2687- items . map ( async ( item ) => {
2688- return await handleTaskRunExecutionResult ( item , item . taskIdentifier ?? "unknown" ) ;
2689+ items . map ( async ( item , index ) => {
2690+ return await handleTaskRunExecutionResult (
2691+ item ,
2692+ item . taskIdentifier ?? taskIdentifiers ?. [ index ] ?? "unknown"
2693+ ) ;
26892694 } )
26902695 ) ;
26912696
@@ -2696,8 +2701,11 @@ async function handleBatchTaskRunExecutionResultV2(
26962701 "store.downloadPayloads" ,
26972702 async ( span ) => {
26982703 const results = await Promise . all (
2699- items . map ( async ( item ) => {
2700- return await handleTaskRunExecutionResult ( item , item . taskIdentifier ?? "unknown" ) ;
2704+ items . map ( async ( item , index ) => {
2705+ return await handleTaskRunExecutionResult (
2706+ item ,
2707+ item . taskIdentifier ?? taskIdentifiers ?. [ index ] ?? "unknown"
2708+ ) ;
27012709 } )
27022710 ) ;
27032711
0 commit comments