Skip to content

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

Closed
Alix-007 wants to merge 5 commits into
openclaw:mainfrom
Alix-007:issue-79100-gateway-port
Closed

Alix-007 wants to merge 5 commits 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

Accept --port on the gateway query commands in both spellings: before the subcommand (gateway --port 18789 health, inherited from the parent) and after it (gateway health --port 18789, the exact spelling the issue reports).

  • gatewayCallOpts accepts --port, so health, call, usage-cost, and stability accept the flag after the subcommand.
  • resolveGatewayRpcOptions still inherits the parent --port for the before-subcommand spelling.
  • callGatewayCli loads the real config and overrides only gateway.port, then marks that explicit CLI port as preferred so OPENCLAW_GATEWAY_PORT cannot silently retarget the request.
  • gateway probe passes a numeric port to gatewayStatusCommand; target/network-hint resolution ignores OPENCLAW_GATEWAY_PORT only for that explicit-port path, while preserving the normal env-over-config behavior when --port is omitted.
  • Config-based auth and TLS scheme selection are still preserved; the implementation does not turn the port into a synthetic ws:// URL.

Fixes #79100

Real behavior proof

Behavior addressed: openclaw gateway health --port <N> and openclaw gateway probe --port <N> should accept the subcommand-position port flag and connect to a real gateway on that non-default local port. When OPENCLAW_GATEWAY_PORT is also set to a different port, the explicit CLI --port must win.

Real environment tested: Local Linux source checkout on commit 09ae914c7c, using an isolated temporary OpenClaw home/config under /media/vdc/0668001470/workSpace/claw-campaign/.proof-89623/env-port-precedence-dist-1780485149, a real gateway run process listening on loopback port 19323, and the built node dist/entry.js CLI entry for the client commands. The temporary config was gateway.mode=local, gateway.bind=loopback, and gateway.auth.mode=none; OPENCLAW_SKIP_CHANNELS=1/OPENCLAW_SKIP_PROVIDERS=1 only skipped external channel sidecars.

Exact steps or command run after this patch:

PROOF_ROOT=/media/vdc/0668001470/workSpace/claw-campaign/.proof-89623/env-port-precedence-dist-1780485149
export HOME="$PROOF_ROOT/home"
export OPENCLAW_HOME="$PROOF_ROOT/home"
export OPENCLAW_STATE_DIR="$PROOF_ROOT/home/.openclaw"
export OPENCLAW_CONFIG_PATH="$OPENCLAW_STATE_DIR/openclaw.json"
export OPENCLAW_SKIP_CHANNELS=1
export OPENCLAW_SKIP_PROVIDERS=1
export OPENCLAW_TEST_FAST=1

node dist/entry.js gateway run --dev --reset --port 19323 --bind loopback --auth none --allow-unconfigured --ws-log compact
# After the gateway logged `ready`, set gateway.auth.mode=none in the isolated config so the CLI preserves matching local auth config.
export OPENCLAW_GATEWAY_PORT=19001
node dist/entry.js gateway health --port 19323 --json --timeout 15000
node dist/entry.js gateway probe --port 19323 --json --timeout 8000

git diff --check
node scripts/run-vitest.mjs src/cli/gateway-cli.coverage.test.ts
node scripts/run-vitest.mjs src/gateway/call.test.ts
node scripts/run-vitest.mjs src/commands/gateway-status.test.ts src/commands/gateway-status/helpers.test.ts

Evidence after fix:

Gateway startup reached the real listener on port 19323:

[gateway] http server listening (8 plugins: acpx, browser, canvas, device-pair, file-transfer, memory-core, phone-control, talk-voice; 8.3s)
[gateway] ready

With OPENCLAW_GATEWAY_PORT=19001, the subcommand-position health command still returned a real gateway health payload for the explicit --port 19323 target:

$ OPENCLAW_GATEWAY_PORT=19001 node dist/entry.js gateway health --port 19323 --json --timeout 15000
{
  "ok": true,
  "defaultAgentId": "dev",
  "agents": [
    {
      "agentId": "dev",
      "isDefault": true
    }
  ]
}

With the same conflicting environment variable, the probe command targeted 19323, not 19001:

