From a24d5fe79066acfa56288244b3852f4f322cdea1 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 6 May 2026 10:17:27 +0100 Subject: [PATCH] perf(config): avoid duplicate plugin auto-enable channel probes --- src/config/plugin-auto-enable.detect.ts | 6 ++-- src/config/plugin-auto-enable.shared.ts | 44 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/config/plugin-auto-enable.detect.ts b/src/config/plugin-auto-enable.detect.ts index e84e32e0c23..7d06705fd5a 100644 --- a/src/config/plugin-auto-enable.detect.ts +++ b/src/config/plugin-auto-enable.detect.ts @@ -1,7 +1,7 @@ import type { PluginManifestRegistry } from "../plugins/manifest-registry.js"; import { - configMayNeedPluginAutoEnable, resolveConfiguredPluginAutoEnableCandidates, + resolvePluginAutoEnableReadiness, resolvePluginAutoEnableManifestRegistry, } from "./plugin-auto-enable.shared.js"; import type { PluginAutoEnableCandidate } from "./plugin-auto-enable.types.js"; @@ -14,7 +14,8 @@ export function detectPluginAutoEnableCandidates(params: { }): PluginAutoEnableCandidate[] { const env = params.env ?? process.env; const config = params.config ?? ({} as OpenClawConfig); - if (!configMayNeedPluginAutoEnable(config, env)) { + const readiness = resolvePluginAutoEnableReadiness(config, env); + if (!readiness.mayNeedAutoEnable) { return []; } const registry = resolvePluginAutoEnableManifestRegistry({ @@ -26,5 +27,6 @@ export function detectPluginAutoEnableCandidates(params: { config, env, registry, + configuredChannelIds: readiness.configuredChannelIds, }); } diff --git a/src/config/plugin-auto-enable.shared.ts b/src/config/plugin-auto-enable.shared.ts index cb9d2a2e18e..10644abbe98 100644 --- a/src/config/plugin-auto-enable.shared.ts +++ b/src/config/plugin-auto-enable.shared.ts @@ -482,38 +482,48 @@ export function configMayNeedPluginAutoEnable( cfg: OpenClawConfig, env: NodeJS.ProcessEnv, ): boolean { + return resolvePluginAutoEnableReadiness(cfg, env).mayNeedAutoEnable; +} + +export function resolvePluginAutoEnableReadiness( + cfg: OpenClawConfig, + env: NodeJS.ProcessEnv, +): { mayNeedAutoEnable: boolean; configuredChannelIds: string[] } { if (arePluginsGloballyDisabled(cfg)) { - return false; + return { mayNeedAutoEnable: false, configuredChannelIds: [] }; } if (hasPluginAllowlistWithMaterialEntries(cfg)) { - return true; + return { mayNeedAutoEnable: true, configuredChannelIds: [] }; } if (hasConfiguredPluginConfigEntry(cfg)) { - return true; + return { mayNeedAutoEnable: true, configuredChannelIds: [] }; } - if (collectConfiguredChannelIds(cfg, env).length > 0) { - return true; + const configuredChannelIds = collectConfiguredChannelIds(cfg, env); + if (configuredChannelIds.length > 0) { + return { mayNeedAutoEnable: true, configuredChannelIds }; } if (hasConfiguredProviderModelOrHarness(cfg, env)) { - return true; + return { mayNeedAutoEnable: true, configuredChannelIds }; } if ( hasConfiguredWebSearchProviderSelection(cfg) || hasConfiguredWebSearchPluginEntry(cfg) || hasConfiguredWebFetchPluginEntry(cfg) ) { - return true; + return { mayNeedAutoEnable: true, configuredChannelIds }; } if (!hasSetupAutoEnableRelevantConfig(cfg)) { - return false; + return { mayNeedAutoEnable: false, configuredChannelIds }; } - return ( - resolvePluginSetupAutoEnableReasons({ - config: cfg, - env, - pluginIds: resolveRelevantSetupAutoEnablePluginIds(cfg), - }).length > 0 - ); + return { + mayNeedAutoEnable: + resolvePluginSetupAutoEnableReasons({ + config: cfg, + env, + pluginIds: resolveRelevantSetupAutoEnablePluginIds(cfg), + }).length > 0, + configuredChannelIds, + }; } export function resolvePluginAutoEnableCandidateReason( @@ -548,9 +558,11 @@ export function resolveConfiguredPluginAutoEnableCandidates(params: { config: OpenClawConfig; env: NodeJS.ProcessEnv; registry: PluginManifestRegistry; + configuredChannelIds?: readonly string[]; }): PluginAutoEnableCandidate[] { const changes: PluginAutoEnableCandidate[] = []; - for (const channelId of collectConfiguredChannelIds(params.config, params.env)) { + for (const channelId of params.configuredChannelIds ?? + collectConfiguredChannelIds(params.config, params.env)) { for (const pluginId of collectPluginIdsForConfiguredChannel(channelId, params.registry)) { changes.push({ pluginId, kind: "channel-configured", channelId }); }