@@ -1114,14 +1114,13 @@ export async function startGatewayServer(
11141114 getActiveTaskCount = earlyRuntime . getActiveTaskCount ;
11151115 runtimeState . skillsChangeUnsub = earlyRuntime . skillsChangeUnsub ;
11161116
1117- const [ { startGatewayEventSubscriptions } , gatewayRuntimeServices ] = await startupTrace . measure (
1118- "runtime.post-early-imports" ,
1119- ( ) =>
1117+ const [ { startGatewayEventSubscriptions } , { startGatewayRuntimeServices } ] =
1118+ await startupTrace . measure ( "runtime.post-early-imports" , ( ) =>
11201119 Promise . all ( [
11211120 import ( "./server-runtime-subscriptions.js" ) ,
1122- import ( "./server-runtime-services.js" ) ,
1121+ import ( "./server-runtime-startup- services.js" ) ,
11231122 ] ) ,
1124- ) ;
1123+ ) ;
11251124 const runtimeSubscriptions = await startupTrace . measure ( "runtime.subscriptions" , ( ) =>
11261125 startGatewayEventSubscriptions ( {
11271126 broadcast,
@@ -1138,7 +1137,7 @@ export async function startGatewayServer(
11381137 Object . assign ( runtimeState , runtimeSubscriptions ) ;
11391138
11401139 const runtimeServices = await startupTrace . measure ( "runtime.services" , ( ) =>
1141- gatewayRuntimeServices . startGatewayRuntimeServices ( {
1140+ startGatewayRuntimeServices ( {
11421141 minimalTestGateway,
11431142 cfgAtStart,
11441143 channelManager,
@@ -1516,6 +1515,13 @@ export async function startGatewayServer(
15161515 const sessionDeliveryRecoveryMaxEnqueuedAt = Date . now ( ) ;
15171516 let postAttachRuntimeReturned = false ;
15181517 let scheduledServicesActivated = false ;
1518+ let scheduledServicesModulePromise : Promise <
1519+ typeof import ( "./server-runtime-services.js" )
1520+ > | null = null ;
1521+ const loadScheduledServicesModule = ( ) => {
1522+ scheduledServicesModulePromise ??= import ( "./server-runtime-services.js" ) ;
1523+ return scheduledServicesModulePromise ;
1524+ } ;
15191525 const activateScheduledServicesWhenReady = ( ) => {
15201526 if (
15211527 closePreludeStarted ||
@@ -1525,20 +1531,25 @@ export async function startGatewayServer(
15251531 ) {
15261532 return ;
15271533 }
1528- const activated = gatewayRuntimeServices . activateGatewayScheduledServices ( {
1529- minimalTestGateway,
1530- cfgAtStart,
1531- deps,
1532- sessionDeliveryRecoveryMaxEnqueuedAt,
1533- cron : runtimeState . cronState . cron ,
1534- startCron : false ,
1535- logCron,
1536- log,
1537- pluginLookUpTable,
1538- } ) ;
15391534 scheduledServicesActivated = true ;
1540- runtimeState . heartbeatRunner = activated . heartbeatRunner ;
1541- runtimeState . stopModelPricingRefresh = activated . stopModelPricingRefresh ;
1535+ void loadScheduledServicesModule ( ) . then ( ( gatewayRuntimeServices ) => {
1536+ if ( closePreludeStarted ) {
1537+ return ;
1538+ }
1539+ const activated = gatewayRuntimeServices . activateGatewayScheduledServices ( {
1540+ minimalTestGateway,
1541+ cfgAtStart,
1542+ deps,
1543+ sessionDeliveryRecoveryMaxEnqueuedAt,
1544+ cron : runtimeState . cronState . cron ,
1545+ startCron : false ,
1546+ logCron,
1547+ log,
1548+ pluginLookUpTable,
1549+ } ) ;
1550+ runtimeState . heartbeatRunner = activated . heartbeatRunner ;
1551+ runtimeState . stopModelPricingRefresh = activated . stopModelPricingRefresh ;
1552+ } ) ;
15421553 } ;
15431554 ( {
15441555 stopGatewayUpdateCheck : runtimeState . stopGatewayUpdateCheck ,
@@ -1693,6 +1704,7 @@ export async function startGatewayServer(
16931704 log . warn ( `gateway: failed to promote config last-known-good backup: ${ String ( err ) } ` ) ;
16941705 } ) ;
16951706 if ( ! minimalTestGateway ) {
1707+ const gatewayRuntimeServices = await loadScheduledServicesModule ( ) ;
16961708 postReadyMaintenanceTimer = gatewayRuntimeServices . scheduleGatewayPostReadyMaintenance ( {
16971709 delayMs : POST_READY_MAINTENANCE_DELAY_MS ,
16981710 isClosing : ( ) => closePreludeStarted ,
0 commit comments