Skip to content

Commit 0c313d7

Browse files
feliramisteipete
andauthored
fix(plugins): allow install when outgoing channel schema disagrees (#122984)
* fix(plugins): unblock upgrades rejected by outgoing channel schemas Recover only requested-plugin channel schema diagnostics, including channel keys different from the plugin ID. Keep incoming-schema validation and unrelated-error rejection intact. Consolidate duplicate config fixtures and remove an unnecessary error assertion; total LOC is net negative. Co-authored-by: felirami <[email protected]> * fix(plugins): retain source rollback until install records commit Use the existing deferred install transaction across managed sources. Record persistence completion at its owner and remove index/path-inferred compensation, keeping committed payloads intact on late refresh failures. Co-authored-by: felirami <[email protected]> * fix(plugins): preserve rollback causes and satisfy lint Keep both failures in AggregateError and its rollback cause. Document the pinned linter false positive for third-argument options and restore required test braces. * test(plugins): register intentional AggregateError lint exception --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: felirami <[email protected]>
1 parent 09d92ff commit 0c313d7

12 files changed

Lines changed: 418 additions & 618 deletions

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,7 @@ src/cli/plugin-install-plan.ts 1
24232423
src/cli/plugins-authoring-command.ts 8
24242424
src/cli/plugins-cli.runtime.ts 2
24252425
src/cli/plugins-command-helpers.ts 1
2426-
src/cli/plugins-install-config.ts 3
2426+
src/cli/plugins-install-config.ts 2
24272427
src/cli/plugins-uninstall-command.ts 4
24282428
src/cli/plugins-update-command.ts 5
24292429
src/cli/ports.ts 9

‎src/cli/plugins-install-config.test.ts‎

Lines changed: 73 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,21 @@ describe("loadConfigForInstall", () => {
136136
hookMutation: { mode: "allowed" },
137137
pluginMutation: { mode: "allowed" },
138138
});
139-
});
140-
141-
it("returns valid source config unchanged", async () => {
142-
const cfg = { plugins: {} } as OpenClawConfig;
143-
readConfigFileSnapshotMock.mockResolvedValue(
144-
makeSnapshot({
145-
valid: true,
146-
sourceConfig: cfg,
147-
config: cfg,
148-
issues: [],
149-
}),
150-
);
151-
152-
const result = await loadConfigForInstall(discordNpmRequest);
153139
expect(result.config).toBe(cfg);
154140
});
155141

