openclaw - ✅(Solved) Fix Silent port fallback on invalid --port in `node run` command [3 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#83923Fetched 2026-05-20 03:46:35
View on GitHub
Comments
1
Participants
2
Timeline
11
Reactions
1
Assignees
Timeline (top)
labeled ×5cross-referenced ×3assigned ×1commented ×1

Error Message

Run openclaw node run --port abc — the host starts on port 18789 without any error or warning. Validate the port in the run action the same way runNodeDaemonInstall does: call parsePort, and if opts.port was provided but parsed as null, print an error and exit rather than falling back silently. The parsePortWithFallback helper should either be removed or renamed to parsePortWithSilentFallback to make the silent behavior explicit at each call-site. In a Vitest unit test for registerNodeCli, invoke the run action with { port: 'abc' } and assert that runNodeHost is NOT called (or is called only after an error is surfaced), mirroring the existing validation contract in runNodeDaemonInstall.

Fix Action

Fix / Workaround

Severity: medium / Confidence: high / Category: bug Triage: confirmed-bug Detected against: openclaw v2026.5.18 (latest stable at time of scan, 2026-05-18) Tooling: clawpatch 0.3.0 + acpx/claude-sonnet-4-5 via Brad Mills protocol


Standardized clawpatch finding. Persistent in v2026.5.18 (not resolved by upgrading from v2026.5.12). Finding ID: fnd_sig-feat-cli-command-264278dce9-_0ae855a8ab.

PR fix notes

PR #84029: fix(cli): validate --port in node run instead of silently falling back (#83923)

Description (problem / solution / changelog)

Fixes #83923.

node run used the local parsePortWithFallback(opts.port, fallback) helper, which silently returns the configured / default port whenever parsePort rejects the input. openclaw node run --port abc therefore started the host on 18789 with no warning. Meanwhile runNodeDaemonInstall already validates the same input via parsePort and fail(formatInvalidPortOption("--port")), and gateway run follows the same pattern. The asymmetry between run and install is exactly the kind of silently-wrong runtime address that is hardest to diagnose — especially when TLS fingerprinting or NAT targets are involved.

Changes

  • src/cli/node-cli/register.ts: drop the silent parsePortWithFallback helper. Introduce resolveNodeRunPort(rawPortOption, configPort) that mirrors the install / gateway-run validation pattern: parsePort-then-fail-fast when --port is provided but unparseable, and a (0, 65535] range check on the resolved port (config-port path) with formatInvalidConfigPort("node.gateway.port").
  • src/cli/node-cli/register.test.ts: extend the existing test scaffold with mocks for loadNodeHostConfig, runNodeHost, and defaultRuntime. Add 4 regression cases — non-numeric --port, out-of-range --port, valid --port passthrough, and config-fallback no-regression when --port is omitted.

Diff stat: 2 files, +104 / -7.

Real behavior proof

  • Behavior or issue addressed: Sanitized issue evidence — openclaw node run --port abc was returning silently on the fallback port (no diagnostic), while openclaw node install --port abc already failed cleanly. Source paths cited in the issue: register.ts:15-16 (parsePortWithFallback), register.ts:58-68 (the run-command action), daemon.ts:89-97 (the matching install validation pattern).

  • Real environment tested: Local Node 22.x. Probe at /tmp/probe_83923.mjs (a) parses the patched register.ts and verifies the silent helper is gone, the validated helper is present, it reuses parsePort, the --port-fail branch + formatInvalidPortOption("--port"), the (0, 65535] range check, and the formatInvalidConfigPort("node.gateway.port") use, and (b) replays the new resolveNodeRunPort semantics against 7 fixtures: the issue's exact --port abc repro (null + --port diagnostic + exit(1)), the out-of-range --port 99999 repro, valid --port 8123 passthrough, no---port config-fallback at 19000, no---port no-config default at 18789, invalid config port (-1) surfacing the node.gateway.port diagnostic, and the pre-fix buggy shape that silently returns 18789 for --port abc (confirms the issue's root cause).

  • Exact steps or command run after this patch: node /tmp/probe_83923.mjs

  • Evidence after fix:

