fix(gateway): scope memory runtime plugin loading

This commit is contained in:
Vincent Koc
2026-04-26 18:54:49 -07:00
parent 20b71e18b2
commit b96a75c95b
2 changed files with 72 additions and 1 deletions

View File

@@ -60,6 +60,7 @@ function expectMemoryRuntimeLoaded(rawConfig: unknown, autoEnabledConfig: unknow
expect.objectContaining({
config: autoEnabledConfig,
activationSourceConfig: rawConfig,
onlyPluginIds: ["memory-core"],
}),
);
}
@@ -159,6 +160,63 @@ describe("memory runtime auto-enable loading", () => {
await expectAutoEnabledMemoryRuntimeCase({ run, expectedResult });
});
it("loads only the configured memory slot plugin", async () => {
const rawConfig = {
plugins: {
slots: {
memory: "memory-lancedb",
},
},
};
const runtime = createMemoryRuntimeFixture();
applyPluginAutoEnableMock.mockReturnValue({
config: rawConfig,
changes: [],
autoEnabledReasons: {},
});
getMemoryRuntimeMock.mockReturnValueOnce(undefined).mockReturnValue(runtime);
await getActiveMemorySearchManager({
cfg: rawConfig as never,
agentId: "main",
});
expect(resolveRuntimePluginRegistryMock).toHaveBeenCalledWith(
expect.objectContaining({
onlyPluginIds: ["memory-lancedb"],
}),
);
});
it("does not fall back to broad plugin loading when the memory slot is disabled", async () => {
const rawConfig = {
plugins: {
slots: {
memory: "none",
},
},
};
applyPluginAutoEnableMock.mockReturnValue({
config: rawConfig,
changes: [],
autoEnabledReasons: {},
});
getMemoryRuntimeMock.mockReturnValue(undefined);
await expect(
getActiveMemorySearchManager({
cfg: rawConfig as never,
agentId: "main",
}),
).resolves.toEqual({ manager: null, error: "memory plugin unavailable" });
expect(applyPluginAutoEnableMock).toHaveBeenCalledWith({
config: rawConfig,
env: process.env,
});
expect(resolveRuntimePluginRegistryMock).not.toHaveBeenCalled();
});
it.each([
{
name: "does not bootstrap the memory runtime just to close managers",

View File

@@ -1,4 +1,5 @@
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { normalizePluginsConfig } from "./config-state.js";
import { resolveRuntimePluginRegistry } from "./loader.js";
import { getMemoryRuntime } from "./memory-state.js";
import {
@@ -6,13 +7,25 @@ import {
resolvePluginRuntimeLoadContext,
} from "./runtime/load-context.js";
function resolveMemoryRuntimePluginIds(config: OpenClawConfig): string[] {
const memorySlot = normalizePluginsConfig(config.plugins).slots.memory;
return typeof memorySlot === "string" && memorySlot.trim().length > 0 ? [memorySlot] : [];
}
function ensureMemoryRuntime(cfg?: OpenClawConfig) {
const current = getMemoryRuntime();
if (current || !cfg) {
return current;
}
const context = resolvePluginRuntimeLoadContext({ config: cfg });
const onlyPluginIds = resolveMemoryRuntimePluginIds(context.config);
if (onlyPluginIds.length === 0) {
return getMemoryRuntime();
}
resolveRuntimePluginRegistry(
buildPluginRuntimeLoadOptions(resolvePluginRuntimeLoadContext({ config: cfg })),
buildPluginRuntimeLoadOptions(context, {
onlyPluginIds,
}),
);
return getMemoryRuntime();
}