Skip to content

fix(node): keep npx-installed services outside the npm cache - #168644

Merged
obviyus merged 6 commits into
mainfrom
fix/durable-npx-node-service
Oct 11, 2026
Merged

obviyus merged 6 commits into
mainfrom
fix/durable-npx-node-service

Conversation

@obviyus

@obviyus obviyus commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes node services installed through npx openclaw connect <join-url> --service or npx openclaw node install pointing at npm's disposable _npx cache.

User Impact

The one-paste command installs the selected OpenClaw release into a durable npm prefix under the node's state directory before writing the service. Removing npm's exec cache no longer removes the service's executable. Installation prints the package version, chosen runtime, service command, and a fresh-npx node update command.

Why This Change Was Made

The service argument resolver previously used the running package's resolved path. #167905 fixes pnpm's replaceable store-generation paths by selecting its existing stable link; npm exec has no stable link to select. This preserves that pnpm behavior and adds node-install promotion through the existing npm update owners (resolveGlobalInstallTarget, runGlobalPackageUpdateSteps, and their staged publication/rollback/cleanup).

There is one <state-dir>/npm prefix, not a prefix per release. The normal state-directory/profile resolver chooses its location. Run npx -y openclaw@latest node install --force on the node to update it, retaining the same profile/state-directory settings. An exact version or @beta can replace @latest. Reinstalling an already-selected version repairs damaged package files. No new settings or package manager.

This does not change openclaw update or its existing co-located Gateway selection behavior. Node auto-update still follows the node's npm channel, not the connected Gateway's version/build. The rebase preserves #168653's paired-credential filtering and explicit --auth-from-env service argument.

Evidence

Final code: 27b447dc07b737126124ff8847f2059cb8a4f921. Packaged live proof ran on 292bd19fe934ecf4ee4e3b20b00a03a1b08f7933; production feature code and docs are unchanged since that proof. The final revision only corrects regression-test platform handling and rebases onto green main.

  • Before: the regression on baseline e40606fdea96135758ec5bc0b1a355d08ead0c7e selected .npm/_npx/.../node_modules/openclaw/dist/index.js. In the live isolated replay, published [email protected] completed real join-URL enrollment; deleting its npm exec cache made the saved command exit 1 with MODULE_NOT_FOUND.
  • After: the canonical self-contained package passed scripts/package-openclaw-for-docker.mjs --skip-build --allow-unreleased-changelog and its tarball inventory/import-graph integrity check. Real npm exec --package=<candidate.tgz> -- openclaw connect <join-url> --service promoted that selected package into the node's state-owned npm prefix. Both actual launchd and systemd generators selected the durable entrypoint. After removing _npx, executing the persisted command as a separate process connected to the isolated Gateway. The published driver's device identity and node settings were unchanged.
  • Upgrade and repair: seeded the durable prefix with published [email protected], retained the enrolled node state, and invoked the candidate through fresh npx with --profile upgrade node install --force. The prefix became the candidate version. Overwriting its dist/index.js and repeating the same command restored the exact original file bytes. The runtime, device identity, and node settings remained unchanged; the repaired persisted command connected after deleting _npx again. The prefix contained only bin and lib, with one openclaw package rather than per-release directories.
  • Package identity: the unpublished candidate shares the version string 2026.9.9 with the public release. An isolated loopback npm registry served the canonical candidate tarball for that version, while forwarding dependency requests to npm. This prevents accidentally testing promotion of the older public package with the same version string; no product behavior was mocked.
  • Focused checks: 50 tests passed across src/commands/node-daemon-install-npx.test.ts, src/commands/node-daemon-install-helpers.test.ts, and src/cli/node-cli/daemon.test.ts. The new regression uses actual generators and executes their commands after cache deletion. The final portability correction keeps systemd coverage on non-Windows platforms and reads launchd artifacts only on macOS. That corrected regression passed (1.285 s test execution), and the core-test-commands type graph passed. Its unchanged durable-path assertion failed on the baseline as expected (pueue 2903).
  • Changed checks: formatting, conflict/line-count/assertion/SQLite/mock-export ratchets, config docs, plugin boundaries, dependency guards, and the core type graph boundary passed. The prior head's local core typecheck stopped on unrelated channel-presence-policy.ts:519 TS6133; the branch is now rebased onto the main fix rather than carrying a separate repair.
  • Independent review: LAND on exact final head 27b447dc07b737126124ff8847f2059cb8a4f921, including the corrected test, updater-step adapter, and paired-auth preservation.