PASS: silent parsePortWithFallback helper removed (no more silent fallback path)
PASS: validated resolveNodeRunPort helper added
PASS: reuses parsePort
PASS: explicit-option-but-unparseable branch fails with --port diagnostic
PASS: uses canonical formatInvalidPortOption for --port
PASS: config-port range check mirrors install path (1..65535)
PASS: config-port-range failure uses canonical node.gateway.port label
PASS: replay: --port abc → null + --port error + exit(1)
PASS: replay: --port 99999 → null + exit(1)
PASS: replay: --port 8123 → 8123 (no exit)
PASS: replay: no --port + configPort=19000 → 19000
PASS: replay: no --port no config → 18789 default
PASS: replay: invalid config port (-1) → null + exit(1) with node.gateway.port diagnostic
PASS: replay (buggy): --port abc silently returns 18789 — confirms #83923 root cause

ALL CASES PASS
  • Observed result after fix: openclaw node run --port abc and openclaw node run --port 99999 now print the same --port diagnostic format that openclaw node install --port abc already prints, and exit with code 1 before reaching runNodeHost. Valid overrides (e.g. --port 8123) pass through unchanged, and the config-port fallback path remains intact.

  • What was not tested: Live openclaw node run --port abc smoke against an actual build — that requires pnpm build. The vitest regression tests exercise the public registerNodeCli contract through Commander, mocking defaultRuntime to intercept the error+exit calls, and the source-level probe verifies the predicate end-to-end.

Audit (per CLAUDE rules — all 5 steps)

  • Existing-helper check: Reuses the existing parsePort import, the existing formatInvalidPortOption / formatInvalidConfigPort helpers from ../error-format.js, and the existing defaultRuntime runtime (same surface runNodeDaemonInstall and gateway run use). No new helper. PASS
  • Shared-helper caller check: The removed parsePortWithFallback had exactly one caller (the node run action in the same file). New resolveNodeRunPort is also called from exactly one site. PASS
  • Broader-fix rival scan: gh pr list --search '83923 in:title,body' returns no open PRs. PASS
  • Recent-merge audit: git log --oneline -5 -- src/cli/node-cli/register.ts shows e1061a8b46 test(live): tolerate provider drift in release checks — unrelated. PASS
  • Prototype-pollution scan: N/A — no external-input key copying.

Changed files

  • src/cli/node-cli/register.test.ts (modified, +89/-3)
  • src/cli/node-cli/register.ts (modified, +28/-4)

PR #84033: fix(cli): node run validates --port loudly (#83923)

Description (problem / solution / changelog)

Closes #83923.

Summary

`openclaw node run --port abc` (or `--port 0`, `--port -5`, `--port 70000`) was starting the node host on the silent fallback port (`existing.gateway.port ?? 18789`) because `parsePortWithFallback` collapsed any invalid input to the fallback with no diagnostic. `openclaw node install` already validates the same input via `runNodeDaemonInstall` in `src/cli/node-cli/daemon.ts:98` and calls `fail(formatInvalidPortOption("--port"))`.

Replaces the silent helper with `resolveNodeGatewayPortOrExit`:

  • `opts.port === undefined` → fall back to `existing.gateway.port ?? 18789` (unchanged for the no-flag case).
  • `opts.port` passed but parses to `null` (non-numeric or non-positive) OR parses above 65535 → write `formatInvalidPortOption("--port")` to stderr and `process.exit(2)`.

Aligns `node run` with the `node install` validation shape so the same CLI surface gives the same diagnostic. Range check is explicit because `parsePort → parseStrictPositiveInteger` enforces `> 0` but no upper bound; relying on it alone would let `--port 70000` through.

Real behavior proof

