惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
D
Docker
B
Blog
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
G
Google Developers Blog
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor(plugins): isolate loader cache state · openclaw/...
vincentkoc · 2026-04-27 · via Recent Commits to openclaw:main

@@ -71,6 +71,7 @@ import {

7171

restorePluginInteractiveHandlers,

7272

} from "./interactive-registry.js";

7373

import { getCachedPluginJitiLoader, type PluginJitiLoaderCache } from "./jiti-loader-cache.js";

74+

import { PluginLoaderCacheState } from "./loader-cache-state.js";

7475

import { loadPluginManifestRegistry, type PluginManifestRecord } from "./manifest-registry.js";

7576

import type { PluginBundleFormat, PluginDiagnostic, PluginFormat } from "./manifest-types.js";

7677

import type { PluginManifestContracts } from "./manifest.js";

@@ -134,6 +135,7 @@ import type {

134135

} from "./types.js";

135136136137

export type PluginLoadResult = PluginRegistry;

138+

export { PluginLoadReentryError } from "./loader-cache-state.js";

137139138140

export type PluginLoadOptions = {

139141

config?: OpenClawConfig;

@@ -207,16 +209,6 @@ export class PluginLoadFailureError extends Error {

207209

}

208210

}

209211210-

export class PluginLoadReentryError extends Error {

211-

readonly cacheKey: string;

212-213-

constructor(cacheKey: string) {

214-

super(`plugin load reentry detected for cache key: ${cacheKey}`);

215-

this.name = "PluginLoadReentryError";

216-

this.cacheKey = cacheKey;

217-

}

218-

}

219-220212

type CachedPluginState = {

221213

registry: PluginRegistry;

222214

detachedTaskRuntimeRegistration: ReturnType<typeof getDetachedTaskLifecycleRuntimeRegistration>;

@@ -234,10 +226,9 @@ type CachedPluginState = {

234226

};

235227236228

const MAX_PLUGIN_REGISTRY_CACHE_ENTRIES = 128;

237-

let pluginRegistryCacheEntryCap = MAX_PLUGIN_REGISTRY_CACHE_ENTRIES;

238-

const registryCache = new Map<string, CachedPluginState>();

239-

const inFlightPluginRegistryLoads = new Set<string>();

240-

const openAllowlistWarningCache = new Set<string>();

229+

const pluginLoaderCacheState = new PluginLoaderCacheState<CachedPluginState>(

230+

MAX_PLUGIN_REGISTRY_CACHE_ENTRIES,

231+

);

241232

const LAZY_RUNTIME_REFLECTION_KEYS = [

242233

"version",

243234

"config",

@@ -255,9 +246,7 @@ const LAZY_RUNTIME_REFLECTION_KEYS = [

255246

] as const satisfies readonly (keyof PluginRuntime)[];

256247257248

export function clearPluginLoaderCache(): void {

258-

registryCache.clear();

259-

inFlightPluginRegistryLoads.clear();

260-

openAllowlistWarningCache.clear();

249+

pluginLoaderCacheState.clear();

261250

clearBundledRuntimeDependencyNodePaths();

262251

bundledRuntimeDependencyJitiAliases.clear();

263252

clearAgentHarnesses();

@@ -949,39 +938,19 @@ export const __testing = {

949938

getCompatibleActivePluginRegistry,

950939

resolvePluginLoadCacheContext,

951940

get maxPluginRegistryCacheEntries() {

952-

return pluginRegistryCacheEntryCap;

941+

return pluginLoaderCacheState.maxEntries;

953942

},

954943

setMaxPluginRegistryCacheEntriesForTest(value?: number) {

955-

pluginRegistryCacheEntryCap =

956-

typeof value === "number" && Number.isFinite(value) && value > 0

957-

? Math.max(1, Math.floor(value))

958-

: MAX_PLUGIN_REGISTRY_CACHE_ENTRIES;

944+

pluginLoaderCacheState.setMaxEntriesForTest(value);

959945

},

960946

};

961947962948

function getCachedPluginRegistry(cacheKey: string): CachedPluginState | undefined {

963-

const cached = registryCache.get(cacheKey);

964-

if (!cached) {

965-

return undefined;

966-

}

967-

// Refresh insertion order so frequently reused registries survive eviction.

968-

registryCache.delete(cacheKey);

969-

registryCache.set(cacheKey, cached);

970-

return cached;

949+

return pluginLoaderCacheState.get(cacheKey);

971950

}

972951973952

function setCachedPluginRegistry(cacheKey: string, state: CachedPluginState): void {

974-

if (registryCache.has(cacheKey)) {

975-

registryCache.delete(cacheKey);

976-

}

977-

registryCache.set(cacheKey, state);

978-

while (registryCache.size > pluginRegistryCacheEntryCap) {

979-

const oldestKey = registryCache.keys().next().value;

980-

if (!oldestKey) {

981-

break;

982-

}

983-

registryCache.delete(oldestKey);

984-

}

953+

pluginLoaderCacheState.set(cacheKey, state);

985954

}

986955987956

function buildCacheKey(params: {

@@ -1398,7 +1367,7 @@ export function resolvePluginRegistryLoadCacheKey(options: PluginLoadOptions = {

13981367

}

1399136814001369

export function isPluginRegistryLoadInFlight(options: PluginLoadOptions = {}): boolean {

1401-

return inFlightPluginRegistryLoads.has(resolvePluginRegistryLoadCacheKey(options));

1370+

return pluginLoaderCacheState.isLoadInFlight(resolvePluginRegistryLoadCacheKey(options));

14021371

}

1403137214041373

export function resolveCompatibleRuntimePluginRegistry(

@@ -2089,15 +2058,15 @@ function warnWhenAllowlistIsOpen(params: {

20892058

if (autoDiscoverable.length === 0) {

20902059

return;

20912060

}

2092-

if (openAllowlistWarningCache.has(params.warningCacheKey)) {

2061+

if (pluginLoaderCacheState.hasOpenAllowlistWarning(params.warningCacheKey)) {

20932062

return;

20942063

}

20952064

const preview = autoDiscoverable

20962065

.slice(0, 6)

20972066

.map((entry) => `${entry.id} (${entry.source})`)

20982067

.join(", ");

20992068

const extra = autoDiscoverable.length > 6 ? ` (+${autoDiscoverable.length - 6} more)` : "";

2100-

openAllowlistWarningCache.add(params.warningCacheKey);

2069+

pluginLoaderCacheState.recordOpenAllowlistWarning(params.warningCacheKey);

21012070

params.logger.warn(

21022071

`[plugins] plugins.allow is empty; discovered non-bundled plugins may auto-load: ${preview}${extra}. Set plugins.allow to explicit trusted ids.`,

21032072

);

@@ -2210,10 +2179,7 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi

22102179

return cached.registry;

22112180

}

22122181

}

2213-

if (inFlightPluginRegistryLoads.has(cacheKey)) {

2214-

throw new PluginLoadReentryError(cacheKey);

2215-

}

2216-

inFlightPluginRegistryLoads.add(cacheKey);

2182+

pluginLoaderCacheState.beginLoad(cacheKey);

22172183

try {

22182184

// Clear previously registered plugin state before reloading.

22192185

// Skip for non-activating (snapshot) loads to avoid wiping commands from other plugins.

@@ -3195,7 +3161,7 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi

31953161

}

31963162

return registry;

31973163

} finally {

3198-

inFlightPluginRegistryLoads.delete(cacheKey);

3164+

pluginLoaderCacheState.finishLoad(cacheKey);

31993165

}

32003166

}

32013167