$ OPENCLAW_GATEWAY_PORT=19001 node dist/entry.js gateway probe --port 19323 --json --timeout 8000
{
  "ok": true,
  "degraded": true,
  "primaryTargetId": "localLoopback",
  "network": {
    "localLoopbackUrl": "ws://127.0.0.1:19323",
    "localTailnetUrl": "ws://100.93.92.6:19323"
  },
  "targets": [
    {
      "id": "localLoopback",
      "url": "ws://127.0.0.1:19323",
      "connect": {
        "ok": true,
        "latencyMs": 89,
        "error": "timeout"
      },
      "auth": {
        "role": "operator",
        "capability": "read_only"
      }
    }
  ]
}

The probe was marked degraded because one follow-up read diagnostic timed out under an 8s probe timeout, but the connection and target-selection evidence is the behavior under test: both network.localLoopbackUrl and the target URL are ws://127.0.0.1:19323 while OPENCLAW_GATEWAY_PORT=19001 was set.

Focused tests also cover the env-precedence regression:

$ git diff --check
# no output

$ node scripts/run-vitest.mjs src/cli/gateway-cli.coverage.test.ts
Test Files  1 passed (1)
Tests  25 passed (25)

$ node scripts/run-vitest.mjs src/gateway/call.test.ts
Test Files  1 passed (1)
Tests  94 passed (94)

$ node scripts/run-vitest.mjs src/commands/gateway-status.test.ts src/commands/gateway-status/helpers.test.ts
Test Files  2 passed (2)
Tests  41 passed (41)

Observed result after fix: Both gateway health --port 19323 and gateway probe --port 19323 accepted the port after the subcommand. In a conflicting environment with OPENCLAW_GATEWAY_PORT=19001, health returned ok: true and probe reported network.localLoopbackUrl plus the local target URL as ws://127.0.0.1:19323, proving the explicit CLI port wins for both RPC calls and probe/status target resolution.

What was not tested: TLS (wss://) and token/password auth variants were not live-tested in this proof; focused tests cover that the implementation preserves config-based auth/TLS selection by patching config.gateway.port instead of forcing a --url override. The normal env-over-config behavior when --port is omitted remains covered by existing config/daemon tests and the new buildGatewayConnectionDetails regression test.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes commands Command implementations size: S triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 2, 2026
@clawsweeper

clawsweeper Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 12, 2026, 5:42 AM ET / 09:42 UTC.

Summary
Review failed before ClawSweeper could summarize the requested change.

PR surface: Source +84, Tests +154, Docs +4. Total +242 across 9 files.

Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

Review metrics: none identified.

Merge readiness
Overall: 🌊 off-meta tidepool
Proof: 🌊 off-meta tidepool
Patch quality: 🌊 off-meta tidepool
Result: rating does not apply to this item.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] No close action taken because the review did not complete.

Maintainer options:

  1. Decide the mitigation before merge
    Retry the Codex review after fixing the execution failure.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Review did not complete, so no work-lane recommendation was made.
Review details

Best possible solution:

Retry the Codex review after fixing the execution failure.

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

Unclear. The review failed before ClawSweeper could establish a reproduction path.

Is this the best way to solve the issue?

Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

AGENTS.md: unclear because the file could not be read completely.

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

Label changes

Label changes:

  • add rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
  • remove proof: sufficient: Current real behavior proof status is not_applicable, not sufficient.
  • remove P2: Current review triage priority is none.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🌊 off-meta tidepool, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.
  • remove status: 👀 ready for maintainer look: Current PR status no longer selects a status label.

Label justifications:

  • rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
Evidence reviewed

PR surface:

Source +84, Tests +154, Docs +4. Total +242 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 5 96 12 +84
Tests 3 156 2 +154
Docs 1 6 2 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 258 16 +242

What I checked:

  • failure reason: retryable codex transport failure (capacity)
  • codex failure detail: Codex review failed for this PR with exit 1.
  • codex stderr: current head SHA;.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@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. labels Jun 2, 2026
@Alix-007
Alix-007 force-pushed the issue-79100-gateway-port branch from a8e6bec to ddc12ac Compare June 2, 2026 22:49
@Alix-007

