Skip to content

fix(update): Keep Openclaw alive across brew upgrade and other Node version bumps - #80386

Closed
yaanfpv wants to merge 1 commit into
openclaw:mainfrom
yaanfpv:fix/update-global-escape-cellar
Closed

yaanfpv wants to merge 1 commit into
openclaw:mainfrom
yaanfpv:fix/update-global-escape-cellar

Conversation

@yaanfpv

@yaanfpv yaanfpv commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: a routine brew upgrade (or any version-manager bump to a new Node major) silently wipes the openclaw command. The operator opens a fresh shell and gets openclaw: command not found with no warning.
  • Why it matters: nothing they did caused it, and openclaw update was the thing keeping them stuck. Each successful self-update was reinstalling openclaw back inside the same per-Node directory the version manager would later delete.
  • What changed: the self-update resolver now spots per-Node ephemeral install prefixes (Homebrew Cellar, nvm, asdf, volta, fnm, n) and refuses to use the per-version npm from inside them. The fallback to PATH npm lands the install at a version-agnostic prefix that survives the next bump.
  • What did NOT change: no CLI flags, no migrations, no telemetry. Stable prefixes (/opt/homebrew/lib/node_modules, ~/.npm-global, /usr/local, etc.) resolve exactly as before.

Change Type

  • Bug fix

Scope

  • CI/CD / infra

Linked Issue/PR

Real behavior proof

  • Behavior or issue addressed: after brew upgrade bumped Homebrew Node from 25.9.0_3 to 26.0.0, openclaw was gone from PATH. The bin shim at /opt/homebrew/bin/openclaw pointed inside the deleted Node 25 cellar.

  • Real environment tested: macOS 26.4.1, Apple Silicon, Homebrew Node 26.0.0 (post-upgrade). Live ~/.openclaw/ with the gateway service still running off the in-memory copy of the now-deleted Node 25 binary.

  • Exact steps or command run after this patch: applied the same fix to the locally installed dist/update-runner-DXN2t6wW.js so the running self-update path picked it up. Reinstalled via the brew-shimmed npm: /opt/homebrew/bin/npm install -g openclaw. Confirmed the install landed at /opt/homebrew/lib/node_modules/openclaw/ instead of the cellar. Ran openclaw --version and which openclaw.

  • Evidence after fix:

    Before:

    $ which openclaw
    openclaw not found
    $ ls -la /opt/homebrew/bin/openclaw
    lrwxr-xr-x 1 sohamagents admin 73 May 4 21:27 /opt/homebrew/bin/openclaw -> /opt/homebrew/Cellar/node/25.9.0_3/lib/node_modules/openclaw/openclaw.mjs
    $ ls /opt/homebrew/Cellar/node/25.9.0_3/lib/node_modules/openclaw/openclaw.mjs
    ls: No such file or directory
    

    After patch + reinstall:

    $ openclaw --version
    OpenClaw 2026.5.2 (8b2a6e5)
    $ readlink /opt/homebrew/bin/openclaw
    /opt/homebrew/lib/node_modules/openclaw/openclaw.mjs
    
  • Observed result after fix: openclaw reachable on PATH again, anchored to the version-agnostic shared prefix. A subsequent npm install -g openclaw brought 2026.5.7 back, also under /opt/homebrew/lib/node_modules/openclaw/ rather than the cellar.

  • What was not tested: live openclaw update against fresh nvm or asdf installs. Those layouts are covered by the unit test only. The cellar repro is one-shot destructive on a maintainer machine, so re-triggering a real second brew upgrade to a new Node major was not done inside this PR.

  • Before evidence: the dangling symlink and which openclaw output above are exactly what an operator lands in after a routine brew upgrade that pulls a new Node major.

Root Cause

  • Root cause: resolvePreferredNpmCommand(pkgRoot) walks up from pkgRoot to find an adjacent bin/npm and returns it. It never checks whether that prefix is a per-Node version-manager directory the manager will later delete. Once openclaw lands in such a directory, every self-update reinstalls back into it.
  • Missing detection / guardrail: no path-shape check for the known ephemeral layouts.
  • Contributing context (if known): brew's node formula bundles its own npm whose default prefix is the cellar. Anything that invokes that bundled npm directly (a post-install script, a CI step, a tooling layer that bypasses the brew shim) lands openclaw inside the cellar. From there, self-update perpetuates it until brew deletes the dir.