Sanitized live results:

before-cache-deleted: exit 1 (MODULE_NOT_FOUND)
after:  /state/npm/lib/node_modules/openclaw/dist/index.js
node host gateway connected: ws://127.0.0.1:<isolated-port>
upgrade: 2026.9.8 -> candidate 2026.9.9
sameVersionRepair: true
runtimePreserved: true
pairingAndSettingsPreserved: true
connectedAfterCacheDeletion: true

Native-supervisor limitation: supervisor activation was not verified. Native service installation reaches the existing systemd user-session/profile guards in the unprivileged container; macOS refuses native installation from an isolated HOME. The proof runs actual generated service arguments as a separate live node, not under an activated OS supervisor. Launchd XML was decoded in Linux and passed through the production generated-environment resolver; the macOS regression exercises the actual plist reader. No HOME-guard bypass, privileged container, existing Gateway, or real laptop installation was used.

CI: final-head run 38097819645 passed, including production types, test types, lint, source contracts, and the corrected Linux regression. All applicable PR checks finished with no failure, cancellation, or pending check. The final head is rebased onto green main; no inherited failure waiver or SDK budget change is needed. ClawSweeper is ready, 5/6, and the independent reviewer returned LAND, both on 27b447dc07b737126124ff8847f2059cb8a4f921.

Bounded cost

Only npx-backed node installation needs an additional npm installation. It uses one state-owned prefix and the existing updater's staging, verification, rollback, and cleanup; it does not accumulate per-version prefixes. Reuse verifies the installed package and advertised content inventory, so a same-version damaged package is repaired. Ordinary node execution and model/session paths are unchanged. Non-npx installation adds only entrypoint inspection and installation diagnostics.

Source +104/-2, tests +88/-0, docs +34/-0; net +224 across seven files. The growth reuses the existing package updater rather than adding another installation or state owner.

Merge Danger

Two-way code change, with a durable npm installation left in the selected node state directory if reverted. A revert restores the old npx service-install behavior; it does not remove an already installed package. Blast radius is headless node service installation and its printed diagnostics; Gateway installation and pnpm launcher resolution are unchanged.

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes commands Command implementations size: S labels Oct 10, 2026
@obviyus
obviyus marked this pull request as ready for review October 10, 2026 21:11
@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR installs npx-backed node services into a durable npm prefix and prints installation and update guidance.

Example: Enroll a node using npx openclaw connect <join-url> --service, then delete npm's _npx cache.

  • Before: The saved command points into .npm/_npx and exits with MODULE_NOT_FOUND.
  • After: The saved command uses /state/npm/lib/node_modules/openclaw/dist/index.js and reconnects to the Gateway.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-level repair with shipped-entry-point durability proof, preserved existing state, and no open finding; pending CI is not a completed validation result.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Supplied packaged npm-exec logs exercise enrollment and durable promotion, then execute the persisted command against an isolated Gateway after cache deletion; upgrade and same-version repair preserve identity, settings, and runtime. All changed production modules match the proven revision. OS supervisor activation was not exercised, and the unrelated downloaded UI screenshots were excluded.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An enrolled node service can lose its executable when npm removes its temporary exec cache.
Reason: Durable service execution is an existing contract, and the focused repair preserves runtime selection, pairing, settings, and existing installation owners.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a service-durability bug still present on current main, with sufficient scoped live proof and no identified correctness or security defect. Exact-head CI remains pending.

Priority: P1
Reviewed head: 27b447dc07b737126124ff8847f2059cb8a4f921

Before merge

None.

Findings

None.

Agent review details

How this fits together

The node-service install planner receives the selected runtime and saved Gateway settings, promotes temporary npm installations through the existing package updater, and supplies durable arguments to platform service writers.

flowchart TD
  A[Node install or connect CLI] --> B[Node install planner]
  B --> C[Npx package resolver]
  C --> D[Existing npm updater]
  D --> E[State owned package prefix]
  E --> F[Platform service command]
  F --> G[Gateway connection]