Alix-007 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — addressed all three review points:

  1. health --port gap (the main P1): added --port to the shared gatewayCallOpts, so gateway health --port <N> (the exact after-subcommand spelling the issue reports) now works, alongside the parent-position gateway --port <N> health. Same for call/usage-cost/stability. Coverage now has 4 gateway health/probe reject --port while gateway run accepts it #79100 cases (health/probe × both spellings).
  2. Dropped the direct CHANGELOG.md edit.
  3. Proof: the vitest suite drives the real registerGatewayCli Commander program through real argv parsing (the option-resolution path this PR actually changes), asserting the port lands as config.gateway.port (not a url override) for all four invocations. A full openclaw CLI round-trip needs a monorepo pnpm build (the source tree ships no dist/, and a build wasn't available here); the socket layer below option resolution is unchanged, and a maintainer can confirm end-to-end locally with gateway run --port N --dev --auth none + gateway health --port N.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 2, 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:

@Alix-007

Alix-007 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

I pushed commit 39fc9902f1 to add the missing registered --port option for gateway health, then updated the PR body with a live non-default-port proof:

  • real openclaw gateway run on loopback port 19323
  • node openclaw.mjs gateway health --port 19323 --json returned ok: true
  • node openclaw.mjs gateway probe --port 19323 --json returned ok: true, connectOk: true, rpcOk: true, and localLoopbackUrl: ws://127.0.0.1:19323
  • focused test still passes: node scripts/run-vitest.mjs src/cli/gateway-cli.coverage.test.ts -> 23 passed

@clawsweeper

clawsweeper Bot commented Jun 3, 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:

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 3, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed 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. labels Jun 3, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M and removed size: S labels Jun 3, 2026
@Alix-007

Alix-007 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

I pushed commit 09ae914c7c to address the env-precedence review finding:

  • gateway health --port <N> now passes preferConfigGatewayPort so the explicit CLI port beats OPENCLAW_GATEWAY_PORT during connection detail resolution.
  • gateway probe --port <N> now uses an explicit-port resolver for targets, network hints, and remotePort so OPENCLAW_GATEWAY_PORT cannot retarget the probe.
  • Added focused regression coverage with OPENCLAW_GATEWAY_PORT=19001 and explicit --port 18799.
  • Updated the PR body with live proof using a real gateway on 19323 while OPENCLAW_GATEWAY_PORT=19001; health returned ok: true, and probe reported network.localLoopbackUrl plus the local target URL as ws://127.0.0.1:19323.

Validation:

git diff --check
node scripts/run-vitest.mjs src/cli/gateway-cli.coverage.test.ts  # 25 passed
node scripts/run-vitest.mjs src/gateway/call.test.ts              # 94 passed
node scripts/run-vitest.mjs src/commands/gateway-status.test.ts src/commands/gateway-status/helpers.test.ts  # 41 passed

@clawsweeper

clawsweeper Bot commented Jun 3, 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:

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 3, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 3, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 3, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
Alix-007 and others added 5 commits June 12, 2026 15:34
`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).

Accept `--port` on the gateway query commands in both spellings — before
the subcommand (`gateway --port 18789 health`, inherited from the parent)
and after it (`gateway health --port 18789`, the spelling the issue
reports) — by patching `config.gateway.port` rather than synthesizing a
ws:// URL, so configured local auth and the TLS scheme (ws:// vs wss://)
are preserved:
- gatewayCallOpts gains a --port option (covers health, call, usage-cost,
  stability) and resolveGatewayRpcOptions still inherits the parent --port
- 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]>
@Alix-007
Alix-007 force-pushed the issue-79100-gateway-port branch from 6a8196b to 93e0ead Compare June 12, 2026 07:44
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 12, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Jun 12, 2026
@Alix-007

Copy link
Copy Markdown
Contributor Author

Closing to keep my queue focused — this one was flagged off-meta + compatibility-risk and hasn't drawn maintainer interest. Happy to revisit if the gateway --port surface becomes relevant later. Thanks!

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 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: 🌊 off-meta tidepool PR readiness rating does not apply to this item. size: M

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