99 waitForMediaCleanupDrains ,
1010} from "./server-media-cleanup-lifecycle.js" ;
1111import { createNoopHeartbeatRunner } from "./server-runtime-service-shared.js" ;
12+ import type { GatewayMaintenanceHandles } from "./server-runtime-services.js" ;
1213import type { GatewayPostReadySidecarHandle } from "./server-startup-post-attach.js" ;
1314
1415// Mutable server handles track timers, sidecars, subscriptions, and service
@@ -25,12 +26,8 @@ export type GatewayConfigReloaderHandle = {
2526/** Mutable handles owned by a running gateway server process. */
2627export type GatewayServerMutableState = {
2728 bonjourStop : ( ( ) => Promise < void > ) | null ;
28- tickInterval : ReturnType < typeof setInterval > ;
29- healthInterval : ReturnType < typeof setInterval > ;
30- dedupeCleanup : ReturnType < typeof setInterval > ;
29+ maintenance : GatewayMaintenanceHandles | null ;
3130 stopMediaCleanup : ( ) => Promise < MediaCleanupStopResult > ;
32- worktreeCleanup : ReturnType < typeof setInterval > | null ;
33- skillCuratorCleanup : ( ) => void ;
3431 heartbeatRunner : HeartbeatRunner ;
3532 stopOutboundDeliveryRecovery : ( ) => Promise < void > ;
3633 stopGatewayUpdateCheck : ( ) => void ;
@@ -41,7 +38,6 @@ export type GatewayServerMutableState = {
4138 skillsRefreshDelayMs : number ;
4239 skillsChangeUnsub : ( ) => Promise < void > ;
4340 channelHealthMonitor : ChannelHealthMonitor | null ;
44- mcpServer : { port : number ; close : ( ) => Promise < void > } | undefined ;
4541 configReloader : GatewayConfigReloaderHandle ;
4642 agentUnsub : ( ( ) => Promise < void > | void ) | null ;
4743 heartbeatUnsub : ( ( ) => void ) | null ;
@@ -52,21 +48,10 @@ export type GatewayServerMutableState = {
5248
5349/** Creates gateway mutable state with inert handles that are safe to stop before startup finishes. */
5450export function createGatewayServerMutableState ( ) : GatewayServerMutableState {
55- const noopInterval = ( ) => {
56- // Dummy unref'd timers give shutdown code a concrete handle to clear even
57- // when startup exits before real maintenance intervals are installed.
58- const timer = setInterval ( ( ) => { } , 1 << 30 ) ;
59- timer . unref ?.( ) ;
60- return timer ;
61- } ;
6251 return {
6352 bonjourStop : null as ( ( ) => Promise < void > ) | null ,
64- tickInterval : noopInterval ( ) ,
65- healthInterval : noopInterval ( ) ,
66- dedupeCleanup : noopInterval ( ) ,
53+ maintenance : null ,
6754 stopMediaCleanup : ( ) => waitForMediaCleanupDrains ( { timeoutMs : MEDIA_CLEANUP_STOP_TIMEOUT_MS } ) ,
68- worktreeCleanup : null as ReturnType < typeof setInterval > | null ,
69- skillCuratorCleanup : ( ) => { } ,
7055 heartbeatRunner : createNoopHeartbeatRunner ( ) ,
7156 stopOutboundDeliveryRecovery : async ( ) => { } ,
7257 stopGatewayUpdateCheck : ( ) => { } ,
@@ -77,7 +62,6 @@ export function createGatewayServerMutableState(): GatewayServerMutableState {
7762 skillsRefreshDelayMs : 30_000 ,
7863 skillsChangeUnsub : async ( ) => { } ,
7964 channelHealthMonitor : null as ChannelHealthMonitor | null ,
80- mcpServer : undefined as { port : number ; close : ( ) => Promise < void > } | undefined ,
8165 configReloader : {
8266 stop : async ( ) => { } ,
8367 notifyPluginMetadataChanged : ( ) => { } ,
0 commit comments