Skip to content

fix(gateway): blank --url silently reports the default gateway status - #193697

Closed
wangmiao0668000666 wants to merge 1 commit into
openclaw:mainfrom
wangmiao0668000666:fix/gateway-status-blank-url
Closed

wangmiao0668000666 wants to merge 1 commit into
openclaw:mainfrom
wangmiao0668000666:fix/gateway-status-blank-url

Conversation

@wangmiao0668000666

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw gateway status --url "" (or --url "$VAR" where the variable is empty) exits 0 and prints the configured default Gateway's service/connectivity report instead of rejecting the blank target. The same command with a non-empty --url ws://… probes exactly that URL, so an explicitly passed empty value is silently treated as "flag not provided" while any other value is honored.

openclaw gateway probe --url "" has the same silent drop: it prints the full Gateway Status report for the configured local/remote targets (byte-identical to running gateway probe with no --url at all).

Root cause: two independent drop points turn "" into "absent" before any target is resolved.

  • src/commands/gateway-status.ts (gatewayStatusCommand, the engine behind gateway probe): ensureExplicitGatewayAuth({ urlOverride: opts.url?.trim() }) early-returns on an empty override, resolveTargets() maps "" → normalizeWsUrl → null (no explicit target), and hasExplicitUrl reads opts.url.trim().length > 0 → false.
  • src/cli/daemon-cli/status.ts (runDaemonStatus, behind gateway status): opts.rpc.url is passed straight through and status.gather.ts treats a falsy override as "use the configured target" (if (opts.deep && !trimToUndefined(opts.rpc.url))).

User Impact

User impact: scripts and operators that pass an empty --url (typically --url "$GATEWAY_URL" with an unset variable) now get a clear error and exit 1 instead of a successful report about a different Gateway than the one they asked about — before any probe, SSH tunnel, Bonjour discovery, or service inspection starts. Blank values fail at command entry, so no partial output is produced.

Why This Change Was Made

Adds a 3-line blank check at the top of gatewayStatusCommand and a 4-line blank check at the top of runDaemonStatus, reusing the repository's existing must not be blank contract (the same wording and shape as agentCliCommand in src/commands/agent-via-gateway.ts, account-selector.ts, channel-selector.ts, and the merged --agent must not be blank guard from #193336). Each check sits at the entry of the command that owns the --url option, before any of its consumers run.

Not introducing: no new error type, no config validation, no shared resolver change, no owner/state/schema/API change, no SDK-visible surface. resolveGatewayRpcOptions / addGatewayClientOptions (shared by gateway call, health, stability, diagnostics export, exec-policy, …) are deliberately untouched — that is a wider family with its own blast radius and is recorded as a follow-up rather than folded into this fix.

Evidence

Base 37706a74a81129f8ec85289399a2703abf98c2b4 (branch base = origin/main at branch creation) → Candidate 166efe4ed6ad68a3dceeee079eececc8dbfd564f (branch fix/gateway-status-blank-url).

Environment: Linux x64, Node v24.22.1, normally built openclaw.mjs (OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build:docker), isolated OPENCLAW_HOME + OPENCLAW_STATE_DIR (+ isolated HOME), no Gateway running, no network dependency, no seed data. Every case below was run twice; each pair was compared with cmp (exit code + stdout + stderr), not by eye.

Shipped CLI (each leg run at least twice)

case base candidate
gateway status --url "" ×2 exit 0, stdout+stderr byte-identical to gateway status with no flag (md5 358f247acd194509801e9873eed89e45 / f8cb63b30f259108654742cce8c82c30) — blank silently dropped exit 1, stderr Gateway status failed: --url must not be blank
gateway status (no --url) ×2 exit 0 exit 0, byte-identical to base
gateway status --url "ws://127.0.0.1:9" ×2 exit 0, Check target: ws://127.0.0.1:9 (explicit target honored) exit 0, byte-identical to base
gateway probe --url "" ×2 exit 1, stdout+stderr byte-identical to gateway probe with no flag (stdout md5 f930c0cfd768d2f066ce142512e2e10d, stderr empty d41d8cd98f00b204e9800998ecf8427e) — blank silently dropped exit 1, stderr --url must not be blank
gateway probe (no --url) ×2 exit 1 (Gateway Status / Reachable: no) exit 1, byte-identical to base
gateway probe --url "ws://127.0.0.1:9" ×2 exit 1, explicit target probed exit 1, byte-identical to base

