@@ -42,7 +42,10 @@ import {
4242} from "../plugins/current-plugin-metadata-snapshot.js" ;
4343import { runGlobalGatewayStopSafely } from "../plugins/hook-runner-global.js" ;
4444import type { PluginHookGatewayCronService } from "../plugins/hook-types.js" ;
45- import { pinActivePluginHttpRouteRegistry } from "../plugins/runtime.js" ;
45+ import {
46+ pinActivePluginChannelRegistry ,
47+ pinActivePluginHttpRouteRegistry ,
48+ } from "../plugins/runtime.js" ;
4649import type { PluginRuntime } from "../plugins/runtime/types.js" ;
4750import { getTotalQueueSize } from "../process/command-queue.js" ;
4851import type { RuntimeEnv } from "../runtime.js" ;
@@ -91,7 +94,11 @@ import {
9194 prepareGatewayPluginBootstrap ,
9295} from "./server-startup-plugins.js" ;
9396import { STARTUP_UNAVAILABLE_GATEWAY_METHODS } from "./server-startup-unavailable-methods.js" ;
94- import { startGatewayEarlyRuntime , startGatewayPostAttachRuntime } from "./server-startup.js" ;
97+ import {
98+ startGatewayEarlyRuntime ,
99+ startGatewayPluginDiscovery ,
100+ startGatewayPostAttachRuntime ,
101+ } from "./server-startup.js" ;
95102import { createWizardSessionTracker } from "./server-wizard-sessions.js" ;
96103import { attachGatewayWsHandlers } from "./server-ws-runtime.js" ;
97104import { createGatewayEventLoopHealthMonitor } from "./server/event-loop-health.js" ;
@@ -1001,6 +1008,36 @@ export async function startGatewayServer(
10011008 Object . assign ( attachedGatewayExtraHandlers , pluginRegistry . gatewayHandlers ) ;
10021009 attachedPluginGatewayHandlerKeys = new Set ( Object . keys ( pluginRegistry . gatewayHandlers ) ) ;
10031010 pinActivePluginHttpRouteRegistry ( pluginRegistry ) ;
1011+ pinActivePluginChannelRegistry ( pluginRegistry ) ;
1012+ } ;
1013+ const refreshAttachedGatewayDiscovery = async ( nextPluginRegistry : typeof pluginRegistry ) => {
1014+ if ( minimalTestGateway ) {
1015+ return ;
1016+ }
1017+ try {
1018+ const stopPreviousDiscovery = runtimeState . bonjourStop ;
1019+ runtimeState . bonjourStop = null ;
1020+ if ( stopPreviousDiscovery ) {
1021+ try {
1022+ await stopPreviousDiscovery ( ) ;
1023+ } catch ( err ) {
1024+ logDiscovery . warn (
1025+ `gateway discovery stop failed before plugin refresh: ${ String ( err ) } ` ,
1026+ ) ;
1027+ }
1028+ }
1029+ runtimeState . bonjourStop = await startGatewayPluginDiscovery ( {
1030+ minimalTestGateway,
1031+ cfgAtStart,
1032+ port,
1033+ gatewayTls,
1034+ tailscaleMode,
1035+ logDiscovery,
1036+ pluginRegistry : nextPluginRegistry ,
1037+ } ) ;
1038+ } catch ( err ) {
1039+ logDiscovery . warn ( `gateway discovery refresh failed after plugin load: ${ String ( err ) } ` ) ;
1040+ }
10041041 } ;
10051042
10061043 const canvasHostServerPort = ( canvasHostServer as CanvasHostServer | null ) ?. port ;
@@ -1084,19 +1121,19 @@ export async function startGatewayServer(
10841121 if ( ! minimalTestGateway ) {
10851122 if ( runtimePluginsLoaded && deferredConfiguredChannelPluginIds . length > 0 ) {
10861123 const { reloadDeferredGatewayPlugins } = await import ( "./server-plugin-bootstrap.js" ) ;
1087- replaceAttachedPluginRuntime (
1088- reloadDeferredGatewayPlugins ( {
1089- cfg : gatewayPluginConfigAtStart ,
1090- activationSourceConfig : startupActivationSourceConfig ,
1091- workspaceDir : defaultWorkspaceDir ,
1092- log ,
1093- coreGatewayMethodNames : baseMethods ,
1094- baseMethods ,
1095- pluginIds : startupPluginIds ,
1096- pluginLookUpTable ,
1097- logDiagnostics : false ,
1098- } ) ,
1099- ) ;
1124+ const loaded = reloadDeferredGatewayPlugins ( {
1125+ cfg : gatewayPluginConfigAtStart ,
1126+ activationSourceConfig : startupActivationSourceConfig ,
1127+ workspaceDir : defaultWorkspaceDir ,
1128+ log ,
1129+ coreGatewayMethodNames : baseMethods ,
1130+ baseMethods,
1131+ pluginIds : startupPluginIds ,
1132+ pluginLookUpTable ,
1133+ logDiagnostics : false ,
1134+ } ) ;
1135+ replaceAttachedPluginRuntime ( loaded ) ;
1136+ await refreshAttachedGatewayDiscovery ( loaded . pluginRegistry ) ;
11001137 }
11011138 }
11021139
@@ -1171,9 +1208,10 @@ export async function startGatewayServer(
11711208 onStartupPluginsLoading : ( ) => {
11721209 startupPendingReason = "plugin-runtime-deps" ;
11731210 } ,
1174- onStartupPluginsLoaded : ( loaded ) => {
1211+ onStartupPluginsLoaded : async ( loaded ) => {
11751212 replaceAttachedPluginRuntime ( loaded ) ;
11761213 startupPendingReason = "startup-sidecars" ;
1214+ await refreshAttachedGatewayDiscovery ( loaded . pluginRegistry ) ;
11771215 } ,
11781216 getCronService : ( ) =>
11791217 runtimeState ?. cronState . cron as PluginHookGatewayCronService | undefined ,
0 commit comments