Behavior addressed: `openclaw node run --port abc` and out-of-range values now emit `Invalid --port. Set ...` to stderr and exit with code 2, instead of silently starting the host on the fallback port.

Real environment tested: darwin / arm64 / Node 22.21.1, openclaw source tree at HEAD of branch above.

Exact steps or command run after this patch:

``` node scripts/run-vitest.mjs src/cli/node-cli/register.test.ts ./node_modules/.bin/oxlint --type-aware src/cli/node-cli/register.ts src/cli/node-cli/register.test.ts ```

Evidence after fix:

``` $ node scripts/run-vitest.mjs src/cli/node-cli/register.test.ts RUN v4.1.6 /Users/harshkumarkaithwas/Desktop/openclaw

✓ registerNodeCli > registers node start for the macOS app node service manager ✓ openclaw node run --port validation (#83923) > rejects --port abc with a loud diagnostic and does not start the host ✓ openclaw node run --port validation (#83923) > rejects --port 0 (out of range) without starting the host ✓ openclaw node run --port validation (#83923) > rejects --port 70000 (out of range) without starting the host ✓ openclaw node run --port validation (#83923) > falls back to config / default gateway port when --port is absent ✓ openclaw node run --port validation (#83923) > uses the parsed --port value when valid

Test Files 1 passed (1) Tests 6 passed (6)

$ ./node_modules/.bin/oxlint --type-aware src/cli/node-cli/register.ts src/cli/node-cli/register.test.ts Found 0 warnings and 0 errors. ```

Observed result after fix: `runNodeHost` is never invoked for invalid `--port` values; the user sees a stderr line matching `Invalid --port. ...` and the process exits 2. Valid ports (`31337`) still drive `runNodeHost` with the parsed value, and the no-flag case still falls back to config / 18789.

What was not tested: a true E2E spawn of the `openclaw` binary against a port-bound check — covered transitively by the parallel `runNodeDaemonInstall` validation that already lives on main.

Notes

  • Same diagnostic format as `runNodeDaemonInstall` (reuses `formatInvalidPortOption` from `src/cli/error-format.ts`).
  • `parsePortWithFallback` removed because `run` was its only caller; if a future call site needs the silent-fallback shape, name it `parsePortWithSilentFallback` so the silent semantics are explicit, as the issue suggested.
  • Local lint+format wrappers (`node scripts/run-oxlint.mjs`, `pnpm format`) hit a pre-existing dts boundary failure on `@openclaw/proxyline` (`ProxylineUndiciOptions` / `ifActive`) unrelated to this PR; ran `./node_modules/.bin/oxlint --type-aware` and `./node_modules/.bin/oxfmt --write` directly on the touched files.

Changed files

  • src/cli/node-cli/register.test.ts (modified, +93/-3)
  • src/cli/node-cli/register.ts (modified, +18/-3)

PR #84307: fix(cli): reject invalid node run port

Description (problem / solution / changelog)

Summary

  • Reject explicit invalid openclaw node run --port values instead of falling back to the configured or default port.
  • Add focused node CLI registration coverage for invalid, valid, and omitted --port values.
  • Add the user-visible fix to the changelog.

Fixes #83923.

Verification

  • git diff --check HEAD~1..HEAD -- CHANGELOG.md src/cli/node-cli/register.ts src/cli/node-cli/register.test.ts
  • Crabbox AWS cbx_b19076fdaf79, run run_26642c3eee98: regression failed before the source patch, then node scripts/run-vitest.mjs src/cli/node-cli/register.test.ts -- --reporter=verbose passed after the patch (4/4).