Regression Test Plan

  • Coverage level that should have caught this:
    • Unit test
  • Target test or file: src/infra/update-global.test.ts, new case covering the cellar / nvm / asdf / volta / fnm / n layouts.
  • Scenario the test should lock in: when pkgRoot sits inside a per-Node prefix and the per-version bin/npm exists on disk, globalInstallArgs and globalInstallFallbackArgs both return argv whose first element is the plain "npm" command, not the per-version path.
  • Why this is the smallest reliable guardrail: the test fabricates each layout under a temp dir with a real on-disk bin/npm, so the existence check inside the resolver would otherwise succeed and the per-version npm would be picked. No live brew, nvm, asdf, volta, fnm, or n needed.
  • Existing test that already covers this (if any): no. The existing "prefers the owning npm prefix" test only covers the stable lib/node_modules shape under a brew-prefix root. It still passes after this fix.

User-visible / Behavior Changes

Healthy installs see no change. Installs currently anchored inside an ephemeral prefix get relocated to the PATH npm prefix on their next openclaw update, one-time per affected install. Operators running the daemon-managed gateway will want to restart it after the relocation.

Diagram

Before:
  openclaw update (inside /opt/homebrew/Cellar/node/X/.../openclaw/)
    -> resolvePreferredNpmCommand picks /opt/homebrew/Cellar/node/X/bin/npm
    -> npm install -g openclaw lands back in the same cellar dir
    -> brew upgrade node deletes /opt/homebrew/Cellar/node/X
    -> openclaw vanishes from PATH

After:
  openclaw update (same starting point)
    -> isEphemeralPerNodeInstallPrefix() => true => resolver returns null
    -> falls back to PATH npm
    -> install lands at a version-agnostic prefix
    -> next brew upgrade leaves openclaw intact

Security Impact

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No. The resolver still picks among existing npm binaries on disk; the only change is which one it picks.
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS 26.4.1 (arm64)
  • Runtime/container: Homebrew Node 26.0.0 (and Node 25.9.0_3 layout in the unit fixture)
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. Have openclaw installed under /opt/homebrew/Cellar/node/<X>/lib/node_modules/openclaw/. Run brew upgrade node to a new major. Observe which openclaw returns "not found".
  2. Apply this patch and rebuild dist.
  3. Reinstall openclaw via the brew-shimmed npm. Confirm the install sits outside any cellar dir.
  4. Run openclaw update again and confirm the install stays at the same version-agnostic prefix.

Expected

openclaw update from inside an ephemeral prefix falls back to PATH npm. The reinstall lands at a stable prefix that survives later version-manager bumps.

Actual

After patch, matches expected. Verified via the unit test and the live dist-patch verification on the affected machine.

Evidence

  • Failing test/log before + passing after (terminal output in Real behavior proof above)
  • Trace/log snippets (which openclaw, ls -la, readlink, openclaw --version)

Human Verification

  • Verified scenarios: reproduced the broken state on the affected machine, applied the same logic to the locally installed dist file, ran openclaw --version (returned OpenClaw 2026.5.2 (8b2a6e5)), reinstalled via the brew-shimmed npm and confirmed openclaw 2026.5.7 landed at the version-agnostic prefix instead of the cellar.
  • Edge cases checked: Cellar with node@<N> (versioned formula) alongside the unversioned node formula. fnm's installation segment after the version. Stable prefixes on the same machine (/opt/homebrew, ~/.npm-global) do not match any pattern and stay unaffected.
  • What you did not verify: live openclaw update against fresh nvm or asdf installs. pnpm check:changed was not run in Testbox; targeted pnpm test src/infra/update-global.test.ts passes locally.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No. Operators currently in an ephemeral prefix get migrated transparently on their next openclaw update.

Risks and Mitigations

  • Risk: false-positive detection on a path that happens to look like a per-Node prefix but is actually stable.
    • Mitigation: the regex patterns require version-segment shapes specific to each manager (Cellar/node/<X>, .nvm/versions/node/v<X>, etc.) and will not match generic user-chosen paths. If a false positive ever did occur, the user-visible effect is just falling back to PATH npm.

@openclaw-barnacle openclaw-barnacle Bot added size: S proof: supplied External PR includes structured after-fix real behavior proof. labels May 10, 2026
@clawsweeper

