Gateway: defer full channel plugins until after listen

This commit is contained in:
Gustavo Madeira Santana
2026-03-16 13:30:24 +00:00
parent 541e697554
commit 1b234b910b
5 changed files with 212 additions and 11 deletions

View File

@@ -54,6 +54,7 @@ export type PluginLoadOptions = {
mode?: "full" | "validate";
onlyPluginIds?: string[];
includeSetupOnlyChannelPlugins?: boolean;
preferSetupRuntimeForChannelPlugins?: boolean;
activate?: boolean;
};
@@ -336,6 +337,7 @@ function buildCacheKey(params: {
env: NodeJS.ProcessEnv;
onlyPluginIds?: string[];
includeSetupOnlyChannelPlugins?: boolean;
preferSetupRuntimeForChannelPlugins?: boolean;
}): string {
const { roots, loadPaths } = resolvePluginCacheInputs({
workspaceDir: params.workspaceDir,
@@ -360,11 +362,13 @@ function buildCacheKey(params: {
);
const scopeKey = JSON.stringify(params.onlyPluginIds ?? []);
const setupOnlyKey = params.includeSetupOnlyChannelPlugins === true ? "setup-only" : "runtime";
const startupChannelMode =
params.preferSetupRuntimeForChannelPlugins === true ? "prefer-setup" : "full";
return `${roots.workspace ?? ""}::${roots.global ?? ""}::${roots.stock ?? ""}::${JSON.stringify({
...params.plugins,
installs,
loadPaths,
})}::${scopeKey}::${setupOnlyKey}`;
})}::${scopeKey}::${setupOnlyKey}::${startupChannelMode}`;
}
function normalizeScopedPluginIds(ids?: string[]): string[] | undefined {
@@ -447,10 +451,14 @@ function shouldLoadChannelPluginInSetupRuntime(params: {
setupSource?: string;
cfg: OpenClawConfig;
env: NodeJS.ProcessEnv;
preferSetupRuntimeForChannelPlugins?: boolean;
}): boolean {
if (!params.setupSource || params.manifestChannels.length === 0) {
return false;
}
if (params.preferSetupRuntimeForChannelPlugins) {
return true;
}
return !params.manifestChannels.some((channelId) =>
isChannelConfigured(params.cfg, channelId, params.env),
);
@@ -800,6 +808,7 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi
const onlyPluginIds = normalizeScopedPluginIds(options.onlyPluginIds);
const onlyPluginIdSet = onlyPluginIds ? new Set(onlyPluginIds) : null;
const includeSetupOnlyChannelPlugins = options.includeSetupOnlyChannelPlugins === true;
const preferSetupRuntimeForChannelPlugins = options.preferSetupRuntimeForChannelPlugins === true;
const shouldActivate = options.activate !== false;
// NOTE: `activate` is intentionally excluded from the cache key. All non-activating
// (snapshot) callers pass `cache: false` via loadOnboardingPluginRegistry(), so they
@@ -812,6 +821,7 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi
env,
onlyPluginIds,
includeSetupOnlyChannelPlugins,
preferSetupRuntimeForChannelPlugins,
});
const cacheEnabled = options.cache !== false;
if (cacheEnabled) {
@@ -1068,6 +1078,7 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi
setupSource: manifestRecord.setupSource,
cfg,
env,
preferSetupRuntimeForChannelPlugins,
})
? "setup-runtime"
: "full"