fix(plugins): clear memory prompt section on plugin reload

This commit is contained in:
Jari Mustonen 2026-03-09 14:33:58 +02:00 committed by Josh Lehman
parent d827603bc9
commit 586326158e
No known key found for this signature in database
GPG Key ID: D141B425AC7F876B
2 changed files with 9 additions and 3 deletions

View File

@ -23,7 +23,10 @@ export function buildMemoryPromptSection(params: {
return _builder?.(params) ?? [];
}
/** Reset state (for tests). */
export function _resetMemoryPromptSection(): void {
/** Clear the registered builder (called on plugin reload and in tests). */
export function clearMemoryPromptSection(): void {
_builder = undefined;
}
/** @deprecated Use {@link clearMemoryPromptSection}. */
export const _resetMemoryPromptSection = clearMemoryPromptSection;

View File

@ -10,6 +10,7 @@ import type { GatewayRequestHandler } from "../gateway/server-methods/types.js";
import { openBoundaryFileSync } from "../infra/boundary-file-read.js";
import { createSubsystemLogger } from "../logging/subsystem.js";
import { resolveUserPath } from "../utils.js";
import { clearMemoryPromptSection } from "../memory/prompt-section.js";
import { inspectBundleMcpRuntimeSupport } from "./bundle-mcp.js";
import { clearPluginCommands } from "./commands.js";
import {
@ -113,6 +114,7 @@ const LAZY_RUNTIME_REFLECTION_KEYS = [
export function clearPluginLoaderCache(): void {
registryCache.clear();
openAllowlistWarningCache.clear();
clearMemoryPromptSection();
}
const defaultLogger = () => createSubsystemLogger("plugins");
@ -739,11 +741,12 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi
}
}
// Clear previously registered plugin commands before reloading.
// Clear previously registered plugin state before reloading.
// Skip for non-activating (snapshot) loads to avoid wiping commands from other plugins.
if (shouldActivate) {
clearPluginCommands();
clearPluginInteractiveHandlers();
clearMemoryPromptSection();
}
// Lazy: avoid creating the Jiti loader when all plugins are disabled (common in unit tests).