clawsweeper Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep this PR open for now: the central fix is already on current main through the merged replacement #93650, but a member explicitly left this source PR open for review context and contributor follow-up on June 16, 2026.

Root-cause cluster
Relationship: superseded
Canonical: #93650
Summary: The same self-update npm-prefix bug is fixed by the merged replacement PR, while this source PR remains open only because a member explicitly left it for context and follow-up.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Close this PR as superseded by #93650.

So I’m closing this here and keeping the remaining discussion on #93650.

Review details

Best possible solution:

Close this PR as superseded by #93650.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection shows the update path uses globalInstallArgs from the resolved install target, and the issue/PR evidence describes a Homebrew Cellar package root whose adjacent npm would previously perpetuate the deleted-prefix trap.

Is this the best way to solve the issue?

Yes for the merged replacement; it keeps ownership detection while avoiding per-Node npm for reinstall command selection. This source branch is no longer the best merge vehicle because the replacement is already on main and removed the changelog churn.

Security review:

Security review cleared: The diff changes local npm command selection, focused tests, and changelog text only; it adds no dependency, workflow, secret, permission, or downloaded-code surface.

AGENTS.md: found and applied where relevant.

What I checked:

  • linked superseding PR: fix(update): avoid per-Node npm prefixes during self-update #93650 (fix(update): avoid per-Node npm prefixes during self-update) is merged at 2026-06-16T13:54:09Z.
  • cluster evidence: the durable review links that PR in the work cluster or recommended risk path.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • vincentkoc: Merged the replacement PR that put the same resolver behavior on main and has recent update CLI/package-update commits in adjacent paths. (role: recent area contributor and merger; confidence: high; commits: df8ceb526725, 15a0156a8cda, c1a414bf286a; files: src/infra/update-global.ts, src/infra/update-global.test.ts, src/cli/update-cli/update-command.ts)
  • steipete: Recent GitHub commit history shows several update-global and update command changes around managed roots, npm freshness, and update compatibility behavior. (role: recent area contributor; confidence: high; commits: db8de0db7aba, 97d1f5fd153c, 86385f72e98d; files: src/infra/update-global.ts, src/infra/update-global.test.ts, src/cli/update-cli/update-command.ts)
  • fuller-stack-dev: Recent commits changed staged/global update behavior and package update steps that consume the resolved install command. (role: recent adjacent contributor; confidence: medium; commits: 84f6b5c7f8de, 7259cb5c771b, ce31fc91e15d; files: src/infra/update-global.ts, src/infra/update-global.test.ts, src/infra/package-update-steps.ts)
  • jayeshp19: GitHub history shows the owning npm prefix selection behavior that this PR narrows for ephemeral per-Node prefixes dates to this contributor's update-global commit. (role: introduced behavior; confidence: medium; commits: eb4b6f7024d3; files: src/infra/update-global.ts, src/infra/update-global.test.ts)
  • yaanfpv: The source PR author is also credited as a co-author on the merged replacement commit, connecting them to the current-main implementation beyond this open branch. (role: source contributor and replacement co-author; confidence: medium; commits: bdcb15b0359c, df8ceb526725; files: src/infra/update-global.ts, src/infra/update-global.test.ts)

Codex review notes: model internal, reasoning high; reviewed against f4e9a6e04780; fix evidence: commit df8ceb526725, main fix timestamp 2026-06-16T13:54:08Z.

What an operator hit:
A routine `brew upgrade` (or `nvm install` of a new Node major) bumped Node from 25 to 26. Brew deleted the old Node 25 cellar directory. Next shell: `openclaw: command not found`. Their `~/.openclaw/` config was fine, but the CLI itself was gone until they manually re-ran `npm install -g openclaw`, with no obvious clue what they did wrong.

Why it kept happening:
`openclaw update` was reinstalling openclaw using the npm sitting next to its current install. If that current install was inside a per-Node version-manager directory (Homebrew Cellar, nvm, asdf, volta, fnm, tj/n), the per-version npm has a per-version prefix, so reinstall went back into the same per-version dir. The trap is self-perpetuating, and `openclaw update` could not get an operator out of it. Only an explicit `npm install -g openclaw` invoked through a version-agnostic shimmed npm would relocate openclaw to a stable prefix, and most operators do not know that.

