@@ -84,6 +84,13 @@ interface RemoteEngineFacts {
8484 running : boolean
8585 healthy : boolean
8686 port : number
87+ idleTimeoutSeconds ?: number
88+ }
89+
90+ function readIdleTimeoutSeconds ( value : JsonValue | undefined ) : number | undefined {
91+ return typeof value === 'number' && Number . isInteger ( value ) && value >= 0 && value <= 86400
92+ ? value
93+ : undefined
8794}
8895
8996interface ModularNode {
@@ -1402,6 +1409,10 @@ class ModularBridgeState {
14021409 port : numberValue ( obj . port ) ,
14031410 idle : booleanValue ( obj . idle )
14041411 } )
1412+ const seconds = readIdleTimeoutSeconds ( obj . idle_timeout_s )
1413+ if ( EnginesWithIdleTimeout . includes ( engineType ) && seconds !== undefined ) {
1414+ this . setEngineIdleSeconds ( engineType , seconds )
1415+ }
14051416 // A fresh authoritative state is the resolution of whatever op was in
14061417 // flight (start/stop done, install `done`+installed, uninstall removed).
14071418 // Drop the optimistic status without re-emitting here — the emit below
@@ -1411,10 +1422,15 @@ class ModularBridgeState {
14111422 }
14121423
14131424 /** The expiry the models of an engine show: its idle limit, or the default. */
1414- private expiryFor ( engineType : EngineType ) : ModelExpiry {
1415- const seconds = this . idleSeconds . get ( engineType )
1425+ private expiryFor ( engineType : EngineType , nodeId = this . selfId ) : ModelExpiry {
1426+ if ( ! EnginesWithIdleTimeout . includes ( engineType ) ) return '10m'
1427+ const seconds =
1428+ nodeId && nodeId !== this . selfId
1429+ ? this . remoteEngineFacts . get ( this . remoteOpKey ( nodeId , engineType ) )
1430+ ?. idleTimeoutSeconds
1431+ : this . idleSeconds . get ( engineType )
14161432 if ( seconds !== undefined ) return idleSecondsToExpiry ( seconds )
1417- return EnginesWithIdleTimeout . includes ( engineType ) ? DefaultIdleExpiry : '10m'
1433+ return DefaultIdleExpiry
14181434 }
14191435
14201436 /**
@@ -1877,7 +1893,8 @@ class ModularBridgeState {
18771893 installed : booleanValue ( engineObj . installed ) ,
18781894 running : booleanValue ( engineObj . running ) ,
18791895 healthy : booleanValue ( engineObj . healthy ) ,
1880- port : numberValue ( engineObj . port )
1896+ port : numberValue ( engineObj . port ) ,
1897+ idleTimeoutSeconds : readIdleTimeoutSeconds ( engineObj . idle_timeout_s )
18811898 } )
18821899 seen . add ( engineType )
18831900 }
@@ -1908,7 +1925,8 @@ class ModularBridgeState {
19081925 installed : booleanValue ( obj . installed ) ,
19091926 running : booleanValue ( obj . running ) ,
19101927 healthy : booleanValue ( obj . healthy ) ,
1911- port : numberValue ( obj . port )
1928+ port : numberValue ( obj . port ) ,
1929+ idleTimeoutSeconds : readIdleTimeoutSeconds ( obj . idle_timeout_s )
19121930 } )
19131931 this . emitRemoteEngineStatus ( nodeId , engineType )
19141932 }
@@ -2088,11 +2106,12 @@ class ModularBridgeState {
20882106
20892107 private toEngineModels ( node : ModularNode , engine : ProxyEngine ) : EngineModels {
20902108 const loaded = loadedNamesForEngine ( node , engine )
2109+ const expiry = this . expiryFor ( engine , node . id )
20912110 return {
20922111 engineType : engine ,
20932112 nodeId : node . id ,
20942113 models : this . modelsForEngine ( node , engine ) . map ( name =>
2095- modelItem ( name , loaded . has ( name ) )
2114+ modelItem ( name , loaded . has ( name ) , expiry )
20962115 )
20972116 }
20982117 }
0 commit comments