Skip to content

fix(gateway): accept --port on gateway health and probe (#79100) - #89555

Closed
Alix-007 wants to merge 1 commit into
openclaw:mainfrom
Alix-007:issue-79100-gateway-port
Closed

Alix-007 wants to merge 1 commit into
openclaw:mainfrom
Alix-007:issue-79100-gateway-port

Conversation

@Alix-007

@Alix-007 Alix-007 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

gateway run --port 18789 accepts --port, but the adjacent query subcommands rejected the same flag:

  • openclaw gateway health --port 18789 → error: unknown option '--port'
  • openclaw gateway probe --port 18789 → error: unknown option '--port'

So scripts that start a gateway on a controlled local port could not target it through health/probe with the same visible flag shape as run, and the --url workaround disables config credential fallback (forcing explicit --token/--password).

Fix

Route the existing parent gateway --port flag through to the query commands by patching config.gateway.port — not by synthesizing a ws:// URL — so configured local auth and the TLS scheme (ws:// vs wss://) are preserved:

  • resolveGatewayRpcOptions now inherits the parent --port (covers health, call, usage-cost, stability via callGatewayCli).
  • callGatewayCli loads the real config and overrides only gateway.port, so configured credentials still apply (no forced --token/--password).
  • gateway probe gains its own --port and passes a numeric port to gatewayStatusCommand, which patches config.gateway.port before resolveTargets derives the scheme.
  • Invalid ports are rejected via the shared strict parsePort.

Usage: openclaw gateway --port 18789 health (port before the subcommand, the same place the parent --port already lives for gateway run).

Fixes #79100

Real behavior proof

Behavior addressed: gateway health and gateway probe rejected the --port that gateway run accepts; they now honor the parent gateway --port <N> flag by patching config.gateway.port (preserving local auth/TLS) instead of erroring or ignoring it.

Real environment tested: vitest (src/cli/gateway-cli.coverage.test.ts) driving the real registerGatewayCli Commander program through runGatewayCommand([...]) argv parsing, with callGateway and gatewayStatusCommand mocked at the RPC boundary to capture the resolved options.

Exact steps or command run after this patch: node scripts/run-vitest.mjs src/cli/gateway-cli.coverage.test.ts

Evidence after fix: Test Files 1 passed (1) / Tests 21 passed (21), including the two new #79100 cases. Reverting only the three source edits (keeping the tests) flips exactly those two cases to failing (Tests 2 failed | 19 passed), proving the tests bind the fix.

Observed result after fix: gateway --port 18799 health calls callGateway once with config.gateway.port === 18799 and url === undefined (the port is patched onto config, not turned into a url override). gateway --port 18799 probe calls gatewayStatusCommand once with a numeric port === 18799 and no string url, so resolveTargets derives ws:// vs wss:// from the loaded config's TLS settings rather than a hard-coded plaintext URL.

What was not tested: A live gateway socket round-trip on a real non-default port — the change is in CLI option resolution and config patching, verified by driving the real Commander program and asserting the resolved RPC/probe options; the downstream connect path is unchanged and already covered elsewhere.

🤖 Generated with Claude Code

`gateway run --port` accepts a port, but the adjacent query subcommands
`gateway health` and `gateway probe` rejected the same flag, so scripts
targeting a non-default local port had to hand-build a WebSocket URL (and
then also pass --token/--password, since --url disables config credential
fallback).

Route the existing parent `gateway --port` flag through to the query
commands by patching `config.gateway.port` rather than synthesizing a
ws:// URL, so configured local auth and the TLS scheme (ws:// vs wss://)
are preserved:
- resolveGatewayRpcOptions inherits the parent --port (covers health,
  call, usage-cost, stability via callGatewayCli)
- callGatewayCli loads the real config and overrides only gateway.port
- gateway probe gains its own --port and passes a numeric port to
  gatewayStatusCommand, which patches config.gateway.port before
  resolveTargets derives the scheme
Invalid ports are rejected via the shared strict parsePort.

Fixes openclaw#79100

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes commands Command implementations size: S r: too-many-prs Auto-close: author has more than twenty active PRs. triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 2, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing this PR because the author has more than 20 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit.

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 r: too-many-prs Auto-close: author has more than twenty active PRs. size: S triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gateway health/probe reject --port while gateway run accepts it

1 participant