Skip to content

fix(cli): honor selected port when tailing logs - #130513

Merged
steipete merged 1 commit into
mainfrom
codex/qa-cli-log-port-20260826
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa-cli-log-port-20260826

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #130512 (logs ignores the selected port in target preparation and diagnostics).

Additional instructions

Maintainers can push to this repository-owned branch.

What Problem This Solves

Fixes an issue where users tailing logs with --port would be blocked by an unrelated remote default, or receive diagnostics naming the wrong Gateway. A safe local selection could fail with a plaintext-remote-URL error before the selected server received logs.tail.

The shared flag was added in #125474 (automation Gateway port options), but the logs command's target preparation, plain-error fallback classification, and diagnostic projection still reconstructed the default connection without that port.

Why This Change Was Made

Prepare one canonical selected connection at the logs command boundary and carry it through client setup, fallback decisions and diagnostics. Reuse the existing strict port/conflict resolver in its owning port-option module; shared RPC still uses the same policy, and typed transport errors retain their actual connection details.

This removes the separate passive-target helper and repeated incomplete target reconstruction. It adds no config, dependencies, protocol, persistence or credential policy. Plaintext-remote validation, explicit-URL credential requirements and explicit-URL no-file-fallback behavior remain intact.

Production LOC: +38/-35, net +3. Tests: +185/-0. Docs: +4/-0. The small production increase records a prepared typed target and its ownership invariant; the resolver is moved rather than duplicated, and the logs owner itself remains line-neutral.

User Impact

openclaw logs --port <port> consistently selects that local Gateway even when a different remote URL is configured or supplied through OPENCLAW_GATEWAY_URL. Terminal failures identify the selected server. Eligible one-shot local-file fallback uses that same target classification.

Usage-error clarification: invalid port values and --url/--port conflicts now use the root CLI's stdout JSON envelope (ok:false, error.type:cli_error) and exit 1, matching existing invalid log-limit/interval/byte-limit errors. They previously emitted a misleading Gateway-unreachable log event on stderr. Actual terminal log-fetch errors still emit type:error on stderr. The docs now explain this distinction and show --port. The shared port option's available release-tag ancestry is beta-only; no stable-release output compatibility claim is made.

Evidence

Before editing production, two real Commander/Gateway WebSocket cases failed on main 25a16dd96c42876cc80b0ad754a612a75524b4eb: both remote-config and environment-default scenarios rejected ws://remote.example:19001 instead of querying the selected local fixture. The same cases pass after the repair.

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/cli/logs-cli.port.test.ts src/cli/logs-cli.test.ts src/cli/gateway-rpc.runtime.test.ts src/cli/gateway-port-option.test.ts
node --import tsx scripts/build-all.mts cliStartup
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/cli/gateway-port-option.ts src/cli/gateway-rpc.runtime.ts src/cli/logs-cli.port.test.ts src/cli/logs-cli.ts
node scripts/check-docs-mdx.mjs docs/cli/logs.md
git diff --check
  • 82 tests / four files passed, independently rerun with the same result. The nine new cases exercise the real parser, configuration/connection builder and WebSocket client with no production module mocks.
  • Four independent narrow fault-injection probes passed, retaining the real connection builder and isolated configured-file reader while injecting a plain transport-close error. These cover both config/environment defaults and JSON/plain fallback output.
  • Nine built-CLI subprocess scenarios passed: selected-server log output despite ambient defaults, no contact with another listening default, JSON/plain target diagnostics, post-handshake close/file fallback and usage validation. A separate exact-baseline build confirmed the old/new usage-error envelopes.
  • Source-blind operator validation passed all five contracts across 35 commands and 72 fresh wire events, with no accepted behavioral findings. It checked fresh per-server log markers, selected/unselected request deltas, failures, implicit versus explicit fallback, malformed ports and explicit URL controls without reading product or fixture source.
  • Fresh authenticated Codex whole-patch review, including docs: no actionable P0–P2 findings.
  • Build, changed-file typed lint, docs MDX/format and diff checks passed.

The full changed gate was attempted with:

node scripts/check-changed.mjs --base 25a16dd96c42876cc80b0ad754a612a75524b4eb -- src/cli/gateway-port-option.ts src/cli/gateway-rpc.runtime.ts src/cli/logs-cli.ts src/cli/logs-cli.port.test.ts

Its generic guards, dead-export scans, formatting and core production typecheck passed. Core-test typechecking stopped at unrelated ui/vite.config.ts:9 with TS7016: this validation checkout's linked dependency donor resolves pako 1.0.11 without declarations, while the UI lockfile requires 3.0.1. No dependencies or unrelated UI files were changed, and this is not a claim of full-gate success; exact-head CI remains required.

All runtime proof used isolated temporary state, loopback protocol fixtures and fake credentials. It did not contact an operator Gateway or an external model/provider. Fixture processes were stopped, temporary state removed, and all five listening ports verified closed.

AI-assisted QA and repair.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: M maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 00:02
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification for 052c49b7c3bb609572febfef870d3562a48727d6:

Native review artifacts validated and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 130513 passed without rebasing or changing the reviewed head. Exact-head CI run 33025461634 is green, including hosted production types, test types and lint; those fresh-install checks close the earlier local dependency-donor type gap.

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/cli/logs-cli.port.test.ts src/cli/logs-cli.test.ts src/cli/gateway-rpc.runtime.test.ts src/cli/gateway-port-option.test.ts

The focused suite passed 82 tests and was independently rerun. Four independent plain-error fallback probes, nine owner built-CLI scenarios, and a source-blind 35-command/five-contract run also passed. The source-blind run observed 72 fresh wire events and no incorrect target contacts. These were isolated protocol-fixture checks, not operator-Gateway or external-provider tests.

Fresh authenticated whole-patch review, including docs, found no actionable P0–P2 issues. Current main's affected logs/RPC owners and callers remain unchanged. The latest ClawSweeper comment is still its review-started placeholder; no actual findings or Rank-up moves are published yet.

The PR body and docs explicitly describe the beta flag's usage-error JSON alignment; transport validation and explicit-URL fallback/credential controls remain intact.

@steipete
steipete merged commit 00713ca into main Aug 27, 2026
268 checks passed
@steipete
steipete deleted the codex/qa-cli-log-port-20260826 branch August 27, 2026 00:34
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: logs --port validates and reports an unrelated default Gateway

1 participant