Repository navigation
fix(cli): honor selected port when tailing logs - #130513
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Land-ready verification for Native review artifacts validated and 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.tsThe 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. |
|
Merged via squash.
|
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
--portwould 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 receivedlogs.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 throughOPENCLAW_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/--portconflicts 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 emittype:erroron 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 rejectedws://remote.example:19001instead of querying the selected local fixture. The same cases pass after the repair.The full changed gate was attempted with:
Its generic guards, dead-export scans, formatting and core production typecheck passed. Core-test typechecking stopped at unrelated
ui/vite.config.ts:9with 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.