Loading

Technical review

Best possible solution:

Use one verified state-owned npm installation for npx-backed node services through the existing package updater.

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

Current-main source retains the temporary package path, and supplied published-package logs show cache deletion producing MODULE_NOT_FOUND; this review executed no target code.

Is this the best way to solve the issue?

The patch repairs service argument selection at its producer, preserves pnpm and paired-auth behavior, and reuses the existing updater rather than adding another package-management owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4754d394130a.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9b46148 adds src/daemon/program-args.ts:37 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9b46148b2680; files: src/daemon/program-args.ts)
  • Ayaan Zaidi: Raw commit 1bc9624 adds src/commands/node-daemon-install-helpers.ts:80 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1bc9624c8aa6; files: src/commands/node-daemon-install-helpers.ts)

PR surface

Source +102, Tests +88, Docs +34. Total +224 across 7 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 104 2 +102
Tests 1 88 0 +88
Docs 2 34 0 +34
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 226 2 +224

Review metrics

Metric Value Why it matters
Production versus test growth Production +104/-2; tests +88/-0 The production growth adds scoped npm-exec promotion and diagnostics while reusing staging, verification, rollback, and cleanup owners; the regression protects generated command durability.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Clearing npm's disposable cache can stop an enrolled node service from starting or reconnecting.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (5 earlier review cycles)
  • reviewed 2026-10-10T21:17:41.358Z sha fe28e61 :: needs changes before merge. :: [P2] Verify content integrity before reusing a same-version package
  • reviewed 2026-10-10T21:56:49.021Z sha a7a604e5298bce25f9ebdbe9417d3ce1b1ede27a :: blocked before merge. :: none
  • reviewed 2026-10-10T22:24:36.096Z sha 88a14fddd786904d7297593ee992b246d231f706 :: blocked before merge. :: none
  • reviewed 2026-10-10T23:10:38.404Z sha 292bd19fe934ecf4ee4e3b20b00a03a1b08f7933 :: blocked before merge. :: none
  • reviewed 2026-10-11T00:07:53.206Z sha 292bd19fe934ecf4ee4e3b20b00a03a1b08f7933 :: needs changes before merge. :: none

Reviewed October 10, 2026, 8:21 PM ET / October 11, 2026, 00:21 UTC (Revision 6).

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@obviyus
obviyus force-pushed the fix/durable-npx-node-service branch from a7a604e to 88a14fd Compare October 10, 2026 22:10
@clawsweeper clawsweeper Bot added the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 10, 2026
@obviyus
obviyus force-pushed the fix/durable-npx-node-service branch from 88a14fd to d7a018e Compare October 10, 2026 22:53
@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 10, 2026
@obviyus

obviyus commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 11, 2026
@obviyus
obviyus force-pushed the fix/durable-npx-node-service branch from 292bd19 to 27b447d Compare October 11, 2026 00:15
@obviyus

obviyus commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@obviyus
obviyus merged commit 84e59be into main Oct 11, 2026
137 of 138 checks passed
@obviyus
obviyus deleted the fix/durable-npx-node-service branch October 11, 2026 00:27
obviyus added a commit that referenced this pull request Oct 11, 2026
## What Problem This Solves

Fixes machine enrollment silently running an old cached npm release when the Gateway is newer.

## User Impact

`devices join-code` and the Control UI now suggest the Gateway's published npm version, not the invoking CLI's version. Both also show the short alternative for an existing OpenClaw installation. The default remains a background service with explicit session-host consent; command-only services remain available.

Source checkouts and unpublished builds prefer a resolvable matching channel tag. If npm cannot confirm a target, the command stays unpinned and a one-line note asks for a matching Gateway build. JSON keeps `joinUrl` and `command`, adding `serviceCommand`, `installedCommand`, and optional `versionNote`.

## Why This Change Was Made

