Skip to content

Commit 1aedd8f

Browse files
authored
fix(memory): load configured providers for CLI search (#119186)
* fix(memory): activate configured providers in CLI commands * fix(memory): resolve configured embedding provider owners * test(memory): keep metadata mock unset by default * fix(memory): preserve plugin allowlist policy * test(memory): classify plugin-owned root command
1 parent 52954a1 commit 1aedd8f

11 files changed

Lines changed: 271 additions & 26 deletions

‎src/cli/command-bootstrap.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ describe("ensureCliCommandBootstrap", () => {
6868
it("skips config guard without skipping plugin loading", async () => {
6969
await ensureCliCommandBootstrap({
7070
runtime: {} as never,
71-
commandPath: ["status"],
71+
commandPath: ["memory", "search"],
7272
suppressDoctorStdout: true,
7373
skipConfigGuard: true,
7474
loadPlugins: true,
75+
pluginRegistry: { scope: "memory" },
7576
});
7677

7778
expect(ensureConfigReadyMock).not.toHaveBeenCalled();
7879
expect(ensureCliPluginRegistryLoadedMock).toHaveBeenCalledWith({
79-
scope: "channels",
80+
scope: "memory",
8081
routeLogsToStderr: true,
8182
});
8283
});

‎src/cli/command-catalog.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type CliConfigGuardMode = "run" | "skip" | "when-suppressed";
1010
type CliConfigGuardPolicy =
1111
| CliConfigGuardMode
1212
| ((ctx: { argv: string[]; commandPath: string[] }) => CliConfigGuardMode);
13-
export type CliPluginRegistryScope = "all" | "channels" | "configured-channels";
13+
export type CliPluginRegistryScope = "all" | "channels" | "configured-channels" | "memory";
1414
export type CliPluginRegistryPolicy = {
1515
scope: CliPluginRegistryScope;
1616
};
@@ -607,18 +607,21 @@ export const cliCommandCatalog: readonly CliCommandCatalogEntry[] = [
607607
exact: true,
608608
policy: { configGuard: "skip", loadPlugins: "never" },
609609
},
610+
{
611+
commandPath: ["memory"],
612+
policy: { loadPlugins: "always", pluginRegistry: { scope: "memory" } },
613+
},
610614
{
611615
commandPath: ["memory", "search"],
612616
exact: true,
613-
policy: { configGuard: "skip", loadPlugins: "never" },
617+
policy: { configGuard: "skip" },
614618
},
615619
{
616620
commandPath: ["memory", "status"],
617621
exact: true,
618622
policy: {
619623
configGuard: ({ argv }) =>
620624
hasFlag(argv, "--index") || hasFlag(argv, "--fix") ? "run" : "skip",
621-
loadPlugins: "never",
622625
},
623626
},
624627
{ commandPath: ["skills", "update"], exact: true },

‎src/cli/command-path-policy.test.ts‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,18 +377,19 @@ describe("command-path-policy", () => {
377377
networkProxy: "bypass",
378378
});
379379
}
380-
for (const commandPath of [
381-
["skills", "search"],
382-
["memory", "search"],
383-
]) {
384-
expectResolvedPolicy(commandPath, {
385-
configGuard: "skip",
386-
loadPlugins: "never",
387-
});
388-
}
380+
expectResolvedPolicy(["skills", "search"], {
381+
configGuard: "skip",
382+
loadPlugins: "never",
383+
});
384+
expectResolvedPolicy(["memory", "search"], {
385+
configGuard: "skip",
386+
loadPlugins: "always",
387+
pluginRegistry: { scope: "memory" },
388+
});
389389
const memoryStatusPolicy = resolveCliCommandPathPolicy(["memory", "status"]);
390390
expectConfigGuardResolver(memoryStatusPolicy);
391-
expect(memoryStatusPolicy.loadPlugins).toBe("never");
391+
expect(memoryStatusPolicy.loadPlugins).toBe("always");
392+
expect(memoryStatusPolicy.pluginRegistry).toEqual({ scope: "memory" });
392393
expect(
393394
memoryStatusPolicy.configGuard({
394395
argv: ["node", "openclaw", "memory", "status"],

‎src/cli/command-startup-policy.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ describe("command-startup-policy", () => {
185185
});
186186

187187
it("matches plugin preload policy", () => {
188+
for (const commandPath of [
189+
["memory", "index"],
190+
["memory", "search"],
191+
["memory", "status"],
192+
]) {
193+
const policy = resolvePolicy({ commandPath });
194+
expect(policy.loadPlugins, commandPath.join(" ")).toBe(true);
195+
expect(policy.pluginRegistry, commandPath.join(" ")).toEqual({ scope: "memory" });
196+
}
188197
expect(
189198
resolvePolicy({
190199
commandPath: ["status"],

‎src/cli/program/preaction.test-helpers.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ export const COLD_READ_COMMAND_PATHS: string[][] = [
77
["hooks", "list"],
88
["hooks", "info"],
99
["hooks", "check"],
10-
["memory", "status"],
11-
["memory", "search"],
1210
["update", "--dry-run"],
1311
];
1412

‎src/cli/program/preaction.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,18 @@ export function registerPreActionHooks(program: Command, programVersion: string)
137137
if (!verbose) {
138138
process.env.NODE_NO_WARNINGS ??= "1";
139139
}
140-
if (
141-
startupPolicy.skipConfigGuard ||
142-
isGuidedConfigAction(actionCommand) ||
143-
isGuidedConfigCommandPath(commandPath)
144-
) {
140+
if (isGuidedConfigAction(actionCommand) || isGuidedConfigCommandPath(commandPath)) {
141+
return;
142+
}
143+
if (startupPolicy.skipConfigGuard) {
144+
// Config validation and plugin activation are independent startup policies.
145+
// A cold config read must not suppress a plugin runtime explicitly required by the command.
146+
await ensureCliExecutionBootstrap({
147+
runtime: defaultRuntime,
148+
commandPath,
149+
startupPolicy,
150+
skipConfigGuard: true,
151+
});
145152
return;
146153
}
147154
let beforeStateMigrations: ((snapshot?: ConfigFileSnapshot) => Promise<boolean>) | undefined;

‎src/cli/program/root-command-descriptions.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const RESERVED_CATALOG_ROOTS = {
1717
} as const;
1818

1919
const PLUGIN_CATALOG_PATHS = {
20+
memory: "registered and covered by the memory-core plugin",
2021
"memory search": "registered and covered by the memory-core plugin",
2122
"memory status": "registered and covered by the memory-core plugin",
2223
} as const;

‎src/plugins/activation-context.test.ts‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,43 @@ vi.mock("../config/plugin-auto-enable.js", () => ({
2121
applyPluginAutoEnable: applyPluginAutoEnableMock,
2222
}));
2323

24-
import { resolveBundledPluginCompatibleActivationInputs } from "./activation-context.js";
24+
import {
25+
resolveBundledPluginCompatibleActivationInputs,
26+
withActivatedPluginIds,
27+
} from "./activation-context.js";
2528

2629
afterEach(() => {
2730
clearCurrentPluginMetadataSnapshot();
2831
applyPluginAutoEnableMock.mockClear();
2932
});
3033

34+
describe("withActivatedPluginIds", () => {
35+
it("keeps omitted plugin ids outside restrictive allowlists", () => {
36+
expect(
37+
withActivatedPluginIds({
38+
config: {
39+
plugins: {
40+
allow: ["memory-core"],
41+
deny: ["blocked"],
42+
entries: {
43+
disabled: { enabled: false },
44+
},
45+
},
46+
},
47+
pluginIds: ["openai", "blocked", "disabled"],
48+
}),
49+
).toEqual({
50+
plugins: {
51+
allow: ["memory-core"],
52+
deny: ["blocked"],
53+
entries: {
54+
disabled: { enabled: false },
55+
},
56+
},
57+
});
58+
});
59+
});
60+
3161
describe("resolveBundledPluginCompatibleActivationInputs", () => {
3262
it("passes the current manifest registry into activation auto-enable", () => {
3363
const manifestRegistry = makeRegistry([{ id: "openai", channels: [], providers: ["openai"] }]);

‎src/plugins/channel-plugin-ids.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,18 @@ describe("resolveGatewayStartupPluginIdsFromRegistry", () => {
775775
} as OpenClawConfig,
776776
["browser", "openai", "memory-core"],
777777
],
778+
[
779+
"keeps configured memory embedding providers behind restrictive allowlists",
780+
{
781+
channels: {},
782+
memory: { search: { provider: "openai" } },
783+
plugins: {
784+
allow: ["memory-core"],
785+
slots: { memory: "memory-core" },
786+
},
787+
} as OpenClawConfig,
788+
["memory-core"],
789+
],
778790
[
779791
"includes the owning plugin for a configured memory embedding fallback at startup",
780792
{

‎src/plugins/runtime/runtime-registry-loader.test.ts‎

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ const mocks = vi.hoisted(() => ({
99
vi.fn<typeof import("../channel-plugin-ids.js").resolveChannelPluginIds>(),
1010
resolveEffectivePluginIds:
1111
vi.fn<typeof import("../effective-plugin-ids.js").resolveEffectivePluginIds>(),
12+
collectConfiguredMemoryEmbeddingProviderIds:
13+
vi.fn<
14+
typeof import("../gateway-startup-plugin-ids.js").collectConfiguredMemoryEmbeddingProviderIds
15+
>(),
1216
applyPluginAutoEnable:
1317
vi.fn<typeof import("../../config/plugin-auto-enable.js").applyPluginAutoEnable>(),
1418
resolvePluginMetadataSnapshot:
1519
vi.fn<typeof import("../plugin-metadata-snapshot.js").resolvePluginMetadataSnapshot>(),
20+
isPluginMetadataSnapshotCompatible:
21+
vi.fn<typeof import("../plugin-metadata-snapshot.js").isPluginMetadataSnapshotCompatible>(),
1622
resolveAgentWorkspaceDir: vi.fn<
1723
typeof import("../../agents/agent-scope.js").resolveAgentWorkspaceDir
1824
>(() => "/resolved-workspace"),
@@ -39,6 +45,12 @@ vi.mock("../effective-plugin-ids.js", () => ({
3945
mocks.resolveEffectivePluginIds(...args),
4046
}));
4147

48+
vi.mock("../gateway-startup-plugin-ids.js", () => ({
49+
collectConfiguredMemoryEmbeddingProviderIds: (
50+
...args: Parameters<typeof mocks.collectConfiguredMemoryEmbeddingProviderIds>
51+
) => mocks.collectConfiguredMemoryEmbeddingProviderIds(...args),
52+
}));
53+
4254
vi.mock("../../config/plugin-auto-enable.js", () => ({
4355
applyPluginAutoEnable: (...args: Parameters<typeof mocks.applyPluginAutoEnable>) =>
4456
mocks.applyPluginAutoEnable(...args),
@@ -48,6 +60,9 @@ vi.mock("../plugin-metadata-snapshot.js", () => ({
4860
resolvePluginMetadataSnapshot: (
4961
...args: Parameters<typeof mocks.resolvePluginMetadataSnapshot>
5062
) => mocks.resolvePluginMetadataSnapshot(...args),
63+
isPluginMetadataSnapshotCompatible: (
64+
...args: Parameters<typeof mocks.isPluginMetadataSnapshotCompatible>
65+
) => mocks.isPluginMetadataSnapshotCompatible(...args),
5166
}));
5267

5368
vi.mock("../../agents/agent-scope.js", () => ({
@@ -59,6 +74,28 @@ vi.mock("../../agents/agent-scope.js", () => ({
5974

6075
import { ensurePluginRegistryLoaded } from "./runtime-registry-loader.js";
6176

77+
function useMemoryProviderOwner(params: {
78+
adapterId: string;
79+
contract: "embeddingProviders" | "memoryEmbeddingProviders";
80+
pluginId: string;
81+
}): void {
82+
mocks.resolvePluginMetadataSnapshot.mockReturnValue({
83+
policyHash: "test",
84+
index: {
85+
installRecords: {},
86+
plugins: [
87+
{
88+
pluginId: params.pluginId,
89+
contributions: {
90+
contracts: { [params.contract]: [params.adapterId] },
91+
},
92+
},
93+
],
94+
},
95+
manifestRegistry: { plugins: [], diagnostics: [] },
96+
} as never);
97+
}
98+
6299
function requireLoadOptions(): Record<string, unknown> {
63100
const options = mocks.loadOpenClawPlugins.mock.calls[0]?.[0];
64101
if (!options) {
@@ -70,6 +107,8 @@ function requireLoadOptions(): Record<string, unknown> {
70107
describe("ensurePluginRegistryLoaded", () => {
71108
beforeEach(() => {
72109
vi.clearAllMocks();
110+
mocks.resolvePluginMetadataSnapshot.mockReset();
111+
mocks.isPluginMetadataSnapshotCompatible.mockReturnValue(true);
73112
mocks.applyPluginAutoEnable.mockImplementation((params) => ({
74113
config: params.config ?? {},
75114
changes: [],
@@ -121,4 +160,114 @@ describe("ensurePluginRegistryLoaded", () => {
121160
}),
122161
);
123162
});
163+
164+
it("loads only the selected memory backend and embedding provider owners", () => {
165+
const config = {
166+
memory: { search: { provider: "openai" } },
167+
plugins: {
168+
allow: ["acpx", "memory-core"],
169+
slots: { memory: "memory-core" },
170+
entries: { unrelated: { enabled: true } },
171+
},
172+
};
173+
mocks.collectConfiguredMemoryEmbeddingProviderIds.mockReturnValue(new Set(["openai"]));
174+
175+
ensurePluginRegistryLoaded({ scope: "memory", config });
176+
177+
expect(mocks.collectConfiguredMemoryEmbeddingProviderIds).toHaveBeenCalledWith(config);
178+
expect(requireLoadOptions()).toEqual(
179+
expect.objectContaining({
180+
config,
181+
activationSourceConfig: config,
182+
onlyPluginIds: ["memory-core", "openai"],
183+
throwOnLoadError: true,
184+
}),
185+
);
186+
});
187+
188+
it.each([
189+
{
190+
adapterId: "gemini",
191+
contract: "memoryEmbeddingProviders" as const,
192+
pluginId: "google",
193+
},
194+
{
195+
adapterId: "local",
196+
contract: "embeddingProviders" as const,
197+
pluginId: "llama-cpp",
198+
},
199+
])("loads the $pluginId owner for the $adapterId memory adapter", (provider) => {
200+
const config = {
201+
memory: { search: { provider: provider.adapterId } },
202+
plugins: { slots: { memory: "memory-core" } },
203+
};
204+
mocks.collectConfiguredMemoryEmbeddingProviderIds.mockReturnValue(
205+
new Set([provider.adapterId]),
206+
);
207+
useMemoryProviderOwner(provider);
208+
209+
ensurePluginRegistryLoaded({ scope: "memory", config });
210+
211+
expect(requireLoadOptions().onlyPluginIds).toEqual(
212+
[provider.pluginId, "memory-core"].toSorted(),
213+
);
214+
});
215+
216+
it("keeps a denied memory provider owner denied", () => {
217+
const config = {
218+
memory: { search: { provider: "gemini" } },
219+
plugins: {
220+
allow: ["memory-core"],
221+
deny: ["google"],
222+
slots: { memory: "memory-core" },
223+
},
224+
};
225+
mocks.collectConfiguredMemoryEmbeddingProviderIds.mockReturnValue(new Set(["gemini"]));
226+
useMemoryProviderOwner({
227+
adapterId: "gemini",
228+
contract: "memoryEmbeddingProviders",
229+
pluginId: "google",
230+
});
231+
232+
ensurePluginRegistryLoaded({ scope: "memory", config });
233+
234+
const options = requireLoadOptions();
235+
expect(options.onlyPluginIds).toEqual(["google", "memory-core"]);
236+
expect(options.config).toEqual(config);
237+
expect(options.activationSourceConfig).toEqual(config);
238+
});
239+
240+
it("keeps an explicitly disabled memory provider owner disabled", () => {
241+
const config = {
242+
memory: { search: { provider: "local" } },
243+
plugins: {
244+
entries: { "llama-cpp": { enabled: false } },
245+
slots: { memory: "memory-core" },
246+
},
247+
};
248+
mocks.collectConfiguredMemoryEmbeddingProviderIds.mockReturnValue(new Set(["local"]));
249+
useMemoryProviderOwner({
250+
adapterId: "local",
251+
contract: "embeddingProviders",
252+
pluginId: "llama-cpp",
253+
});
254+
255+
ensurePluginRegistryLoaded({ scope: "memory", config });
256+
257+
const options = requireLoadOptions();
258+
expect(options.onlyPluginIds).toEqual(["llama-cpp", "memory-core"]);
259+
expect(options.config).toEqual(config);
260+
expect(options.activationSourceConfig).toEqual(config);
261+
});
262+
263+
it("keeps an empty memory scope empty when no backend is selected", () => {
264+
mocks.collectConfiguredMemoryEmbeddingProviderIds.mockReturnValue(new Set());
265+
266+
ensurePluginRegistryLoaded({
267+
scope: "memory",
268+
config: { plugins: { slots: { memory: "none" } } },
269+
});
270+
271+
expect(requireLoadOptions().onlyPluginIds).toEqual([]);
272+
});
124273
});

0 commit comments

Comments
 (0)