Files
openclaw/src/plugins/loader-cache-state.ts
Peter Steinberger d678bcfcc7 fix: hot reload plugin management changes (#75976)
Summary:
- The PR changes Gateway reload planning, CLI plugin install-index writes, plugin runtime/cache cleanup, docs, changelog, and tests so plugin enable/disable hot reloads while install/update/uninstall stay restart-backed.
- Reproducibility: yes. The earlier blocker has a source-level reproduction: run an external plugin install/up ...  watches config and only the managed plugin index changes; the PR now tests that path and queues a restart.

ClawSweeper fixups:
- Included follow-up commit: fix: hot reload plugin management changes
- Included follow-up commit: fix(clawsweeper): address review for automerge-openclaw-openclaw-7597…
- Ran the ClawSweeper repair loop before final review.

Validation:
- ClawSweeper review passed for head 860594f722.
- Required merge gates passed before the squash merge.

Prepared head SHA: 860594f722
Review: https://github.com/openclaw/openclaw/pull/75976#issuecomment-4363168379

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
2026-05-02 13:19:24 +00:00

72 lines
1.8 KiB
TypeScript

import { PluginLruCache } from "./plugin-cache-primitives.js";
export class PluginLoadReentryError extends Error {
readonly cacheKey: string;
constructor(cacheKey: string) {
super(`plugin load reentry detected for cache key: ${cacheKey}`);
this.name = "PluginLoadReentryError";
this.cacheKey = cacheKey;
}
}
export class PluginLoaderCacheState<T> {
readonly #registryCache: PluginLruCache<T>;
readonly #inFlightLoads = new Set<string>();
readonly #openAllowlistWarningCache = new Set<string>();
constructor(defaultMaxEntries: number) {
this.#registryCache = new PluginLruCache<T>(defaultMaxEntries);
}
get maxEntries(): number {
return this.#registryCache.maxEntries;
}
setMaxEntriesForTest(value?: number): void {
this.#registryCache.setMaxEntriesForTest(value);
}
clear(): void {
this.#registryCache.clear();
this.#inFlightLoads.clear();
this.#openAllowlistWarningCache.clear();
}
clearCachedRegistries(): void {
this.#registryCache.clear();
this.#openAllowlistWarningCache.clear();
}
get(cacheKey: string): T | undefined {
return this.#registryCache.get(cacheKey);
}
set(cacheKey: string, state: T): void {
this.#registryCache.set(cacheKey, state);
}
isLoadInFlight(cacheKey: string): boolean {
return this.#inFlightLoads.has(cacheKey);
}
beginLoad(cacheKey: string): void {
if (this.#inFlightLoads.has(cacheKey)) {
throw new PluginLoadReentryError(cacheKey);
}
this.#inFlightLoads.add(cacheKey);
}
finishLoad(cacheKey: string): void {
this.#inFlightLoads.delete(cacheKey);
}
hasOpenAllowlistWarning(cacheKey: string): boolean {
return this.#openAllowlistWarningCache.has(cacheKey);
}
recordOpenAllowlistWarning(cacheKey: string): void {
this.#openAllowlistWarningCache.add(cacheKey);
}
}