Repository navigation
Description
Gateway crash-loops on npm 12: npm view --json now always returns an array, breaking plugin metadata parsing
Summary
On npm 12.x, npm view <spec> --json returns a JSON array even for a single exact version. OpenClaw's normalizeNpmViewMetadata() assumes a single object, so every plugin version check fails with npm view produced incomplete package metadata. Because this check runs during startup migrations and is treated as fatal, the gateway refuses to report ready and crash-loops until systemd/launchd gives up. The CLI becomes effectively unusable after an update that bumps the environment to Node 26 / npm 12.
Environment
- OpenClaw:
2026.7.1 (2d2ddc4) - Node:
v26.5.0 - npm:
12.0.1 - OS: Linux (systemd user service, Homebrew-installed Node/npm)
Impact
- Gateway startup migration aborts:
OpenClaw startup migrations did not complete cleanly; refusing to report the gateway ready. - systemd stops restarting after repeated crashes (
start request repeated too quickly), soopenclaw/ the TUI can't reach a gateway. openclaw update repairalso fails for every npm plugin (brave,codex,slackin my case) and auto-disables them — but the startup check still fails even for disabled plugins, so disabling is not a workaround.- Any plugin version range that matches multiple published versions (e.g.
^2026.7.1-beta.2once2026.7.1ships) makes it more obvious (array length > 1), but it fails even for exact single-version specs because npm 12 wraps the lone result in an array.
Root cause
src/infra/install-source-utils.ts → normalizeNpmViewMetadata(value) (shipped in dist/install-source-utils-*.js):
function normalizeNpmViewMetadata(value) {
if (!value || typeof value !== "object") return null; // arrays pass: typeof [] === "object"
const rec = value;
const name = normalizeOptionalString(rec.name); // undefined on an array
const version = normalizeOptionalString(rec.version); // undefined on an array
...
}resolveNpmSpecMetadata() runs:
npm view <spec> name version dist.integrity dist.shasum openclaw --json
then normalizeNpmViewMetadata(JSON.parse(stdout)). On npm 12 the stdout is an array, so name/version come back undefined and the caller reports npm view produced incomplete package metadata.
Notably, the sibling npm pack path (parseNpmPackJsonOutput) already handles arrays:
const entries = Array.isArray(parsed) ? parsed : [parsed];
// iterate from the end, pick the highest matching versionOnly the npm view path was missed.
Reproduction
$ node --version
v26.5.0
$ npm --version
12.0.1
# Even a single exact version returns an array on npm 12:
$ npm view 'lodash@4.17.21' --json | node -e 'process.stdin.once("data",d=>console.log(Array.isArray(JSON.parse(d))))'
true
# A range that matches several versions returns a multi-element array:
$ npm view '@openclaw/codex@^2026.7.1-beta.2' --json | node -e 'process.stdin.once("data",d=>console.log(JSON.parse(d).length))'
5Result: gateway logs repeat
Reason: OpenClaw startup migrations did not complete cleanly; refusing to report the gateway ready.
- Failed to check codex: npm view produced incomplete package metadata
Suggested fix
Normalize the array in normalizeNpmViewMetadata, consistent with the existing npm pack handling — take the last (highest) matching entry:
function normalizeNpmViewMetadata(value) {
if (Array.isArray(value)) value = value[value.length - 1];
if (!value || typeof value !== "object") return null;
const rec = value;
...
}(Verified locally: applying this one-liner lets openclaw update repair reinstall all plugins and the gateway reaches [gateway] ready with codex among the active plugins.)
Secondary hardening (optional but recommended)
- A failed best-effort plugin freshness check at startup probably shouldn't be fatal to the gateway. Consider degrading to a warning (disable/skip the plugin) rather than aborting startup migrations, so a single flaky/incompatible
npm viewcan't take the whole gateway down. - Consider pinning the metadata query with
--json+ selecting by the requested version explicitly, so future npm output-shape changes are less likely to break parsing.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jul 16, 2026
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.
This is a high-quality reproduction of the same npm 12 array-shape parser defect already tracked by the older open canonical issue. The current-main mitigation preserves plugin state on metadata failure but explicitly leaves array normalization unresolved, so the remaining fix should stay consolidated there.
Root-cause cluster
Relationship:
duplicateCanonical: #107222
Summary: The current report and canonical issue identify the same parser, npm 12 array output, failure string, affected npm plugin operations, and unwrap-style repair. This report adds valuable gateway-startup impact evidence but no distinct root cause.
Members:
canonical: normalizeNpmViewMetadata fails on array input from 'npm view --json', breaking all plugin updates #107222 - Older open issue dedicated to the same unresolved npm 12 array-normalization defect.partial_overlap: [Bug]: npm 12 breaks every plugin npm operation ("npm view produced incomplete package metadata"); failure path then disables healthy plugins #106189 - Broader earlier report combined the same parser failure with destructive plugin-state cleanup; the cleanup portion was mitigated while array parsing remains canonical elsewhere.partial_overlap: fix(plugins): preserve state on npm metadata failures #107063 - Merged adjacent mitigation preserves healthy plugin state on metadata failure but explicitly does not normalize npm singleton arrays.Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.
Canonical path: Keep one canonical fix in #107222 that normalizes object and array metadata deterministically, covers single- and multi-result npm output, and verifies plugin update, repair, and gateway-startup paths while retaining the merged non-destructive failure policy.
So I’m closing this here and keeping the remaining discussion on #107222.
Review details
Best possible solution:
Keep one canonical fix in #107222 that normalizes object and array metadata deterministically, covers single- and multi-result npm output, and verifies plugin update, repair, and gateway-startup paths while retaining the merged non-destructive failure policy.
Do we have a high-confidence way to reproduce the issue?
Yes at source level: npm 12's array output reaches an object-only parser, and the exact command, error, startup logs, and locally verified patch are provided. I did not independently execute npm 12 in this read-only review.
Is this the best way to solve the issue?
Yes for the parser defect: normalize the shared npm metadata boundary and add focused array-shape coverage. The broader question of which migration warnings should block readiness is separate from this duplicate.
Security review:
Security review: This is an ordinary issue triage without a proposed patch or security-sensitive report.
AGENTS.md: found and applied where relevant.
What I checked:
normalizeNpmViewMetadataobject assumption, npm 12 array output, incomplete-metadata error, affected plugin operations, and locally verified unwrap fix. (src/infra/install-source-utils.ts, 08ecf63bb608)src/infra/install-source-utils.ts, 08ecf63bb608)src/plugins/update.ts, 08ecf63bb608)docs/cli/plugins.md. (docs/cli/plugins.md, 08ecf63bb608)VISION.md, 08ecf63bb608)Likely related people:
src/infra/install-source-utils.ts,src/plugins/install.ts,src/plugins/update.ts)src/infra/install-source-utils.ts,src/plugins/install.ts,src/plugins/update.ts)src/plugins/update.ts,src/plugins/update.test.ts,docs/cli/plugins.md)Codex review notes: model internal, reasoning high; reviewed against 08ecf63bb608.