What changes:
The self-update resolver in src/infra/update-global.ts now recognizes per-Node ephemeral prefixes by path shape and refuses to use the per-version npm in those cases. The existing fallback in resolvePreferredGlobalManagerCommand uses the npm on PATH, which on properly-configured systems lives at a version-agnostic prefix that survives version bumps. Operators currently in the trap are transparently relocated on their next openclaw update. Healthy installs are untouched.

Patterns matched (the prefix is the dir holding bin/ and lib/, e.g. /opt/homebrew/Cellar/node/X.Y.Z):
  Homebrew:        .../Cellar/node/<X>           or .../Cellar/node@<N>/<X>
  nvm:             .../.nvm/versions/node/v<X>
  asdf (classic):  .../.asdf/installs/nodejs/<X>
  volta:           .../.volta/tools/image/node/<X>
  fnm:             .../.fnm/node-versions/v<X>/installation
  n (tj/n):        .../n/versions/node/<X>

Regression test in src/infra/update-global.test.ts covers all six layouts by fabricating each version-manager directory with a real on-disk bin/npm and asserting globalInstallArgs falls back to plain "npm" instead of the per-version path.
@yaanfpv
yaanfpv force-pushed the fix/update-global-escape-cellar branch from 0cd09e7 to bdcb15b Compare May 20, 2026 10:02
@yaanfpv

yaanfpv commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main and addressed the clawsweeper P1 by separating npm-ownership detection from preferred-npm selection.

P1 fix: added detectOwningNpmCommand in src/infra/update-global.ts that performs the same "is there an npm next to this package root" check as resolvePreferredNpmCommand but does NOT refuse ephemeral per-Node prefixes. detectGlobalInstallManagerForRoot now calls detectOwningNpmCommand instead, so when openclaw is installed inside a trapped Cellar / nvm / asdf / volta / fnm / n directory, ownership detection correctly returns "npm" and runSelfUpdate enters its global-update branch instead of returning skipped / not-git-install. resolvePreferredNpmCommand keeps refusing those prefixes, so the reinstall argv still falls back to PATH npm and relocates to a version-agnostic prefix as before.

Test gap fix (regression coverage for clawsweeper's concern): new test in src/infra/update-global.test.ts asserts detectGlobalInstallManagerForRoot returns "npm" for all six trapped layouts (Cellar, nvm, asdf, volta, fnm, n), with PATH npm pointing at a different non-ephemeral global root. Each layout case also re-asserts that globalInstallArgs still falls back to plain "npm" so both halves of the fix stay locked in. 32 tests pass locally via node scripts/run-vitest.mjs src/infra/update-global.test.ts.

Real behavior proof still pending: I do not have a trapped Cellar / nvm install on this machine to capture an after-fix openclaw update transcript. The unit tests cover the code path that was broken (the P1 finding), but the "real after-fix terminal output of openclaw update relocating a trapped install" proof that the PR body's original block referenced is not in this push. If a maintainer wants that captured before merge, I can stand one up; if the unit-level proof is sufficient given the audit-trail in the new test, the PR is ready for re-review.

Test-fixture updates: while rebasing, the existing test had to grow --min-release-age=0 to match upstream's npm install-args change. Both globalInstallArgs and globalInstallFallbackArgs assertions for the trapped-Cellar case were updated.

Other changes: none. The branch is now a single squashed commit on top of current main, containing the original ephemeral-prefix refusal logic, the new ownership-detection split, the new regression test, the updated argv assertions, and the existing CHANGELOG entry.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels May 20, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@yaanfpv

yaanfpv commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Pushed bdcb15b since your last review. Rebased onto main, addressed P1 by splitting ownership detection from preferred-npm selection, added a regression test covering all six trapped layouts. Real behavior proof check went green post-push. Curious if the rating updates.

@clawsweeper

clawsweeper Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

Clownfish 🐠 reef update

Thanks for the contribution. Clownfish hit a branch-permission wall on this PR, so it opened a replacement branch to keep review moving while preserving credit.

Replacement PR: #93650
Source PR: #80386
Leaving this source PR open for review context and contributor follow-up.
Attribution is preserved in the replacement PR body and release-note trail.

fish notes: model gpt-5.5, reasoning medium; reviewed against 82c8b7c.

@clawsweeper

clawsweeper Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Openclaw command disappears after brew upgrade installs a new Node major

2 participants