Skip to content

Commit babbad8

Browse files
committed
fix: preserve plugin install records without manifests
1 parent 1848d0d commit babbad8

15 files changed

Lines changed: 284 additions & 36 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Docs: https://docs.openclaw.ai
204204
a parent `$HOME/node_modules` tree. Fixes #71730.
205205
- Plugins/install: pass onboarding plugin config into plugin index writes so local plugin installs outside default discovery roots keep their install records. Thanks @shakkernerd.
206206
- Plugins/install: migrate shipped `plugins.installs` config records into the plugin index while stripping them from runtime config and future writes. Thanks @shakkernerd.
207+
- Plugins/install: keep migrated plugin install records in the plugin index even when the plugin manifest is missing or invalid, so update, uninstall, inspect, and audit can still recover broken installs. Thanks @shakkernerd.
207208
- Plugins/security: keep plugin audit JSON check ids stable while reporting plugin index install-record findings with updated wording. Thanks @shakkernerd.
208209
- CLI/config: reject direct `plugins.installs` edits with guidance to use `openclaw plugins install`, `openclaw plugins update`, or `openclaw plugins uninstall` instead. Thanks @shakkernerd.
209210
- Live tests/voice: accept common STT variants for OpenClaw and ElevenLabs

‎docs/cli/plugins.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,11 @@ the managed plugin index while keeping the default behavior unpinned.
238238

239239
Plugin install metadata is machine-managed state, not user config. Installs
240240
and updates write it to `plugins/installs.json` under the active OpenClaw state
241-
directory. The file includes a do-not-edit warning and is used by
242-
`openclaw plugins update`, uninstall, diagnostics, and the cold plugin registry.
241+
directory. Its top-level `installRecords` map is the durable source of install
242+
metadata, including records for broken or missing plugin manifests. The
243+
`plugins` array is the manifest-derived cold registry cache. The file includes a
244+
do-not-edit warning and is used by `openclaw plugins update`, uninstall,
245+
diagnostics, and the cold plugin registry.
243246

244247
### Uninstall
245248

‎docs/plugins/architecture-internals.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ paths into long-lived config. This keeps local development installs visible to
921921
source-plane diagnostics without adding a second raw filesystem-path disclosure
922922
surface. The persisted `plugins/installs.json` plugin index is the install
923923
source of truth and can be refreshed without loading plugin runtime modules.
924+
Its `installRecords` map is durable even when a plugin manifest is missing or
925+
invalid; its `plugins` array is a rebuildable manifest/cache view.
924926

925927
## Context engine plugins
926928

‎docs/tools/plugin.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,10 @@ immediately loadable after restart.
305305
OpenClaw keeps a persisted local plugin registry as the cold read model for
306306
plugin inventory, contribution ownership, and startup planning. Install, update,
307307
uninstall, enable, and disable flows refresh that registry after changing plugin
308-
state. If the registry is missing, stale, or invalid, `openclaw plugins registry
309-
--refresh` rebuilds it from the durable plugin index, config policy, and
308+
state. The same `plugins/installs.json` file keeps durable install metadata in
309+
top-level `installRecords` and rebuildable manifest metadata in `plugins`. If
310+
the registry is missing, stale, or invalid, `openclaw plugins registry
311+
--refresh` rebuilds its manifest view from install records, config policy, and
310312
manifest/package metadata without loading plugin runtime modules.
311313
`openclaw plugins update <id-or-npm-spec>` applies to tracked installs. Passing
312314
an npm package spec with a dist-tag or exact version resolves the package name

‎src/commands/doctor-plugin-registry.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function createCurrentIndex(): InstalledPluginIndex {
7070
migrationVersion: 1,
7171
policyHash: "policy-v1",
7272
generatedAtMs: 1777118400000,
73+
installRecords: {},
7374
plugins: [],
7475
diagnostics: [],
7576
};

