66 type OpenClawConfig ,
77 applyConfigOverrides ,
88 isNixMode ,
9- readConfigFileSnapshot ,
9+ readConfigFileSnapshotWithPluginMetadata ,
1010 recoverConfigFromLastKnownGood ,
1111 recoverConfigFromJsonRootSuffix ,
1212 replaceConfigFile ,
@@ -18,6 +18,7 @@ import { formatConfigIssueLines } from "../config/issue-format.js";
1818import { asResolvedSourceConfig , materializeRuntimeConfig } from "../config/materialize.js" ;
1919import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js" ;
2020import { isTruthyEnvValue } from "../infra/env.js" ;
21+ import type { PluginMetadataSnapshot } from "../plugins/plugin-metadata-snapshot.js" ;
2122import {
2223 GATEWAY_AUTH_SURFACE_PATHS ,
2324 evaluateGatewayAuthSurfaceStates ,
@@ -61,6 +62,7 @@ type GatewayStartupConfigMeasure = <T>(name: string, run: () => T | Promise<T>)
6162export type GatewayStartupConfigSnapshotLoadResult = {
6263 snapshot : ConfigFileSnapshot ;
6364 wroteConfig : boolean ;
65+ pluginMetadataSnapshot ?: PluginMetadataSnapshot ;
6466 degradedProviderApi ?: boolean ;
6567 degradedPluginConfig ?: boolean ;
6668} ;
@@ -192,9 +194,11 @@ export async function loadGatewayStartupConfigSnapshot(params: {
192194 measure ?: GatewayStartupConfigMeasure ;
193195} ) : Promise < GatewayStartupConfigSnapshotLoadResult > {
194196 const measure = params . measure ?? ( async ( _name , run ) => await run ( ) ) ;
195- let configSnapshot = await measure ( "config.snapshot.read" , ( ) =>
196- readConfigFileSnapshot ( { measure } ) ,
197+ let snapshotRead = await measure ( "config.snapshot.read" , ( ) =>
198+ readConfigFileSnapshotWithPluginMetadata ( { measure } ) ,
197199 ) ;
200+ let configSnapshot = snapshotRead . snapshot ;
201+ let pluginMetadataSnapshot = snapshotRead . pluginMetadataSnapshot ;
198202 let wroteConfig = false ;
199203 let degradedStartupConfig = false ;
200204 let degradedPluginConfig = false ;
@@ -242,9 +246,11 @@ export async function loadGatewayStartupConfigSnapshot(params: {
242246 params . log . warn (
243247 `gateway: invalid config was restored from last-known-good backup: ${ configSnapshot . path } ` ,
244248 ) ;
245- configSnapshot = await measure ( "config.snapshot.recovery-read" , ( ) =>
246- readConfigFileSnapshot ( { measure } ) ,
249+ snapshotRead = await measure ( "config.snapshot.recovery-read" , ( ) =>
250+ readConfigFileSnapshotWithPluginMetadata ( { measure } ) ,
247251 ) ;
252+ configSnapshot = snapshotRead . snapshot ;
253+ pluginMetadataSnapshot = snapshotRead . pluginMetadataSnapshot ;
248254 if ( configSnapshot . valid ) {
249255 enqueueConfigRecoveryNotice ( {
250256 cfg : configSnapshot . config ,
@@ -259,9 +265,11 @@ export async function loadGatewayStartupConfigSnapshot(params: {
259265 params . log . warn (
260266 `gateway: invalid config was repaired by stripping a non-JSON prefix: ${ configSnapshot . path } ` ,
261267 ) ;
262- configSnapshot = await measure ( "config.snapshot.prefix-recovery-read" , ( ) =>
263- readConfigFileSnapshot ( { measure } ) ,
268+ snapshotRead = await measure ( "config.snapshot.prefix-recovery-read" , ( ) =>
269+ readConfigFileSnapshotWithPluginMetadata ( { measure } ) ,
264270 ) ;
271+ configSnapshot = snapshotRead . snapshot ;
272+ pluginMetadataSnapshot = snapshotRead . pluginMetadataSnapshot ;
265273 }
266274 }
267275 assertValidGatewayStartupConfigSnapshot ( configSnapshot , { includeDoctorHint : true } ) ;
@@ -274,15 +282,16 @@ export async function loadGatewayStartupConfigSnapshot(params: {
274282 applyPluginAutoEnable ( {
275283 config : configSnapshot . sourceConfig ,
276284 env : process . env ,
277- ...( configSnapshot . pluginMetadataSnapshot ?. manifestRegistry
278- ? { manifestRegistry : configSnapshot . pluginMetadataSnapshot . manifestRegistry }
285+ ...( pluginMetadataSnapshot ?. manifestRegistry
286+ ? { manifestRegistry : pluginMetadataSnapshot . manifestRegistry }
279287 : { } ) ,
280288 } ) ,
281289 ) ;
282290 if ( autoEnable . changes . length === 0 ) {
283291 return {
284292 snapshot : configSnapshot ,
285293 wroteConfig,
294+ ...( pluginMetadataSnapshot ? { pluginMetadataSnapshot } : { } ) ,
286295 ...( degradedStartupConfig ? { degradedProviderApi : true } : { } ) ,
287296 ...( degradedPluginConfig ? { degradedPluginConfig : true } : { } ) ,
288297 } ;
@@ -294,9 +303,11 @@ export async function loadGatewayStartupConfigSnapshot(params: {
294303 afterWrite : { mode : "auto" } ,
295304 } ) ;
296305 wroteConfig = true ;
297- configSnapshot = await measure ( "config.snapshot.auto-enable-read" , ( ) =>
298- readConfigFileSnapshot ( { measure } ) ,
306+ snapshotRead = await measure ( "config.snapshot.auto-enable-read" , ( ) =>
307+ readConfigFileSnapshotWithPluginMetadata ( { measure } ) ,
299308 ) ;
309+ configSnapshot = snapshotRead . snapshot ;
310+ pluginMetadataSnapshot = snapshotRead . pluginMetadataSnapshot ;
300311 assertValidGatewayStartupConfigSnapshot ( configSnapshot ) ;
301312 params . log . info (
302313 `gateway: auto-enabled plugins:\n${ autoEnable . changes . map ( ( entry ) => `- ${ entry } ` ) . join ( "\n" ) } ` ,
@@ -308,6 +319,7 @@ export async function loadGatewayStartupConfigSnapshot(params: {
308319 return {
309320 snapshot : configSnapshot ,
310321 wroteConfig,
322+ ...( pluginMetadataSnapshot ? { pluginMetadataSnapshot } : { } ) ,
311323 ...( degradedStartupConfig ? { degradedProviderApi : true } : { } ) ,
312324 ...( degradedPluginConfig ? { degradedPluginConfig : true } : { } ) ,
313325 } ;
0 commit comments