Behavior addressed: openclaw node run --port abc now reports Invalid --port and exits before starting the node host. Real environment tested: AWS Crabbox Linux lease cbx_b19076fdaf79, run run_26642c3eee98, using a clean remote clone. Exact steps or command run after this patch: node scripts/run-vitest.mjs src/cli/node-cli/register.test.ts -- --reporter=verbose Evidence after fix: focused Vitest passed with 4 passed; scoped git diff --check passed. Observed result after fix: invalid explicit --port no longer calls runNodeHost; valid explicit and omitted ports still dispatch with the expected gateway port. What was not tested: no foreground node host process was started; the behavior is covered through the CLI registration path and runNodeHost dispatch mock.

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/cli/node-cli/register.test.ts (modified, +62/-3)
  • src/cli/node-cli/register.ts (modified, +13/-4)

Code Example

function parsePortWithFallback(value: unknown, fallback: number): number {
  const parsed = parsePort(value);
  return parsed ?? fallback;
}

---

const port = parsePortWithFallback(opts.port, existing?.gateway?.port ?? 18789);
      await runNodeHost({
        gatewayHost: host,
        gatewayPort: port,

---

if (!Number.isFinite(port ?? Number.NaN) || (port ?? 0) <= 0 || (port ?? 0) > 65_535) {
    fail(
      opts.port !== undefined
        ? formatInvalidPortOption("--port")
        : formatInvalidConfigPort("node.gateway.port"),
    );
    return;
  }
RAW_BUFFERClick to expand / collapse

Severity: medium / Confidence: high / Category: bug Triage: confirmed-bug Detected against: openclaw v2026.5.18 (latest stable at time of scan, 2026-05-18) Tooling: clawpatch 0.3.0 + acpx/claude-sonnet-4-5 via Brad Mills protocol

Evidence

  • src/cli/node-cli/register.ts:15-16 (parsePortWithFallback)
function parsePortWithFallback(value: unknown, fallback: number): number {
  const parsed = parsePort(value);
  return parsed ?? fallback;
}
  • src/cli/node-cli/register.ts:58-68 (None)
const port = parsePortWithFallback(opts.port, existing?.gateway?.port ?? 18789);
      await runNodeHost({
        gatewayHost: host,
        gatewayPort: port,
  • src/cli/node-cli/daemon.ts:89-97 (runNodeDaemonInstall)
if (!Number.isFinite(port ?? Number.NaN) || (port ?? 0) <= 0 || (port ?? 0) > 65_535) {
    fail(
      opts.port !== undefined
        ? formatInvalidPortOption("--port")
        : formatInvalidConfigPort("node.gateway.port"),
    );
    return;
  }

Reasoning

The run subcommand uses parsePortWithFallback, which silently returns the fallback value (config port or 18789) when the supplied --port value is non-numeric or out of range. This means openclaw node run --port abc starts the node host on the fallback port with no diagnostic. The install subcommand validates the same value and calls fail with formatInvalidPortOption. A user who mis-types a port for run will get a silently wrong runtime address, which is hard to diagnose — especially when TLS fingerprinting or a NAT target is involved.

Reproduction

Run openclaw node run --port abc — the host starts on port 18789 without any error or warning.

Recommendation

Validate the port in the run action the same way runNodeDaemonInstall does: call parsePort, and if opts.port was provided but parsed as null, print an error and exit rather than falling back silently. The parsePortWithFallback helper should either be removed or renamed to parsePortWithSilentFallback to make the silent behavior explicit at each call-site.

Why existing tests miss this

No tests exist for this feature (the feature definition lists an empty tests array), so this path has never been exercised in a test environment.

Suggested regression test

In a Vitest unit test for registerNodeCli, invoke the run action with { port: 'abc' } and assert that runNodeHost is NOT called (or is called only after an error is surfaced), mirroring the existing validation contract in runNodeDaemonInstall.

Minimum fix scope

Add port validation to the run action handler in src/cli/node-cli/register.ts, matching the pattern in runNodeDaemonInstall.


Standardized clawpatch finding. Persistent in v2026.5.18 (not resolved by upgrading from v2026.5.12). Finding ID: fnd_sig-feat-cli-command-264278dce9-_0ae855a8ab.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Silent port fallback on invalid --port in `node run` command [3 pull requests, 1 comments, 2 participants]