Skip to content

Gateway crash-loops on npm 12: npm view --json now always returns an array, breaking plugin metadata parsing #107920

Closed as not planned

Description

@ezimerman

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), so openclaw / the TUI can't reach a gateway.
  • openclaw update repair also fails for every npm plugin (brave, codex, slack in 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.2 once 2026.7.1 ships) 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 version

Only 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))'
5

Result: 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 view can'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.

Activity

  1. added
    P0Emergency: data loss, security bypass, crash loop, or unusable core runtime.
    impact:crash-loopCrash, hang, restart loop, or process-level availability failure.
    impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.
    impact:ux-release-blockerA non-technical user is blocked without terminal, logs, config, or support.
    on Jul 16, 2026
  2. clawsweeper commented on Jul 16, 2026

    @clawsweeper
    Contributor

    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: duplicate
    Canonical: #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:

    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:

    Likely related people:

    • steipete: Merged the current-main metadata-failure state-preservation fix and has recent history across plugin installation, update behavior, tests, and plugin CLI documentation. (role: merger and recent area contributor; confidence: high; commits: 54ec14262b84, 5920ea838d51, 5ca92b0498c9; files: src/infra/install-source-utils.ts, src/plugins/install.ts, src/plugins/update.ts)
    • mushuiyu886: Authored the merged adjacent fix that classifies npm metadata failures and preserves installed plugin state, making them directly familiar with this failure boundary. (role: recent merged fix author; confidence: high; commits: c413e4c88223; files: src/infra/install-source-utils.ts, src/plugins/install.ts, src/plugins/update.ts)
    • huntharo: The versioned plugin update flow and central updater regression coverage appear to date to this contributor's merged work. (role: introduced related behavior; confidence: medium; commits: 401ffb59f538; files: src/plugins/update.ts, src/plugins/update.test.ts, docs/cli/plugins.md)

    Codex review notes: model internal, reasoning high; reviewed against 08ecf63bb608.

  3. locked as resolved and limited conversation to collaborators on Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Emergency: data loss, security bypass, crash loop, or unusable core runtime.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.impact:ux-release-blockerA non-technical user is blocked without terminal, logs, config, or support.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions