mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:10:43 +00:00
fix(gateway): scope memory runtime plugin loading
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user