‎src/commands/doctor/shared/plugin-registry-migration.test.ts‎

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function createCurrentIndex(): InstalledPluginIndex {
7575
migrationVersion: 1,
7676
policyHash: "policy-v1",
7777
generatedAtMs: 1777118400000,
78+
installRecords: {},
7879
plugins: [],
7980
diagnostics: [],
8081
};
@@ -268,30 +269,88 @@ describe("plugin registry install migration", () => {
268269
).resolves.toMatchObject({
269270
status: "migrated",
270271
current: {
272+
installRecords: {
273+
demo: {
274+
source: "npm",
275+
276+
installPath: pluginDir,
277+
},
278+
},
271279
plugins: [
272280
expect.objectContaining({
273281
pluginId: "demo",
274-
installRecord: {
275-
source: "npm",
276-
277-
installPath: pluginDir,
278-
},
282+
installRecordHash: expect.stringMatching(/^[a-f0-9]{64}$/u),
279283
}),
280284
],
281285
},
282286
});
283287

284288
await expect(readPersistedInstalledPluginIndex({ stateDir })).resolves.toMatchObject({
289+
installRecords: {
290+
demo: {
291+
source: "npm",
292+
293+
installPath: pluginDir,
294+
},
295+
},
285296
plugins: [
286297
expect.objectContaining({
287298
pluginId: "demo",
288-
installRecord: {
299+
installRecordHash: expect.stringMatching(/^[a-f0-9]{64}$/u),
300+
}),
301+
],
302+
});
303+
});
304+
305+
it("preserves shipped install records when the plugin manifest cannot be discovered", async () => {
306+
const stateDir = makeTempDir();
307+
const pluginDir = path.join(stateDir, "plugins", "missing");
308+
309+
await expect(
310+
migratePluginRegistryForInstall({
311+
stateDir,
312+
candidates: [],
313+
readConfig: async () => ({
314+
plugins: {
315+
entries: {
316+
missing: {
317+
enabled: true,
318+
},
319+
},
320+
installs: {
321+
missing: {
322+
source: "npm",
323+
324+
installPath: pluginDir,
325+
},
326+
},
327+
},
328+
}),
329+
env: hermeticEnv(),
330+
}),
331+
).resolves.toMatchObject({
332+
status: "migrated",
333+
current: {
334+
installRecords: {
335+
missing: {
289336
source: "npm",
290-
spec: "demo@1.0.0",
337+
spec: "missing-plugin@1.0.0",
291338
installPath: pluginDir,
292339
},
293-
}),
294-
],
340+
},
341+
plugins: [],
342+
},
343+
});
344+
345+
await expect(readPersistedInstalledPluginIndex({ stateDir })).resolves.toMatchObject({
346+
installRecords: {
347+
missing: {
348+
source: "npm",
349+
350+
installPath: pluginDir,
351+
},
352+
},
353+
plugins: [],
295354
});
296355
});
297356

‎src/config/io.write-config.test.ts‎

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,17 @@ describe("config io write", () => {
165165
stateDir: path.join(home, ".openclaw"),
166166
}),
167167
).resolves.toMatchObject({
168+
installRecords: {
169+
demo: {
170+
source: "npm",
171+
172+
installPath: pluginDir,
173+
},
174+
},
168175
plugins: [
169176
expect.objectContaining({
170177
pluginId: "demo",
171-
installRecord: {
172-
source: "npm",
173-
174-
installPath: pluginDir,
175-
},
178+
installRecordHash: expect.stringMatching(/^[a-f0-9]{64}$/u),
176179
}),
177180
],
178181
});
@@ -185,6 +188,53 @@ describe("config io write", () => {
185188
});
186189
});
187190