156-
it("falls back to snapshot config for explicit bundled-plugin reinstall when issues match the known upgrade failure", async () => {
142+
it.each([
143+
{ path: "channels.discord", message: "unknown channel id: discord" },
144+
{ path: "channels.discord", message: "invalid config for plugin discord: must be object" },
145+
{
146+
path: "channels.discord.accounts.work",
147+
message: "invalid config for plugin discord: must be object",
148+
},
149+
{
150+
path: "channels.other-channel",
151+
message: "invalid config for plugin discord: must be object",
152+
},
153+
])("recovers requested-plugin upgrade issue $path: $message", async (issue) => {
157154
const snapshotCfg = {
158155
plugins: { installs: { discord: { source: "path", installPath: "/gone" } } },
159156
} as unknown as OpenClawConfig;
@@ -162,7 +159,7 @@ describe("loadConfigForInstall", () => {
162159
parsed: { plugins: { installs: { discord: {} } } },
163160
config: snapshotCfg,
164161
issues: [
165-
{ path: "channels.discord", message: "unknown channel id: discord" },
162+
issue,
166163
{ path: "plugins.load.paths", message: "plugin: plugin path not found: /gone" },
167164
],
168165
}),
@@ -179,40 +176,6 @@ describe("loadConfigForInstall", () => {
179176
});
180177
});
181178

182-
it("allows versioned npm:-prefixed bundled-plugin reinstall recovery", async () => {
183-
const snapshotCfg = {
184-
plugins: { installs: { discord: { source: "path", installPath: "/gone" } } },
185-
} as unknown as OpenClawConfig;
186-
readConfigFileSnapshotMock.mockResolvedValue(
187-
makeSnapshot({
188-
parsed: { plugins: { installs: { discord: {} } } },
189-
config: snapshotCfg,
190-
issues: [
191-
{ path: "channels.discord", message: "unknown channel id: discord" },
192-
{ path: "plugins.load.paths", message: "plugin: plugin path not found: /gone" },
193-
],
194-
}),
195-
);
196-
197-
const request = resolvePluginInstallRequestContext({
198-
rawSpec: "npm:@openclaw/[email protected]",
199-
});
200-
if (!request.ok) {
201-
throw new Error(request.error);
202-
}
203-
204-
expect(request.request.bundledPluginId).toBe("discord");
205-
expect(request.request.allowInvalidConfigRecovery).toBe(true);
206-
const result = await loadConfigForInstall(request.request);
207-
expect(result).toEqual({
208-
config: snapshotCfg,
209-
baseHash: "abc",
210-
writeOptions: installWriteOptions,
211-
hookMutation: { mode: "allowed" },
212-
pluginMutation: { mode: "allowed" },
213-
});
214-
});
215-
216179
it.each(["file:@openclaw/discord", "FILE:@openclaw/discord"])(
217180
"does not treat %s as an official plugin recovery request",
218181
(rawSpec) => {
@@ -238,49 +201,50 @@ describe("loadConfigForInstall", () => {
238201
expect(request.request.installKind).toBe("plugin");
239202
});
240203

241-
it("allows versioned official npm spec reinstall recovery", async () => {
242-
const snapshotCfg = {
243-
plugins: {
244-
installs: { discord: { source: "npm", installPath: "/gone" } },
245-
load: { paths: ["/gone", "/keep"] },
246-
},
247-
channels: { discord: { token: "preserve-me" } },
248-
} as unknown as OpenClawConfig;
249-
readConfigFileSnapshotMock.mockResolvedValue(
250-
makeSnapshot({
251-
parsed: { plugins: { installs: { discord: {} }, load: { paths: ["/gone", "/keep"] } } },
252-
config: snapshotCfg,
253-
issues: [
254-
{ path: "channels.discord", message: "unknown channel id: discord" },
255-
{ path: "plugins.load.paths", message: "plugin: plugin path not found: /gone" },
256-
],
257-
}),
258-
);
259-
260-
const request = resolvePluginInstallRequestContext({
261-
rawSpec: "@openclaw/[email protected]",
262-
});
263-
if (!request.ok) {
264-
throw new Error(request.error);
265-
}
266-
267-
expect(request.request.bundledPluginId).toBe("discord");
268-
expect(request.request.allowInvalidConfigRecovery).toBe(true);
269-
const result = await loadConfigForInstall(request.request);
270-
expect(result).toEqual({
271-
config: {
204+
it.each(["@openclaw/[email protected]", "npm:@openclaw/[email protected]"])(
205+
"allows versioned official reinstall recovery for %s",
206+
async (rawSpec) => {
207+
const snapshotCfg = {
272208
plugins: {
273209
installs: { discord: { source: "npm", installPath: "/gone" } },
274-
load: { paths: ["/keep"] },
210+
load: { paths: ["/gone", "/keep"] },
275211
},
276212
channels: { discord: { token: "preserve-me" } },
277-
},
278-
baseHash: "abc",
279-
writeOptions: installWriteOptions,
280-
hookMutation: { mode: "allowed" },
281-
pluginMutation: { mode: "allowed" },
282-
});
283-
});
213+
} as unknown as OpenClawConfig;
214+
readConfigFileSnapshotMock.mockResolvedValue(
215+
makeSnapshot({
216+
parsed: { plugins: { installs: { discord: {} }, load: { paths: ["/gone", "/keep"] } } },
217+
config: snapshotCfg,
218+
issues: [
219+
{ path: "channels.discord", message: "unknown channel id: discord" },
220+
{ path: "plugins.load.paths", message: "plugin: plugin path not found: /gone" },
221+
],
222+
}),
223+
);
224+
225+
const request = resolvePluginInstallRequestContext({ rawSpec });
226+
if (!request.ok) {
227+
throw new Error(request.error);
228+
}
229+
230+
expect(request.request.bundledPluginId).toBe("discord");
231+
expect(request.request.allowInvalidConfigRecovery).toBe(true);
232+
const result = await loadConfigForInstall(request.request);
233+
expect(result).toEqual({
234+
config: {
235+
plugins: {
236+
installs: { discord: { source: "npm", installPath: "/gone" } },
237+
load: { paths: ["/keep"] },
238+
},
239+
channels: { discord: { token: "preserve-me" } },
240+
},
241+
baseHash: "abc",
242+
writeOptions: installWriteOptions,
243+
hookMutation: { mode: "allowed" },
244+
pluginMutation: { mode: "allowed" },
245+
});
246+
},
247+
);
284248

285249
it("uses the canonical plugin install record to own a stale recovery load path", async () => {
286250
const snapshotCfg = {
@@ -916,10 +880,28 @@ describe("loadConfigForInstall", () => {
916880
},
917881
);
918882

919-
it("rejects unrelated invalid config even during bundled-plugin reinstall recovery", async () => {
883+
it.each([
884+
{ path: "models.default", message: "invalid model ref" },
885+
{ path: "channels.discord", message: "invalid config for plugin telegram: must be object" },
886+
{
887+
path: "channels.discord",
888+
message: "invalid config for plugin discord-extra: must be object",
889+
},
890+
{ path: "channels.discord", message: "must be object" },
891+
{
892+
path: "plugins.entries.discord.config",
893+
message: "invalid config for plugin discord: must be object",
894+
},
895+
])("rejects unrelated issue $path: $message during plugin recovery", async (issue) => {
920896
readConfigFileSnapshotMock.mockResolvedValue(
921897
makeSnapshot({
922-
issues: [{ path: "models.default", message: "invalid model ref" }],
898+
issues: [
899+
{
900+
path: "channels.discord",
901+
message: "invalid config for plugin discord: must be object",
902+
},
903+
issue,
904+
],
923905
}),
924906
);
925907

‎src/cli/plugins-install-config.ts‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Owns config snapshots, include boundaries, and recovery for plugin installation.
22
import { readConfigFileSnapshotForWrite } from "../config/config.js";
3-
import type { OpenClawConfig } from "../config/types.openclaw.js";
3+
import type { ConfigValidationIssue, OpenClawConfig } from "../config/types.openclaw.js";
44
import {
55
resolveInstallConfigMutationPreflights,
66
selectInstallMutationWriteOptions,
@@ -35,9 +35,7 @@ export function resolveFullyBlockedConfigMutationReason(
3535
}
3636

3737
function buildInvalidPluginInstallConfigError(message: string): Error {
38-
const error = new Error(message);
39-
(error as { code?: string }).code = "INVALID_CONFIG";
40-
return error;
38+
return Object.assign(new Error(message), { code: "INVALID_CONFIG" });
4139
}
4240

4341
function assertPluginConfigMutationAllowed(preflight: ConfigMutationPreflight): void {
@@ -53,8 +51,8 @@ function supportsPluginRecoveryIncludeShape(parsed: Record<string, unknown>): bo
5351
return supportsInstallConfigSingleTopLevelIncludeShape(parsed.plugins);
5452
}
5553

56-
function extractMissingPluginLoadPath(issue: { path?: string; message?: string }): string | null {
57-
if (issue.path !== "plugins.load.paths" || typeof issue.message !== "string") {
54+
function extractMissingPluginLoadPath(issue: ConfigValidationIssue): string | null {
55+
if (issue.path !== "plugins.load.paths") {
5856
return null;
5957
}
6058
const marker = "plugin path not found:";
@@ -67,7 +65,7 @@ function extractMissingPluginLoadPath(issue: { path?: string; message?: string }
6765
}
6866

6967
function isOwnedMissingPluginLoadPathIssue(
70-
issue: { path?: string; message?: string },
68+
issue: ConfigValidationIssue,
7169
ownedLoadPaths: ReadonlySet<string>,
7270
env: NodeJS.ProcessEnv = process.env,
7371
): boolean {
@@ -76,7 +74,7 @@ function isOwnedMissingPluginLoadPathIssue(
7674
}
7775

7876
function isAllowedPluginRecoveryIssue(
79-
issue: { path?: string; message?: string },
77+
issue: ConfigValidationIssue,
8078
request: PluginInstallRequestContext,
8179
ownedLoadPaths: ReadonlySet<string>,
8280
): boolean {
@@ -87,13 +85,14 @@ function isAllowedPluginRecoveryIssue(
8785
return (
8886
(issue.path === `channels.${pluginId}` &&
8987
issue.message === `unknown channel id: ${pluginId}`) ||
88+
// The outgoing schema must not block its replacement. The validator names
89+
// the schema owner; a plugin may own a channel whose id differs from its own.
90+
(issue.path.startsWith("channels.") &&
91+
issue.message.startsWith(`invalid config for plugin ${pluginId}:`)) ||
9092
isOwnedMissingPluginLoadPathIssue(issue, ownedLoadPaths) ||
9193
(issue.path === `plugins.entries.${pluginId}` &&
92-
typeof issue.message === "string" &&
9394
issue.message.includes("requires compiled runtime output")) ||
94-
(issue.path === "tools.web.search.provider" &&
95-
typeof issue.message === "string" &&
96-
issue.message.includes(`plugin "${pluginId}"`))
95+
(issue.path === "tools.web.search.provider" && issue.message.includes(`plugin "${pluginId}"`))
9796
);
9897
}
9998

@@ -135,7 +134,7 @@ async function collectRequestedPluginLocationBridgePaths(
135134

136135
function removeOwnedMissingPluginLoadPaths(
137136
cfg: OpenClawConfig,
138-
issues: readonly { path?: string; message?: string }[],
137+
issues: readonly ConfigValidationIssue[],
139138
ownedLoadPaths: ReadonlySet<string>,
140139
env: NodeJS.ProcessEnv,
141140
): OpenClawConfig {
@@ -174,7 +173,7 @@ function removeOwnedMissingPluginLoadPaths(
174173

175174
async function resolveRequestedPluginInstallPaths(
176175
cfg: OpenClawConfig,
177-
issues: readonly { path?: string; message?: string }[],
176+
issues: readonly ConfigValidationIssue[],
178177
request: PluginInstallRequestContext,
179178
env: NodeJS.ProcessEnv,
180179
): Promise<Set<string>> {

0 commit comments

Comments
 (0)