Skip to content

Commit cd1ab40

Browse files
VACIncsteipete
andauthored
fix: gateway boots when a configured plugin payload is broken (#110239)
* fix: quarantine broken plugins during gateway startup * fix(plugins): preserve degraded boot on package read errors * fix(gateway): emit quarantine diagnostic once * fix(gateway): refresh plugin quarantine every boot * fix(gateway): harden plugin payload quarantine Co-authored-by: VACInc <[email protected]> * fix(ci): satisfy plugin quarantine checks Co-authored-by: VACInc <[email protected]> --------- Co-authored-by: VACInc <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent 73cf9ee commit cd1ab40

29 files changed

Lines changed: 1724 additions & 131 deletions

‎docs/tools/plugin.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ serves your channels, not only a wrapper or supervisor.
289289
| `OPENCLAW_NIX_MODE=1` blocks lifecycle commands | Confirm the install is managed by Nix | Change plugin selection in the Nix source instead of using plugin mutator commands |
290290
| Dependency import fails at runtime | Check whether the plugin was installed through npm/git/ClawHub or loaded from a local path | Run `openclaw plugins update <id>`, reinstall the source, or install local plugin dependencies yourself |
291291

292+
When an enabled managed plugin fails payload verification during Gateway
293+
startup, OpenClaw quarantines that exact installed plugin root for the boot and
294+
continues serving other plugins. `openclaw status --all`, `openclaw health`,
295+
and `openclaw doctor` report it as `configured-unavailable`. Fix or reinstall
296+
the plugin, then restart the Gateway. A healthy explicit `plugins.load.paths`
297+
override with the same plugin id is not quarantined by a stale broken install.
298+
292299
When stale plugin config still names a no-longer-discoverable channel plugin,
293300
config validation downgrades that channel key to a warning instead of a hard
294301
failure, so Gateway startup can still serve every other channel. Run
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Boot-local plugin payload verification without repair, install, or catalog imports.
2+
import type { OpenClawConfig } from "../../config/types.openclaw.js";
3+
import type { PluginInstallRecord } from "../../config/types.plugins.js";
4+
import { normalizePluginsConfig, resolveEffectiveEnableState } from "../../plugins/config-state.js";
5+
import {
6+
resolveTrustedSourceLinkedOfficialClawHubSpec,
7+
resolveTrustedSourceLinkedOfficialNpmSpec,
8+
} from "../../plugins/official-external-install-records.js";
9+
import {
10+
runPluginPayloadSmokeCheck,
11+
type PluginPayloadSmokeResult,
12+
} from "./plugin-payload-validation.js";
13+
14+
/** Runs the static payload check without repair, installs, or network access. */
15+
export async function runActivePluginPayloadSmokeCheck(params: {
16+
cfg: OpenClawConfig;
17+
records: Record<string, PluginInstallRecord>;
18+
env: NodeJS.ProcessEnv;
19+
}): Promise<PluginPayloadSmokeResult> {
20+
return await runPluginPayloadSmokeCheck({
21+
records: filterRecordsToActive({ cfg: params.cfg, records: params.records }),
22+
env: params.env,
23+
});
24+
}
25+
26+
/** Selects the installed records covered by update/startup payload verification. */
27+
export function filterRecordsToActive(params: {
28+
cfg: OpenClawConfig;
29+
records: Record<string, PluginInstallRecord>;
30+
}): Record<string, PluginInstallRecord> {
31+
const normalizedPluginConfig = normalizePluginsConfig(params.cfg.plugins);
32+
const filtered: Record<string, PluginInstallRecord> = {};
33+
for (const [pluginId, record] of Object.entries(params.records)) {
34+
if (!record || typeof record !== "object") {
35+
continue;
36+
}
37+
const enableState = resolveEffectiveEnableState({
38+
id: pluginId,
39+
origin: "global",
40+
config: normalizedPluginConfig,
41+
rootConfig: params.cfg,
42+
});
43+
if (enableState.enabled) {
44+
filtered[pluginId] = record;
45+
continue;
46+
}
47+
// Trusted-source-linked official installs remain authoritative sync targets
48+
// even when their plugin entry is disabled.
49+
const officialNpm = resolveTrustedSourceLinkedOfficialNpmSpec({ pluginId, record });
50+
const officialClawHub = resolveTrustedSourceLinkedOfficialClawHubSpec({ pluginId, record });
51+
if (officialNpm || officialClawHub) {
52+
filtered[pluginId] = record;
53+
}
54+
}
55+
return filtered;
56+
}

‎src/cli/update-cli/plugin-payload-validation.ts‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,17 @@ import type { PluginBundleFormat } from "../../plugins/manifest-types.js";
77
import { resolvePackageExtensionEntries, type PackageManifest } from "../../plugins/manifest.js";
88
import { validatePackageExtensionEntriesForInstall } from "../../plugins/package-entry-resolution.js";
99
import { auditOpenClawPeerDependencyLink } from "../../plugins/plugin-peer-link.js";
10+
import type { PluginVerificationFailureReason } from "../../plugins/runtime-degraded-state.js";
1011
import { resolveUserPath } from "../../utils.js";
1112

12-
type PluginPayloadSmokeFailureReason =
13-
| "missing-install-path"
14-
| "missing-package-dir"
15-
| "missing-package-json"
16-
| "unreadable-package-json"
17-
| "invalid-package-json"
18-
| "missing-bundle-manifest"
19-
| "invalid-bundle-manifest"
20-
| "missing-main-entry"
21-
| "missing-extension-entry"
22-
| "missing-openclaw-peer-link";
23-
2413
export type PluginPayloadSmokeFailure = {
2514
pluginId: string;
2615
installPath?: string;
27-
reason: PluginPayloadSmokeFailureReason;
16+
reason: PluginVerificationFailureReason;
2817
detail: string;
2918
};
3019

31-
type PluginPayloadSmokeResult = {
20+
export type PluginPayloadSmokeResult = {
3221
checked: string[];
3322
failures: PluginPayloadSmokeFailure[];
3423
};

‎src/cli/update-cli/post-core-plugin-convergence.test.ts‎

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ vi.mock("./plugin-payload-validation.js", () => ({
2929
import type { OpenClawConfig } from "../../config/types.openclaw.js";
3030
import { VERSION } from "../../version.js";
3131
import {
32-
convergenceWarningsToOutcomes,
3332
filterRecordsToActive,
33+
runActivePluginPayloadSmokeCheck,
34+
} from "./active-plugin-payload-validation.js";
35+
import {
36+
convergenceWarningsToOutcomes,
3437
runPostCorePluginConvergence,
3538
} from "./post-core-plugin-convergence.js";
3639

@@ -110,6 +113,28 @@ describe("runPostCorePluginConvergence", () => {
110113
});
111114
});
112115

116+
it("checks active payloads without running repair or peer-link convergence", async () => {
117+
const cfg = {
118+
plugins: {
119+
deny: ["disabled"],
120+
entries: { active: { enabled: true }, disabled: { enabled: true } },
121+
},
122+
} as unknown as OpenClawConfig;
123+
const records = {
124+
active: { source: "npm" as const, installPath: "/p/active" },
125+
disabled: { source: "npm" as const, installPath: "/p/disabled" },
126+
};
127+
128+
await runActivePluginPayloadSmokeCheck({ cfg, records, env: { OPENCLAW_STATE_DIR: "/state" } });
129+
130+
expect(mocks.runPluginPayloadSmokeCheck).toHaveBeenCalledWith({
131+
records: { active: records.active },
132+
env: { OPENCLAW_STATE_DIR: "/state" },
133+
});
134+
expect(mocks.repairMissingConfiguredPluginInstalls).not.toHaveBeenCalled();
135+
expect(mocks.relinkOpenClawPeerDependenciesInManagedNpmRoot).not.toHaveBeenCalled();
136+
});
137+
113138
it("uses the candidate runtime version over a stale inherited host version", async () => {
114139
const cfg = { plugins: { entries: {} } } as unknown as OpenClawConfig;
115140
await runPostCorePluginConvergence({
@@ -189,10 +214,12 @@ describe("runPostCorePluginConvergence", () => {
189214
expect(mocks.relinkOpenClawPeerDependenciesInManagedNpmRoot).toHaveBeenNthCalledWith(1, {
190215
npmRoot: "/tmp/openclaw-state/npm",
191216
logger: {},
217+
onPackageReadError: expect.any(Function),
192218
});
193219
expect(mocks.relinkOpenClawPeerDependenciesInManagedNpmRoot).toHaveBeenNthCalledWith(2, {
194220
npmRoot: "/tmp/openclaw-state/npm/projects/codex",
195221
logger: {},
222+
onPackageReadError: expect.any(Function),
196223
});
197224
expect(result.changes).toEqual([
198225
"Repaired OpenClaw host peer link(s) for 1 managed npm plugin package(s).",
@@ -549,6 +576,105 @@ describe("runPostCorePluginConvergence", () => {
549576
});
550577
});
551578

579+
it("does not duplicate a package-scoped repair error owned by a smoke failure", async () => {
580+
const installPath = "/tmp/openclaw-state/npm/projects/brave/node_modules/brave";
581+
mocks.repairMissingConfiguredPluginInstalls.mockResolvedValue({
582+
changes: [],
583+
warnings: [],
584+
records: { brave: { source: "npm", installPath } },
585+
});
586+
mocks.relinkOpenClawPeerDependenciesInManagedNpmRoot.mockImplementation(
587+
async (params: { onPackageReadError?: (error: unknown, packageDir: string) => void }) => {
588+
params.onPackageReadError?.(
589+
new Error(`EACCES: permission denied, open '${installPath}/package.json'`),
590+
installPath,
591+
);
592+
return { checked: 0, attempted: 0, repaired: 0, skipped: 1 };
593+
},
594+
);
595+
mocks.runPluginPayloadSmokeCheck.mockResolvedValue({
596+
checked: ["brave"],
597+
failures: [
598+
{
599+
pluginId: "brave",
600+
installPath,
601+
reason: "unreadable-package-json",
602+
detail: `Could not read package.json at ${installPath}/package.json: EACCES: permission denied`,
603+
},
604+
],
605+
});
606+
607+
const result = await runPostCorePluginConvergence({
608+
cfg: {
609+
plugins: { entries: { brave: { enabled: true } } },
610+
} as unknown as OpenClawConfig,
611+
env: { OPENCLAW_STATE_DIR: "/tmp/openclaw-state" },
612+
});
613+
614+
expect(result.warnings).toHaveLength(1);
615+
expect(result.warnings[0]).toMatchObject({
616+
pluginId: "brave",
617+
reason: expect.stringContaining("unreadable-package-json"),
618+
});
619+
expect(result.errored).toBe(true);
620+
});
621+
622+
it("does not promote an inactive package read error into an ownerless blocker", async () => {
623+
const installPath = "/tmp/openclaw-state/npm/projects/brave/node_modules/brave";
624+
mocks.repairMissingConfiguredPluginInstalls.mockResolvedValue({
625+
changes: [],
626+
warnings: [],
627+
records: { brave: { source: "npm", installPath } },
628+
});
629+
mocks.relinkOpenClawPeerDependenciesInManagedNpmRoot.mockImplementation(
630+
async (params: { onPackageReadError?: (error: unknown, packageDir: string) => void }) => {
631+
params.onPackageReadError?.(
632+
new Error(`EACCES: permission denied, open '${installPath}/package.json'`),
633+
installPath,
634+
);
635+
return { checked: 0, attempted: 0, repaired: 0, skipped: 1 };
636+
},
637+
);
638+
639+
const result = await runPostCorePluginConvergence({
640+
cfg: {
641+
plugins: { entries: { brave: { enabled: false } } },
642+
} as unknown as OpenClawConfig,
643+
env: { OPENCLAW_STATE_DIR: "/tmp/openclaw-state" },
644+
});
645+
646+
expect(mocks.runPluginPayloadSmokeCheck).toHaveBeenCalledWith({
647+
records: {},
648+
env: expect.any(Object),
649+
});
650+
expect(result.warnings).toEqual([]);
651+
expect(result.errored).toBe(false);
652+
});
653+
654+
it("keeps an unowned package read error visible for startup to block", async () => {
655+
const packageDir = "/tmp/openclaw-state/npm/node_modules/untracked";
656+
mocks.relinkOpenClawPeerDependenciesInManagedNpmRoot.mockImplementation(
657+
async (params: { onPackageReadError?: (error: unknown, packageDir: string) => void }) => {
658+
params.onPackageReadError?.(new Error("EACCES: permission denied"), packageDir);
659+
return { checked: 0, attempted: 0, repaired: 0, skipped: 1 };
660+
},
661+
);
662+
663+
const result = await runPostCorePluginConvergence({
664+
cfg: { plugins: { entries: {} } } as unknown as OpenClawConfig,
665+
env: { OPENCLAW_STATE_DIR: "/tmp/openclaw-state" },
666+
});
667+
668+
expect(result.warnings).toStrictEqual([
669+
{
670+
reason: "Failed to repair managed npm OpenClaw host peer links: EACCES: permission denied",
671+
message: "Failed to repair managed npm OpenClaw host peer links: EACCES: permission denied",
672+
guidance: ["Run `openclaw update repair` to retry plugin repair."],
673+
},
674+
]);
675+
expect(result.errored).toBe(false);
676+
});
677+
552678
it("hands repair's post-mutation records straight to the smoke check (no second disk read)", async () => {
553679
const records = { brave: { source: "npm" as const, installPath: "/p/brave" } };
554680
mocks.repairMissingConfiguredPluginInstalls.mockResolvedValue({

0 commit comments

Comments
 (0)