191+
it("migrates shipped plugin install config records even when the manifest is missing", async () => {
192+
await withSuiteHome(async (home) => {
193+
const configPath = path.join(home, ".openclaw", "openclaw.json");
194+
const pluginDir = path.join(home, ".openclaw", "plugins", "missing");
195+
await fs.mkdir(path.dirname(configPath), { recursive: true });
196+
await fs.writeFile(
197+
configPath,
198+
`${JSON.stringify(
199+
{
200+
plugins: {
201+
entries: { missing: { enabled: true } },
202+
installs: {
203+
missing: {
204+
source: "npm",
205+
206+
installPath: pluginDir,
207+
},
208+
},
209+
},
210+
},
211+
null,
212+
2,
213+
)}\n`,
214+
"utf-8",
215+
);
216+
217+
const io = createFastConfigIO(home);
218+
const cfg = io.loadConfig();
219+
220+
expect(cfg.plugins?.installs).toBeUndefined();
221+
await expect(
222+
readPersistedInstalledPluginIndex({
223+
stateDir: path.join(home, ".openclaw"),
224+
}),
225+
).resolves.toMatchObject({
226+
installRecords: {
227+
missing: {
228+
source: "npm",
229+
230+
installPath: pluginDir,
231+
},
232+
},
233+
plugins: [],
234+
});
235+
});
236+
});
237+
188238
it("keeps shipped plugin install config records when index migration fails", async () => {
189239
await withSuiteHome(async (home) => {
190240
const configPath = path.join(home, ".openclaw", "openclaw.json");

‎src/plugins/installed-plugin-index-record-reader.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,30 @@ function cloneInstallRecords(
1515
return structuredClone(records ?? {});
1616
}
1717

18+
function readRecordMap(value: unknown): Record<string, PluginInstallRecord> | null {
19+
if (!isRecord(value)) {
20+
return null;
21+
}
22+
const records: Record<string, PluginInstallRecord> = {};
23+
for (const [pluginId, record] of Object.entries(value).toSorted(([left], [right]) =>
24+
left.localeCompare(right),
25+
)) {
26+
if (isRecord(record) && typeof record.source === "string") {
27+
records[pluginId] = structuredClone(record) as PluginInstallRecord;
28+
}
29+
}
30+
return records;
31+
}
32+
1833
export function extractPluginInstallRecordsFromPersistedInstalledPluginIndex(
1934
index: unknown,
2035
): Record<string, PluginInstallRecord> | null {
2136
if (!isRecord(index) || !Array.isArray(index.plugins)) {
2237
return null;
2338
}
39+
if (Object.prototype.hasOwnProperty.call(index, "installRecords")) {
40+
return readRecordMap(index.installRecords) ?? {};
41+
}
2442
const records: Record<string, PluginInstallRecord> = {};
2543
for (const entry of index.plugins) {
2644
if (!isRecord(entry) || typeof entry.pluginId !== "string" || !isRecord(entry.installRecord)) {

‎src/plugins/installed-plugin-index-records.test.ts‎

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ describe("plugin index install records store", () => {
7575
expect(JSON.parse(fs.readFileSync(indexPath, "utf8"))).toMatchObject({
7676
version: 1,
7777
generatedAtMs: 1777118400000,
78+
installRecords: {
79+
twitch: {
80+
source: "npm",
81+
spec: "@openclaw/[email protected]",
82+
installPath: "plugins/npm/@openclaw/plugin-twitch",
83+
},
84+
},
7885
plugins: [
7986
{
8087
pluginId: "twitch",
81-
installRecord: {
82-
source: "npm",
83-
spec: "@openclaw/[email protected]",
84-
installPath: "plugins/npm/@openclaw/plugin-twitch",
85-
},
88+
installRecordHash: expect.stringMatching(/^[a-f0-9]{64}$/u),
8689
},
8790
],
8891
});
@@ -95,6 +98,47 @@ describe("plugin index install records store", () => {
9598
});
9699
});
97100

101+
it("preserves install records for plugins without a discovered manifest", async () => {
102+
const stateDir = makeStateDir();
103+
104+
await writePersistedInstalledPluginIndexInstallRecords(
105+
{
106+
missing: {
107+
source: "npm",
108+
109+
installPath: path.join(stateDir, "plugins", "missing"),
110+
},
111+
},
112+
{
113+
stateDir,
114+
candidates: [],
115+
now: () => new Date(1777118400000),
116+
},
117+
);
118+
119+
expect(
120+
JSON.parse(
121+
fs.readFileSync(resolveInstalledPluginIndexRecordsStorePath({ stateDir }), "utf8"),
122+
),
123+
).toMatchObject({
124+
installRecords: {
125+
missing: {
126+
source: "npm",
127+
128+
installPath: path.join(stateDir, "plugins", "missing"),
129+
},
130+
},
131+
plugins: [],
132+
});
133+
await expect(loadInstalledPluginIndexInstallRecords({ stateDir })).resolves.toEqual({
134+
missing: {
135+
source: "npm",
136+
137+
installPath: path.join(stateDir, "plugins", "missing"),
138+
},
139+
});
140+
});
141+
98142
it("reads persisted records from the plugin index", async () => {
99143
const stateDir = makeStateDir();
100144
const candidate = createPluginCandidate(stateDir, "persisted");

‎src/plugins/installed-plugin-index-store.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function createIndex(overrides: Partial<InstalledPluginIndex> = {}): InstalledPl
3030
migrationVersion: 1,
3131
policyHash: "policy-v1",
3232
generatedAtMs: 1777118400000,
33+
installRecords: {},
3334
plugins: [
3435
{
3536
pluginId: "demo",

0 commit comments

Comments
 (0)