All eight "unchanged" comparisons were byte-identical (cmp clean on both streams) between the base build and the candidate build in the same isolated home/state directory.

Regression RED → GREEN (remote, real vitest)

Remote proof host (Docker lexiflow-all:latest, Node v24.22.1, OPENCLAW_VITEST_RUNTIME=node), production files at 37706a74a81 bytes (verified md5-identical to git show origin/main:<path> for all four files before the run):

sh node_modules/.bin/vitest run --config test/vitest/vitest.commands.config.ts \
  src/commands/gateway-status.test.ts --maxWorkers=1
sh node_modules/.bin/vitest run --config test/vitest/vitest.cli.config.ts \
  src/cli/daemon-cli/status.test.ts --maxWorkers=1
  • base production + new test → RED. commands shard: 1 failed | 30 passed (31) — rejects a blank --url before reading config or probing fails with AssertionError: promise resolved "undefined" instead of rejecting at src/commands/gateway-status.test.ts:234 (the blank value silently proceeded past the guard). cli shard: 1 failed | 7 passed (8) — rejects a blank --url before gathering status fails with the same promise resolved "undefined" instead of rejecting at src/cli/daemon-cli/status.test.ts:140.
  • candidate production + the same tests → GREEN. commands shard: 31 passed (31); cli shard: 8 passed (8) (the new rejects a blank --url before gathering status case is green).
  • Siblings/consumers on the candidate (all green): src/cli/gateway-cli.coverage.test.ts, src/cli/gateway-cli/register.option-collisions.test.ts, src/cli/daemon-cli/register-service-commands.test.ts, src/cli/daemon-cli/status.install-hints.test.ts, src/cli/daemon-cli/status.gather.test.ts, src/cli/daemon-cli/status.print.test.ts → 6 passed (6) files, 156 passed | 2 skipped (158); src/commands/gateway-status/helpers.test.ts (root matrix) → 1 passed (1) file, 18 passed (18).

Local gates

oxlint (v1.88.0) src/commands/gateway-status.ts src/commands/gateway-status.test.ts src/cli/daemon-cli/status.ts src/cli/daemon-cli/status.test.ts → 0 findings, exit 0
node scripts/run-format.mts --check <those four files> → All matched files use the correct format
node scripts/check-test-lines-ratchet.mts --base 37706a74a81 → Test lines OK (allocation credit equals this PR's +18 delta)
git diff --check → clean

Line counts

Whole-PR delta: production +7/-0 (2 files), tests +18/-0 (2 files), config/test-lines-allocations/gateway-status-blank-url.txt = 18 for exactly this PR's net test growth. Shared scalar config/test-lines-baseline.txt untouched. On a clean 37706a74a81 the ratchet reports Test lines OK: 6496704; ceiling: 6496746; slack: 42, so this branch stays inside the ceiling with the allocation applied.

Negative claims

  • Not claimed: gateway status/gateway probe against a running Gateway — both legs run with no listener, and the proof is exit code + byte-identical output identity, not live capability data.
  • Not claimed: the shared --url consumers (gateway call, health, stability, diagnostics export, exec-policy, …). They share the shape but are a wider family; fixing them belongs to a separate, explicitly scoped change.
  • Not claimed: whitespace-only --url " " at the CLI (covered by the same .trim() expression; the shipped CLI leg exercises "", and the unit test exercises both "" and " " for gateway probe).

Focused Checks and Simplification

  • 7 production lines across 2 production files; each guard is a straight-line if at the existing command entry, no helper, no wrapper, no new export, no new error class.
  • Tests were merged into the two files that already own these commands (gateway-status.test.ts, status.test.ts), reusing their existing mock-not-called assertions so no new harness was introduced.
  • Test-lines: this PR adds an allocation of exactly its +18 growth and leaves the shared scalar alone.

Compatibility and Merge Risk

Two-way door: reverting restores the previous silent fallback without migrations or persisted state changes. Blast radius is --url validation at exactly two command entries (gateway status, gateway probe); both fail before config reads, probes, SSH tunnels, Bonjour discovery, and service inspection. Unchanged adjacent behavior: omitted --url, non-empty valid URLs, non-empty invalid URLs (still probed and reported as before), --token/--password/--port/--ssh handling, --json output shape for every non-blank case, and every other command.

Collision check (run against origin/main minutes before opening): no open PR modifies src/commands/gateway-status.ts, src/commands/gateway-status.test.ts, src/cli/daemon-cli/status.ts, or src/cli/daemon-cli/status.test.ts; gh pr list --search "gateway status" / "blank url" and per-file gh api pulls/<n>/files checks returned only unrelated work (the one parallel-lane PR touching remote URLs, #193538, edits src/commands/onboard-remote.ts only).

@clawsweeper

clawsweeper Bot commented Nov 5, 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.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes commands Command implementations size: XS labels Nov 5, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Reject explicitly empty or whitespace-only --url values before gateway status or probe diagnostics begin.

Example: Run openclaw gateway status --url "".

  • Before: The command reports the configured Gateway's status and exits 0.
  • After: The command reports “Gateway status failed: --url must not be blank” and exits 1.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A useful, minimal boundary fix with shipped-CLI evidence, reported red/green regressions, and no actionable correctness or security findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied built openclaw.mjs results exercise both changed command owners on isolated Linux with Node 24.22.1, demonstrating blank-input rejection and unchanged omitted/nonblank cases; the later prefix-only adjustment has a reported focused retest.
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 explicitly blank URL silently selects configured Gateway diagnostics, potentially misleading operators and scripts.
Reason: Rejecting malformed explicit input restores target intent using existing command and error owners, without adding settings or changing valid URL behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still silently discards blank URL targets, and this PR provides a focused fix with no actionable findings. Current-head CI remains pending.

Priority: P2
Reviewed head: 17f4158e758acd269498aa85869321441ccb5f92

Before merge

None.

Findings

None.

Agent review details

How this fits together

Commander passes URL options to the status and probe command owners, which select Gateway targets and render human-readable or JSON diagnostics.

flowchart TD
  A[CLI URL option] --> B[Status command]
  A --> C[Probe command]
  B --> D[Blank input rejection]
  C --> D
  B --> E[Service diagnostics]
  C --> F[Gateway target probes]
Loading

Technical review

Best possible solution:

Land the two command-entry checks once the existing current-head CI gate passes.

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

Yes: current-main source traces blank input into default-target selection, and the contributor supplies matching built-CLI before/after results; no target code was executed during this review.

Is this the best way to solve the issue?

The defect is lost explicit-target intent; the invariant is that a supplied blank URL cannot select defaults, and the smallest complete fix is rejection at these two existing command owners.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Gateway target selection and explicit-URL authentication keeps the original intent (5b50c97: The original status implementation assembled explicit, configured remote, and local targets; the later merged explicit-auth repair prevents ambient credentials reaching overridden URLs.)
  • Daemon status failure rendering keeps the original intent (433bb3f: The merged CLI reliability repair established canonical command validation and machine-readable failures; this check reuses that renderer.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 433bb3f adds src/cli/daemon-cli/status.ts:8 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 433bb3f954ed; files: src/cli/daemon-cli/status.ts)
  • Ayaan Zaidi: Raw commit fca1c6e adds src/commands/gateway-status.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: fca1c6ec13f4; files: src/commands/gateway-status.ts)

PR surface

Source +7, Tests +18, Other +2. Total +27 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 7 0 +7
Tests 2 18 0 +18
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 5 27 0 +27

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus regression growth Production +7/-0; tests +18/-0 Two existing command boundaries need separate rejection behavior, covered within their existing suites without new scaffolding.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Blank shell-expanded URL values can produce misleading diagnostics about another Gateway, with limited impact on operator scripts.
  • 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 execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-05T19:33:26.226Z sha 166efe4ed6ad68a3dceeee079eececc8dbfd564f :: needs maintainer review before merge. :: none

Reviewed November 9, 2026, 7:25 AM ET / 12:25 UTC (Revision 2).

@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/gateway-status-blank-url branch from 166efe4 to d2f9e88 Compare November 6, 2026 07:57

@yxshee yxshee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review draft: #193697 (fix(gateway): reject a blank --url instead of probing the default Gateway)

Post as a PR review (Comment, not Approve/Request changes; contributor review). Static review: the auto-mode classifier blocked running this branch locally, so these notes come from the diff, the surrounding code on main (826999c), and the shipped behaviour of gatewayAction / runDaemonStatus.


Read through both drop points against main and the fix lands at the right layer: runDaemonStatus is the only engine behind gateway status, and gatewayStatusCommand the only one behind gateway probe, so a check at each entry covers every route in before ensureExplicitGatewayAuth, resolveTargets or gatherDaemonStatus can turn "" into "absent".

Checked how the two errors surface, since they use different shapes:

  • gateway status --url "" goes through failDaemonStatus, so human output is Gateway status failed: --url must not be blank and --json is the canonical { ok: false, error: { type: "cli_error", … } } document. Matches the new status.test.ts case.
  • gateway probe --url "" throws a plain Error. That is fine here because gatewayAction (src/cli/gateway-cli/gateway-action.ts) prints formatErrorMessage(err) for non-expected errors in human mode and formatCliJsonFailure(err) in JSON mode, so the operator still sees --url must not be blank rather than the generic "The CLI command failed." line. Worth one sentence in the body, since most thrown plain errors elsewhere in the CLI do end up generic.

Two small things, neither blocking:

  1. The two messages differ (Gateway status failed: --url must not be blank vs --url must not be blank). gateway probe has no label in its gatewayAction, so a Gateway probe failed: prefix would need to come from the thrown message itself; consistent wording across the two commands would make the error easier to grep for in scripts.
  2. opts.url !== undefined && !opts.url.trim() also catches --url " ", which the gateway-status.test.ts case covers; the status.test.ts case only covers "". Not needed for coverage, just noting the asymmetry.

The test-line allocation is annotated and the four new assertions are the right ones (no readBestEffortConfig, no probeGateway, no gatherDaemonStatus call before the rejection). LGTM from my side.

@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/gateway-status-blank-url branch from d2f9e88 to 17f4158 Compare November 9, 2026 12:18
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review, @yxshee — both notes were accurate and I've acted on the wording one.

Updated gatewayStatusCommand to throw Gateway probe failed: --url must not be blank, so both commands now share the … must not be blank suffix and scripts can grep for it consistently. The probe test's "" assertion was updated to match; verified red on the old message and green on the new one (real vitest run in the container, 2 files / 38 tests pass).

On the whitespace asymmetry note: gateway probe already covers " " (and ""), while gateway status covers "" — both go through the same !trim() guard, so coverage is complete; left as-is per your "not needed for coverage" note.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
@wangmiao0668000666
wangmiao0668000666 deleted the fix/gateway-status-blank-url branch November 12, 2026 06:19
@wangmiao0668000666
wangmiao0668000666 restored the fix/gateway-status-blank-url branch November 12, 2026 07:54
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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.

2 participants