@@ -80,6 +80,7 @@ import {
8080import { shouldRewarmProviderAuthState } from "./config-reload-recovery.js" ;
8181import { applyHookMappings } from "./hooks-mapping.js" ;
8282import { commitHooksConfigReload } from "./hooks.js" ;
83+ import type { GatewayCronState } from "./server-cron.js" ;
8384import type { GatewayPluginReloadResult } from "./server-reload-handlers.js" ;
8485import {
8586 abortPendingChannelReloads ,
@@ -157,16 +158,26 @@ function createDefaultGatewayReloadState(
157158 hooksConfig : { } as never ,
158159 hookClientIpConfig : { } as never ,
159160 heartbeatRunner : { stop : vi . fn ( ) , updateConfig : vi . fn ( ) } as never ,
160- cronState : {
161- cron : { start : vi . fn ( async ( ) => { } ) , stop : vi . fn ( ) } ,
162- storePath : "/tmp/cron.json" ,
163- cronEnabled : false ,
164- } as never ,
161+ cronState : createTestCronState ( ) ,
165162 channelHealthMonitor : null ,
166163 ...overrides ,
167164 } ;
168165}
169166
167+ function createTestCronState ( overrides : Partial < GatewayCronState > = { } ) : GatewayCronState {
168+ return {
169+ cron : { start : vi . fn ( async ( ) => { } ) , stop : vi . fn ( ) } as never ,
170+ storePath : "/tmp/cron.json" ,
171+ cronEnabled : false ,
172+ reconcileExitWatchers : vi . fn ( async ( ) => { } ) ,
173+ stopExitWatchers : vi . fn ( ) ,
174+ reconcileStreamWatchers : vi . fn ( async ( ) => { } ) ,
175+ stopStreamWatchers : vi . fn ( async ( ) => { } ) ,
176+ reconcileHeartbeatJobs : vi . fn ( async ( ) => { } ) ,
177+ ...overrides ,
178+ } ;
179+ }
180+
170181function startManagedGatewayConfigReloader ( params : ManagedReloaderTestParams ) {
171182 return startManagedGatewayConfigReloaderImpl ( {
172183 minimalTestGateway : false ,
@@ -266,6 +277,9 @@ const hoisted = vi.hoisted(() => ({
266277 cronEnabled : true ,
267278 reconcileExitWatchers : vi . fn ( async ( ) => { } ) ,
268279 stopExitWatchers : vi . fn ( ) ,
280+ reconcileStreamWatchers : vi . fn ( async ( ) => { } ) ,
281+ stopStreamWatchers : vi . fn ( async ( ) => { } ) ,
282+ reconcileHeartbeatJobs : vi . fn ( async ( ) => { } ) ,
269283 } ) ) ,
270284} ) ) ;
271285
@@ -597,6 +611,7 @@ function createReloadHandlersForTest(
597611) {
598612 const cron = { start : vi . fn ( async ( ) => { } ) , stop : vi . fn ( ) } ;
599613 const stopExitWatchers = vi . fn ( ) ;
614+ const reconcileHeartbeatJobs = vi . fn ( async ( ) => { } ) ;
600615 const heartbeatRunner = {
601616 stop : vi . fn ( ) ,
602617 updateConfig : vi . fn ( ) ,
@@ -605,12 +620,11 @@ function createReloadHandlersForTest(
605620 hooksConfig : { } as never ,
606621 hookClientIpConfig : { } as never ,
607622 heartbeatRunner : heartbeatRunner as never ,
608- cronState : {
609- cron,
610- storePath : "/tmp/cron.json" ,
611- cronEnabled : false ,
623+ cronState : createTestCronState ( {
624+ cron : cron as never ,
612625 stopExitWatchers,
613- } as never ,
626+ reconcileHeartbeatJobs,
627+ } ) ,
614628 channelHealthMonitor : null ,
615629 } ;
616630 const setState = vi . fn ( ( nextState : typeof state ) => {
@@ -646,6 +660,7 @@ function createReloadHandlersForTest(
646660 heartbeatRunner,
647661 logChannels,
648662 logCron,
663+ reconcileHeartbeatJobs,
649664 setState,
650665 stopExitWatchers,
651666 } ;
@@ -1191,6 +1206,9 @@ describe("gateway hot reload model state", () => {
11911206 cronEnabled : true ,
11921207 reconcileExitWatchers : newReconcileExitWatchers ,
11931208 stopExitWatchers : vi . fn ( ) ,
1209+ reconcileStreamWatchers : vi . fn ( async ( ) => { } ) ,
1210+ stopStreamWatchers : vi . fn ( async ( ) => { } ) ,
1211+ reconcileHeartbeatJobs : vi . fn ( async ( ) => { } ) ,
11941212 } ;
11951213 hoisted . buildGatewayCronService . mockImplementationOnce ( ( ) => {
11961214 order . push ( "build-new" ) ;
@@ -1251,6 +1269,9 @@ describe("gateway hot reload model state", () => {
12511269 cronEnabled : false ,
12521270 reconcileExitWatchers : vi . fn ( async ( ) => { } ) ,
12531271 stopExitWatchers : vi . fn ( ) ,
1272+ reconcileStreamWatchers : vi . fn ( async ( ) => { } ) ,
1273+ stopStreamWatchers : vi . fn ( async ( ) => { } ) ,
1274+ reconcileHeartbeatJobs : vi . fn ( async ( ) => { } ) ,
12541275 } ;
12551276 hoisted . buildGatewayCronService . mockReturnValueOnce ( rebuiltCronState ) ;
12561277 const { applyHotReload, cronReconciliation } = createReloadHandlersForTest ( ) ;
@@ -1290,20 +1311,18 @@ describe("gateway hot reload model state", () => {
12901311 } ) ;
12911312
12921313 it ( "applies an in-place heartbeat update without a recovery restart owner" , async ( ) => {
1293- const { applyHotReload, heartbeatRunner, setState } = createReloadHandlersForTest (
1294- undefined ,
1295- undefined ,
1296- undefined ,
1297- vi . fn ( ) ,
1298- false ,
1299- ) ;
1314+ const { applyHotReload, heartbeatRunner, reconcileHeartbeatJobs, setState } =
1315+ createReloadHandlersForTest ( undefined , undefined , undefined , vi . fn ( ) , false ) ;
13001316 const nextConfig = { agents : { defaults : { heartbeat : { every : "1h" } } } } as OpenClawConfig ;
13011317
13021318 await expect (
13031319 applyHotReload ( createHotTailPlan ( { restartHeartbeat : true } ) , nextConfig ) ,
13041320 ) . resolves . toBeUndefined ( ) ;
13051321
13061322 expect ( heartbeatRunner . updateConfig ) . toHaveBeenCalledWith ( nextConfig ) ;
1323+ // Heartbeat cadence lives in system-owned cron monitor jobs; the reload
1324+ // must reconverge them or `heartbeat.every` changes silently never apply.
1325+ await waitForFast ( ( ) => expect ( reconcileHeartbeatJobs ) . toHaveBeenCalledWith ( nextConfig ) ) ;
13071326 expect ( setState ) . toHaveBeenCalledOnce ( ) ;
13081327 } ) ;
13091328
@@ -1358,6 +1377,9 @@ describe("gateway hot reload model state", () => {
13581377 cronEnabled : true ,
13591378 reconcileExitWatchers : vi . fn ( async ( ) => { } ) ,
13601379 stopExitWatchers : vi . fn ( ) ,
1380+ reconcileStreamWatchers : vi . fn ( async ( ) => { } ) ,
1381+ stopStreamWatchers : vi . fn ( async ( ) => { } ) ,
1382+ reconcileHeartbeatJobs : vi . fn ( async ( ) => { } ) ,
13611383 } ) ;
13621384 const { applyHotReload, setState } = createReloadHandlersForTest ( logReload ) ;
13631385
@@ -1391,13 +1413,19 @@ describe("gateway hot reload model state", () => {
13911413 cronEnabled : true ,
13921414 reconcileExitWatchers : vi . fn ( async ( ) => { } ) ,
13931415 stopExitWatchers : vi . fn ( ) ,
1416+ reconcileStreamWatchers : vi . fn ( async ( ) => { } ) ,
1417+ stopStreamWatchers : vi . fn ( async ( ) => { } ) ,
1418+ reconcileHeartbeatJobs : vi . fn ( async ( ) => { } ) ,
13941419 } ;
13951420 const secondCronState = {
13961421 cron : { start : vi . fn ( async ( ) => { } ) , stop : vi . fn ( ) } ,
13971422 storePath : "/tmp/second-cron.json" ,
13981423 cronEnabled : true ,
13991424 reconcileExitWatchers : vi . fn ( async ( ) => { } ) ,
14001425 stopExitWatchers : vi . fn ( ) ,
1426+ reconcileStreamWatchers : vi . fn ( async ( ) => { } ) ,
1427+ stopStreamWatchers : vi . fn ( async ( ) => { } ) ,
1428+ reconcileHeartbeatJobs : vi . fn ( async ( ) => { } ) ,
14011429 } ;
14021430 hoisted . buildGatewayCronService
14031431 . mockReturnValueOnce ( firstCronState )
@@ -2021,11 +2049,7 @@ describe("gateway hot reload commit policy", () => {
20212049 hooksConfig : { } as never ,
20222050 hookClientIpConfig : { } as never ,
20232051 heartbeatRunner : { stop : vi . fn ( ) , updateConfig : vi . fn ( ) } as never ,
2024- cronState : {
2025- cron : { start : vi . fn ( async ( ) => { } ) , stop : vi . fn ( ) } ,
2026- storePath : "/tmp/cron.json" ,
2027- cronEnabled : false ,
2028- } as never ,
2052+ cronState : createTestCronState ( ) ,
20292053 channelHealthMonitor : oldMonitor as never ,
20302054 } ;
20312055 const setState = vi . fn ( ( nextState : typeof state ) => {
@@ -3499,11 +3523,7 @@ describe("gateway Gmail hot reload handlers", () => {
34993523 getState : ( ) =>
35003524 createDefaultGatewayReloadState ( {
35013525 heartbeatRunner : heartbeatRunner as never ,
3502- cronState : {
3503- cron : { start : vi . fn ( async ( ) => { } ) , stop : vi . fn ( ) } ,
3504- storePath : "/tmp/cron.json" ,
3505- cronEnabled : false ,
3506- } as never ,
3526+ cronState : createTestCronState ( ) ,
35073527 } ) ,
35083528 activateRuntimeSecrets : activateRuntimeSecrets as never ,
35093529 commitTerminalConfig,
@@ -4919,6 +4939,9 @@ describe("gateway plugin hot reload handlers", () => {
49194939 cronEnabled : true ,
49204940 reconcileExitWatchers : vi . fn ( async ( ) => { } ) ,
49214941 stopExitWatchers : vi . fn ( ) ,
4942+ reconcileStreamWatchers : vi . fn ( async ( ) => { } ) ,
4943+ stopStreamWatchers : vi . fn ( async ( ) => { } ) ,
4944+ reconcileHeartbeatJobs : vi . fn ( async ( ) => { } ) ,
49224945 } ;
49234946 hoisted . buildGatewayCronService . mockImplementationOnce ( ( params ) => {
49244947 events . push ( `cron-build:${ params ?. env ?. [ envKey ] } :${ targetEnv [ envKey ] } ` ) ;
0 commit comments