[#168623](#168623) / `8f91e4bb65f` established the one-paste service/session-host default but deliberately left npm unpinned. npm can reuse an old cached package. The Gateway now owns version selection and command formatting in the same RPC that mints the URL; CLI and UI consume its commands instead of independently rebuilding them.

The existing update owners supply install identity and channel policy. Joining does not run a full update/dependency inspection. This composes with the durable service installation work in [#168644](#168644); it does not change node execution, service lifecycle, or upgrade commands.

No overlap with Pash/Sarah changes.

## Evidence

- Regressions on `8f91e4bb65f`: eight Gateway/CLI-boundary cases and three CLI text/JSON cases fail for missing authoritative commands; the real browser regression reaches the setup RPC and fails waiting for the pinned command.
- Focused Gateway and CLI suites: 84 tests passed after the final lightweight-install-discovery refinement. The Gateway suite took 173.85s and CLI suite 43.42s on the loaded local host (including transform/setup); assertions took about 1.7s and 15.5s respectively.
- All five browser flows passed. After the final template simplification, the real bundled UI mint/refresh flow passed again (46.41s, including setup), covering the pinned command, installed alternative, and development fallback note. The Control UI Lit ratchet also passed.
- Real isolated Gateway text/JSON: baseline printed unpinned npm commands; candidate printed `[email protected]`, matching the Gateway release, plus the existing-installation alternative. Both exited successfully. This proof exercises command generation, not installation on a second machine; durable service installation is covered separately by #168644.
- The built CLI bootstrap guard passed. The local changed gate stopped at an unrelated existing mock-export violation in `src/model-picker/apply-session-model-selection-placement.test.ts`; the rebase picked up its existing `mock-isolation` explanation. Hosted exact-head CI is the final check.
- Inherited CI failure: [the final-head job](https://github.com/openclaw/openclaw/actions/runs/38096158809/job/114342554800) failed `plugin-sdk-surface-report.test.ts` on SDK export-budget drift: 3672 > 3656 exports, 2133 > 2122 callables, 158 > 154 deprecated exports, and two deprecated-entrypoint budgets. Clean `origin/main` at `dd4b258a3cfa6fdef41535e5518fe260f5665a9c` reproduces the same budget failures (2 failed, 3 passed, 1 Linux-only test skipped on macOS; 18.84s). The aggregate CI gate reports this failure; fail-fast cancelled the other unfinished lanes. This PR changes no plugin SDK surface or budget.

Production: +105/-17 lines; tests: +188/-27; documentation: +23/-2. The added production logic replaces independent CLI/UI formatting with one Gateway decision owner.

<details>
<summary>Real isolated Gateway terminal output (redacted)</summary>

Gateway: `OpenClaw 2026.9.9`. Both text and JSON commands exited 0. Only the ephemeral loopback port and single-use code are redacted.

Before (`devices join-code`):

```text
npx -y openclaw connect http://127.0.0.1:<port>/j/<code> --service --session-host
```

After (`devices join-code`):

```text
npx -y [email protected] connect http://127.0.0.1:<port>/j/<code> --service --session-host
Already have OpenClaw installed? Run: openclaw connect http://127.0.0.1:<port>/j/<code> --service --session-host
```

After (`devices join-code --json`):

```json
{
  "joinUrl": "http://127.0.0.1:<port>/j/<code>",
  "command": "npx -y [email protected] connect http://127.0.0.1:<port>/j/<code> --service --session-host",
  "serviceCommand": "npx -y [email protected] connect http://127.0.0.1:<port>/j/<code> --service",
  "installedCommand": "openclaw connect http://127.0.0.1:<port>/j/<code> --service --session-host"
}
```

</details>

### Connect a machine

| Before | After |
| --- | --- |
| ![Before: unpinned npm join command](https://github.com/user-attachments/assets/f9af80a8-039d-4b95-8102-1dd943a89672) | ![After: Gateway-selected npm version and installed alternative](https://github.com/user-attachments/assets/9b627f4b-5bf8-49a9-ae0b-3e222aa9652f) |

The screenshots use synthetic Gateway data and the actual bundled Control UI.

## Bounded cost

Only explicit join-code creation performs registry work: at most two npm metadata GETs, each with a one-second deadline including the response body. No background polling, model calls, package-manager subprocesses, retries, or new caches. Existing prepared install identity is reused; if absent, the update owner's lightweight local classifier runs without dependency inspection, with its Git probe bounded to one second. No registry lookup is performed by CLI or UI.

## Compatibility and Risk

The RPC fields are additive. A new CLI needs a Gateway that returns the authoritative commands and explains how to update if it connects to an older Gateway. Published npm releases use exact versions; development/unpublished/offline results are explicitly marked as requiring a matching build. Shell quoting remains owned by the existing CLI argument helper.

Two-way door: reverting changes future suggestions and added response fields only. It does not change existing pairings, service state, or session-host consent. The blast radius is enrollment instructions and their presentation.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…w#168644)

## What Problem This Solves

Fixes node services installed through `npx openclaw connect <join-url> --service` or `npx openclaw node install` pointing at npm's disposable `_npx` cache.

## User Impact

The one-paste command installs the selected OpenClaw release into a durable npm prefix under the node's state directory before writing the service. Removing npm's exec cache no longer removes the service's executable. Installation prints the package version, chosen runtime, service command, and a fresh-npx node update command.

## Why This Change Was Made

The service argument resolver previously used the running package's resolved path. openclaw#167905 fixes pnpm's replaceable store-generation paths by selecting its existing stable link; npm exec has no stable link to select. This preserves that pnpm behavior and adds node-install promotion through the existing npm update owners (`resolveGlobalInstallTarget`, `runGlobalPackageUpdateSteps`, and their staged publication/rollback/cleanup).

There is one `<state-dir>/npm` prefix, not a prefix per release. The normal state-directory/profile resolver chooses its location. Run `npx -y openclaw@latest node install --force` on the node to update it, retaining the same profile/state-directory settings. An exact version or `@beta` can replace `@latest`. Reinstalling an already-selected version repairs damaged package files. No new settings or package manager.

This does not change `openclaw update` or its existing co-located Gateway selection behavior. Node auto-update still follows the node's npm channel, not the connected Gateway's version/build. The rebase preserves openclaw#168653's paired-credential filtering and explicit `--auth-from-env` service argument.

No overlap with Pash/Sarah changes.

## Evidence

Final code: `27b447dc07b737126124ff8847f2059cb8a4f921`. Packaged live proof ran on `292bd19fe934ecf4ee4e3b20b00a03a1b08f7933`; production feature code and docs are unchanged since that proof. The final revision only corrects regression-test platform handling and rebases onto green main.

- **Before:** the regression on baseline `d1abe907cb7cfa63aeee7168099fabc81dd8309a` selected `.npm/_npx/.../node_modules/openclaw/dist/index.js`. In the live isolated replay, published `[email protected]` completed real join-URL enrollment; deleting its npm exec cache made the saved command exit 1 with `MODULE_NOT_FOUND`.
- **After:** the canonical self-contained package passed `scripts/package-openclaw-for-docker.mjs --skip-build --allow-unreleased-changelog` and its tarball inventory/import-graph integrity check. Real `npm exec --package=<candidate.tgz> -- openclaw connect <join-url> --service` promoted that selected package into the node's state-owned npm prefix. Both actual launchd and systemd generators selected the durable entrypoint. After removing `_npx`, executing the persisted command as a separate process connected to the isolated Gateway. The published driver's device identity and node settings were unchanged.
- **Upgrade and repair:** seeded the durable prefix with published `[email protected]`, retained the enrolled node state, and invoked the candidate through fresh npx with `--profile upgrade node install --force`. The prefix became the candidate version. Overwriting its `dist/index.js` and repeating the same command restored the exact original file bytes. The runtime, device identity, and node settings remained unchanged; the repaired persisted command connected after deleting `_npx` again. The prefix contained only `bin` and `lib`, with one `openclaw` package rather than per-release directories.
- **Package identity:** the unpublished candidate shares the version string `2026.9.9` with the public release. An isolated loopback npm registry served the canonical candidate tarball for that version, while forwarding dependency requests to npm. This prevents accidentally testing promotion of the older public package with the same version string; no product behavior was mocked.
- **Focused checks:** 50 tests passed across `src/commands/node-daemon-install-npx.test.ts`, `src/commands/node-daemon-install-helpers.test.ts`, and `src/cli/node-cli/daemon.test.ts`. The new regression uses actual generators and executes their commands after cache deletion. The final portability correction keeps systemd coverage on non-Windows platforms and reads launchd artifacts only on macOS. That corrected regression passed (1.285 s test execution), and the `core-test-commands` type graph passed. Its unchanged durable-path assertion failed on the baseline as expected (pueue 2903).
- **Changed checks:** formatting, conflict/line-count/assertion/SQLite/mock-export ratchets, config docs, plugin boundaries, dependency guards, and the core type graph boundary passed. The prior head's local core typecheck stopped on unrelated `channel-presence-policy.ts:519` TS6133; the branch is now rebased onto the main fix rather than carrying a separate repair.
- **Independent review:** LAND on exact final head `27b447dc07b737126124ff8847f2059cb8a4f921`, including the corrected test, updater-step adapter, and paired-auth preservation.

Sanitized live results:

```text
before-cache-deleted: exit 1 (MODULE_NOT_FOUND)
after:  /state/npm/lib/node_modules/openclaw/dist/index.js
node host gateway connected: ws://127.0.0.1:<isolated-port>
upgrade: 2026.9.8 -> candidate 2026.9.9
sameVersionRepair: true
runtimePreserved: true
pairingAndSettingsPreserved: true
connectedAfterCacheDeletion: true
```

**Native-supervisor limitation:** supervisor activation was not verified. Native service installation reaches the existing systemd user-session/profile guards in the unprivileged container; macOS refuses native installation from an isolated HOME. The proof runs actual generated service arguments as a separate live node, not under an activated OS supervisor. Launchd XML was decoded in Linux and passed through the production generated-environment resolver; the macOS regression exercises the actual plist reader. No HOME-guard bypass, privileged container, existing Gateway, or real laptop installation was used.

**CI:** [final-head run 38097819645](https://github.com/openclaw/openclaw/actions/runs/38097819645) passed, including production types, test types, lint, source contracts, and the corrected Linux regression. All applicable PR checks finished with no failure, cancellation, or pending check. The final head is rebased onto green main; no inherited failure waiver or SDK budget change is needed. ClawSweeper is **ready, 5/6**, and the independent reviewer returned **LAND**, both on `27b447dc07b737126124ff8847f2059cb8a4f921`.

## Bounded cost

Only npx-backed node installation needs an additional npm installation. It uses one state-owned prefix and the existing updater's staging, verification, rollback, and cleanup; it does not accumulate per-version prefixes. Reuse verifies the installed package and advertised content inventory, so a same-version damaged package is repaired. Ordinary node execution and model/session paths are unchanged. Non-npx installation adds only entrypoint inspection and installation diagnostics.

Source +104/-2, tests +88/-0, docs +34/-0; net +224 across seven files. The growth reuses the existing package updater rather than adding another installation or state owner.

## Merge Danger

Two-way code change, with a durable npm installation left in the selected node state directory if reverted. A revert restores the old npx service-install behavior; it does not remove an already installed package. Blast radius is headless node service installation and its printed diagnostics; Gateway installation and pnpm launcher resolution are unchanged.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
)

## What Problem This Solves

Fixes machine enrollment silently running an old cached npm release when the Gateway is newer.

## User Impact

`devices join-code` and the Control UI now suggest the Gateway's published npm version, not the invoking CLI's version. Both also show the short alternative for an existing OpenClaw installation. The default remains a background service with explicit session-host consent; command-only services remain available.

Source checkouts and unpublished builds prefer a resolvable matching channel tag. If npm cannot confirm a target, the command stays unpinned and a one-line note asks for a matching Gateway build. JSON keeps `joinUrl` and `command`, adding `serviceCommand`, `installedCommand`, and optional `versionNote`.

## Why This Change Was Made

[openclaw#168623](openclaw#168623) / `13d3847f108` established the one-paste service/session-host default but deliberately left npm unpinned. npm can reuse an old cached package. The Gateway now owns version selection and command formatting in the same RPC that mints the URL; CLI and UI consume its commands instead of independently rebuilding them.

The existing update owners supply install identity and channel policy. Joining does not run a full update/dependency inspection. This composes with the durable service installation work in [openclaw#168644](openclaw#168644); it does not change node execution, service lifecycle, or upgrade commands.

No overlap with Pash/Sarah changes.

## Evidence

- Regressions on `13d3847f108`: eight Gateway/CLI-boundary cases and three CLI text/JSON cases fail for missing authoritative commands; the real browser regression reaches the setup RPC and fails waiting for the pinned command.
- Focused Gateway and CLI suites: 84 tests passed after the final lightweight-install-discovery refinement. The Gateway suite took 173.85s and CLI suite 43.42s on the loaded local host (including transform/setup); assertions took about 1.7s and 15.5s respectively.
- All five browser flows passed. After the final template simplification, the real bundled UI mint/refresh flow passed again (46.41s, including setup), covering the pinned command, installed alternative, and development fallback note. The Control UI Lit ratchet also passed.
- Real isolated Gateway text/JSON: baseline printed unpinned npm commands; candidate printed `[email protected]`, matching the Gateway release, plus the existing-installation alternative. Both exited successfully. This proof exercises command generation, not installation on a second machine; durable service installation is covered separately by openclaw#168644.
- The built CLI bootstrap guard passed. The local changed gate stopped at an unrelated existing mock-export violation in `src/model-picker/apply-session-model-selection-placement.test.ts`; the rebase picked up its existing `mock-isolation` explanation. Hosted exact-head CI is the final check.
- Inherited CI failure: [the final-head job](https://github.com/openclaw/openclaw/actions/runs/38096158809/job/114342554800) failed `plugin-sdk-surface-report.test.ts` on SDK export-budget drift: 3672 > 3656 exports, 2133 > 2122 callables, 158 > 154 deprecated exports, and two deprecated-entrypoint budgets. Clean `origin/main` at `39900fc906e66ff0e4bf61ef11ad531883ea979f` reproduces the same budget failures (2 failed, 3 passed, 1 Linux-only test skipped on macOS; 18.84s). The aggregate CI gate reports this failure; fail-fast cancelled the other unfinished lanes. This PR changes no plugin SDK surface or budget.

Production: +105/-17 lines; tests: +188/-27; documentation: +23/-2. The added production logic replaces independent CLI/UI formatting with one Gateway decision owner.

<details>
<summary>Real isolated Gateway terminal output (redacted)</summary>

Gateway: `OpenClaw 2026.9.9`. Both text and JSON commands exited 0. Only the ephemeral loopback port and single-use code are redacted.

Before (`devices join-code`):

```text
npx -y openclaw connect http://127.0.0.1:<port>/j/<code> --service --session-host
```

After (`devices join-code`):

```text
npx -y [email protected] connect http://127.0.0.1:<port>/j/<code> --service --session-host
Already have OpenClaw installed? Run: openclaw connect http://127.0.0.1:<port>/j/<code> --service --session-host
```

After (`devices join-code --json`):

```json
{
  "joinUrl": "http://127.0.0.1:<port>/j/<code>",
  "command": "npx -y [email protected] connect http://127.0.0.1:<port>/j/<code> --service --session-host",
  "serviceCommand": "npx -y [email protected] connect http://127.0.0.1:<port>/j/<code> --service",
  "installedCommand": "openclaw connect http://127.0.0.1:<port>/j/<code> --service --session-host"
}
```

</details>

### Connect a machine

| Before | After |
| --- | --- |
| ![Before: unpinned npm join command](https://github.com/user-attachments/assets/f9af80a8-039d-4b95-8102-1dd943a89672) | ![After: Gateway-selected npm version and installed alternative](https://github.com/user-attachments/assets/9b627f4b-5bf8-49a9-ae0b-3e222aa9652f) |

The screenshots use synthetic Gateway data and the actual bundled Control UI.

## Bounded cost

Only explicit join-code creation performs registry work: at most two npm metadata GETs, each with a one-second deadline including the response body. No background polling, model calls, package-manager subprocesses, retries, or new caches. Existing prepared install identity is reused; if absent, the update owner's lightweight local classifier runs without dependency inspection, with its Git probe bounded to one second. No registry lookup is performed by CLI or UI.

## Compatibility and Risk

The RPC fields are additive. A new CLI needs a Gateway that returns the authoritative commands and explains how to update if it connects to an older Gateway. Published npm releases use exact versions; development/unpublished/offline results are explicitly marked as requiring a matching build. Shell quoting remains owned by the existing CLI argument helper.

Two-way door: reverting changes future suggestions and added response fields only. It does not change existing pairings, service state, or session-host consent. The blast radius is enrollment instructions and their presentation.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant