@@ -336,6 +336,7 @@ const buildDefaultUnits = (context, request) => {
336336 const noIsolateArgs = context . noIsolateArgs ;
337337 const selectedSurfaces = buildRequestedSurfaces ( request , env ) ;
338338 const selectedSurfaceSet = new Set ( selectedSurfaces ) ;
339+ const channelsOnlyRun = selectedSurfaceSet . size === 1 && selectedSurfaceSet . has ( "channels" ) ;
339340
340341 const {
341342 heavyUnitLaneCount,
@@ -615,7 +616,7 @@ const buildDefaultUnits = (context, request) => {
615616 id : unitId ,
616617 surface : "channels" ,
617618 isolate : false ,
618- serialPhase : "channels" ,
619+ serialPhase : channelsOnlyRun ? undefined : "channels" ,
619620 includeFiles : batch ,
620621 estimatedDurationMs : estimateEntryFilesDurationMs (
621622 { args : [ "vitest" , "run" , "--config" , "vitest.channels.config.ts" ] } ,
@@ -764,6 +765,15 @@ const buildTargetedUnits = (context, request) => {
764765 return [ ] ;
765766 }
766767 const unitMemoryIsolatedFiles = request . unitMemoryIsolatedFiles ?? [ ] ;
768+ const estimateChannelDurationMs = ( file ) =>
769+ context . channelTimingManifest . files [ file ] ?. durationMs ??
770+ context . channelTimingManifest . defaultDurationMs ;
771+ const defaultTargetedChannelsBatchTargetMs = 12_000 ;
772+ const targetedChannelsBatchTargetMs = parseEnvNumber (
773+ context . env ,
774+ "OPENCLAW_TEST_TARGETED_CHANNELS_BATCH_TARGET_MS" ,
775+ defaultTargetedChannelsBatchTargetMs ,
776+ ) ;
767777 const groups = request . fileFilters . reduce ( ( acc , fileFilter ) => {
768778 const matchedFiles = context . catalog . resolveFilterMatches ( fileFilter ) ;
769779 if ( matchedFiles . length === 0 ) {
@@ -804,6 +814,28 @@ const buildTargetedUnits = (context, request) => {
804814 ) ,
805815 ) ;
806816 }
817+ if (
818+ classification . surface === "channels" &&
819+ uniqueFilters . length > 4 &&
820+ targetedChannelsBatchTargetMs > 0
821+ ) {
822+ const estimatedTotalDurationMs = uniqueFilters . reduce (
823+ ( totalMs , file ) => totalMs + estimateChannelDurationMs ( file ) ,
824+ 0 ,
825+ ) ;
826+ if ( estimatedTotalDurationMs > targetedChannelsBatchTargetMs ) {
827+ return splitFilesByDurationBudget (
828+ uniqueFilters ,
829+ targetedChannelsBatchTargetMs ,
830+ estimateChannelDurationMs ,
831+ ) . map ( ( batch , batchIndex ) =>
832+ createExecutionUnit ( context , {
833+ ...createTargetedUnit ( context , classification , batch ) ,
834+ id : `channels-batch-${ String ( batchIndex + 1 ) } ` ,
835+ } ) ,
836+ ) ;
837+ }
838+ }
807839 return [ createTargetedUnit ( context , classification , uniqueFilters ) ] ;
808840 } ) ;
809841} ;
0 commit comments