fix: reuse plugin snapshot for read-only channels

This commit is contained in:
Shakker
2026-05-06 07:00:31 +01:00
parent df209586bd
commit fe393e4427
2 changed files with 37 additions and 14 deletions

View File

@@ -1,5 +1,6 @@
import type { OpenClawConfig } from "../../config/types.openclaw.js";
import { isBlockedObjectKey } from "../../infra/prototype-keys.js";
import { getCurrentPluginMetadataSnapshot } from "../../plugins/current-plugin-metadata-snapshot.js";
import { isInstalledPluginEnabled } from "../../plugins/installed-plugin-index.js";
import type { PluginManifestRecord } from "../../plugins/manifest-registry.js";
import { loadPluginMetadataSnapshot } from "../../plugins/plugin-metadata-snapshot.js";
@@ -64,17 +65,28 @@ export function resolveReadOnlyChannelCommandDefaults(
if (!normalizedChannelId || !isSafeManifestChannelId(normalizedChannelId)) {
return undefined;
}
const snapshot = loadPluginMetadataSnapshot({
config: options.config,
stateDir: options.stateDir,
workspaceDir: options.workspaceDir,
env: options.env ?? process.env,
});
for (const record of snapshot.plugins) {
const env = options.env ?? process.env;
const snapshot =
options.stateDir === undefined
? getCurrentPluginMetadataSnapshot({
config: options.config,
env,
workspaceDir: options.workspaceDir,
})
: undefined;
const resolvedSnapshot =
snapshot ??
loadPluginMetadataSnapshot({
config: options.config,
stateDir: options.stateDir,
workspaceDir: options.workspaceDir,
env,
});
for (const record of resolvedSnapshot.plugins) {
if (!record.channels.includes(normalizedChannelId)) {
continue;
}
if (!isInstalledPluginEnabled(snapshot.index, record.id, options.config)) {
if (!isInstalledPluginEnabled(resolvedSnapshot.index, record.id, options.config)) {
continue;
}
const channelConfigValue = record.channelConfigs

View File

@@ -10,6 +10,7 @@ import {
listConfiguredChannelIdsForReadOnlyScope,
resolveDiscoverableScopedChannelPluginIds,
} from "../../plugins/channel-plugin-ids.js";
import { getCurrentPluginMetadataSnapshot } from "../../plugins/current-plugin-metadata-snapshot.js";
import {
channelPluginIdBelongsToManifest,
resolveSetupChannelRegistration,
@@ -697,12 +698,22 @@ export function resolveReadOnlyChannelPluginsForConfig(
): ReadOnlyChannelPluginResolution {
const env = options.env ?? process.env;
const workspaceDir = resolveReadOnlyWorkspaceDir(cfg, options);
const manifestRecords = loadPluginMetadataSnapshot({
config: cfg,
stateDir: options.stateDir,
workspaceDir,
env,
}).plugins;
const metadataSnapshot =
options.stateDir === undefined
? getCurrentPluginMetadataSnapshot({
config: cfg,
env,
workspaceDir,
})
: undefined;
const manifestRecords =
metadataSnapshot?.plugins ??
loadPluginMetadataSnapshot({
config: cfg,
stateDir: options.stateDir,
workspaceDir,
env,
}).plugins;
const bundledManifestRecords = listBundledChannelManifestRecords(manifestRecords);
const externalManifestRecords = listExternalChannelManifestRecords(manifestRecords);
const configuredChannelIds = [