Skip to content

fix(cli): surface blank --account/--channel remedies in both lanes - #198965

Merged
obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/channels-selector-coercion-remedy
Nov 14, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/channels-selector-coercion-remedy

Conversation

@SunnyShu0925

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw channels capabilities --account "" exits 1 and prints only [openclaw] The CLI command failed. plus [openclaw] For help, run `openclaw doctor`. — the actual reason, --account must not be blank, never reaches the terminal, and the same happens for channels resolve, directory self, directory peers list and message send with a blank --account or --channel (the usual result of an unset shell variable). This change routes both blank-input guards through the CLI's expected-failure owner so the remedy is printed in the default text mode and in --json mode.

  • Problem: parseAccountSelector (src/commands/channels/account-selector.ts:5) and parseChannelSelector (src/commands/channels/channel-selector.ts:5) threw a plain Error. They are registered as Commander option coercion callbacks (channels-cli.ts:243/263, directory-cli.ts:89/91, register.message.ts:161/163), so the throw happens during option parsing, before the action wrapper that prints CLI errors, and the root renderer folds it into the generic failure pair
  • Solution: throw through throwExpectedCliError() from src/cli/expected-cli-error.ts, the owner already used for the same guard shape in src/commands/status-json-command.ts:32, src/commands/export-trajectory.ts:91 and src/cli/capability-cli/shared.ts:54
  • What changed: one import and one throw statement per selector file (net +4 production lines: two imports, two blank separators, two line-neutral throw swaps); the existing rejection cases in src/cli/account-selector-boundary.test.ts and src/cli/channels-account-selector.integration.test.ts now assert the rejection type (net −1 test line, no new file, no new exports)
  • What did NOT change: the remedy strings, the exit code, stdout in either mode, the --json envelope, the behavior of a non-blank value, and every failure that is not one of these two guards

Why This Change Was Made

The complete fix is to make these two bootstrap argument parsers raise the error type the root renderer already understands, so one owner serves both output lanes regardless of where the guard is called from. runCommandWithRuntime (src/cli/cli-utils.ts:39-57) prints through the runtime only when the error is not an ExitError, JSON mode is off, and the error is not an ExpectedCliError; otherwise it rethrows and src/cli/failure-output.ts prints humanOutput. A plain Error raised during coercion never reaches that wrapper at all, which is why both lanes lost the text.

Best fix: yes — src/cli/expected-cli-error.ts states "Bootstrap argument parsers use this module; keep runtime dependencies out", and these two files are exactly that; the conversion adds no runtime dependency, no formatter and no second rendering rule. Alternatives rejected: special-casing these two strings in the root renderer (duplicate policy for one command family), moving the checks into each action body (six call sites reimplement one guard), or leaving them because a --json consumer can parse stdout (the error stream still contradicts the envelope and the text mode prints nothing).

Risk and boundaries: the only behavior beyond the remedy restoration is that an ExpectedCliError is rethrown past runChannelsCommandWithDanger, so the Channel login failed: / Channel logout failed: label is no longer prepended for these two guards (measured below, exit code and stdout unchanged). Non-goals: the independent --agent blank guards, dead-letters.ts's own selector owner, and any runtime failure that is not an argument check stay on their current paths.

User Impact

A mistyped or unset --account / --channel now explains itself: openclaw channels capabilities --account "", channels resolve --account "" abc, directory self --channel "", directory peers list --account " " and message send --target x --account " " --dry-run print --account must not be blank / --channel must not be blank on stderr, in the default text mode where previously the reason appeared nowhere, and in --json mode where previously only the stdout envelope carried it. Scripts and agent logs that read stderr get the same explanation the envelope already had. No new flags, no config keys, no documentation changes; both remedy strings are already documented in docs/cli/directory.md and docs/cli/pairing.md.

Compatibility

Evidence

Both arms are real builds of the shipped CLI, run end to end through the launcher. node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup was run in a frozen origin/main checkout at d98f18ff7c3 and in this head 364f15a8e61; each launcher identifies its own build (OpenClaw 2026.11.3 (d98f18f) and OpenClaw 2026.11.3 (364f15a)). Every cell below is node openclaw.mjs … under env -i with HOME, XDG_RUNTIME_DIR and OPENCLAW_STATE_DIR pointed at a fresh mode-0700 scratch directory — no gateway, no credentials, no mocks, no source-level harness. Sixteen cells per arm, all exit 1 in both arms. Each stderr stream also carries a Node TLS advisory and a log-file notice that are byte-identical across arms; sizes are whole-stream, quoted lines are the payload.

Case (shipped node openclaw.mjs …) Before — built origin/main d98f18f After — built this head 364f15a
channels capabilities --account "" (text) stderr 453 B: The CLI command failed. + For help, run \openclaw doctor`.`; stdout 0 B stderr 402 B: --account must not be blank; stdout 0 B
channels capabilities --account "" --json stderr 453 B generic pair; stdout 106 B envelope stderr 402 B remedy; stdout 106 B envelope, cmp identical
channels resolve --account "" abc (text and --json) generic pair on stderr in both modes --account must not be blank in both modes; stdout cmp identical
directory self --channel "" (text and --json) generic pair on stderr in both modes --channel must not be blank in both modes; stdout cmp identical
directory peers list --account " " (text and --json) generic pair on stderr in both modes --account must not be blank in both modes; stdout cmp identical
message send --target x --account " " --dry-run (text and --json) generic pair on stderr in both modes --account must not be blank in both modes; stdout cmp identical
message send --target x --channel "" --dry-run (text and --json) generic pair on stderr in both modes --channel must not be blank in both modes; stdout cmp identical
control: channels capabilities --account default (non-blank) stderr 457 B --account requires a specific --channel. Run openclaw channels list to choose one. byte-identical, 457 B; stdout 0 B
action lane: channels add --channel telegram --account "" stderr 402 B remedy; stdout 173 B byte-identical, 402 B and 173 B
action lane: channels login --account "" stderr 424 B Channel login failed: --account must not be blank stderr 402 B bare remedy; stdout 173 B identical
action lane: channels logout --account "" stderr 425 B Channel logout failed: --account must not be blank stderr 402 B bare remedy; stdout 0 B identical
exit code, all 16 cells in both arms 1 1

BASE build, default text mode — the reason is missing from every stream:

$ node openclaw.mjs channels capabilities --account ""
[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw doctor`.

HEAD build, same command — remedy restored, same exit code:

$ node openclaw.mjs channels capabilities --account ""
--account must not be blank

HEAD build, --json stdout of that same command — identical to BASE:

{
  "ok": false,
  "error": {
    "type": "cli_error",
    "message": "--account must not be blank"
  }
}

The shipped bundles carry exactly this change and nothing else. BASE chunk dist/channel-selector-8Io11J60.mjs:

//!src/commands/channels/channel-selector.ts
function parseChannelSelector(e){if(e!==void 0&&!e.trim())throw new Error(`--channel must not be blank`);return e}export{parseChannelSelector as t};

HEAD chunk dist/channel-selector-CMlB-vmp.mjs (the account chunk is symmetric):

import{n as throwExpectedCliError}from"./expected-cli-error-oDVmXYil.mjs";
//!src/commands/channels/channel-selector.ts
function parseChannelSelector(e){if(e!==void 0&&!e.trim())throwExpectedCliError(`--channel must not be blank`);return e}export{parseChannelSelector as t};

cmp across the two builds confirms the blast radius: all six --json envelopes (106 B), all six text-mode stdout streams (0 B), the non-blank control (457 B) and both channels add streams (402 B / 173 B) are byte-identical. The twelve coercion stderr cells and the two wrapper-label cells are the only differences.

Regression tests, folded into the existing cases of the two suites that already cover these guards (net −1 test line, no new file, no new exports):

# unfixed source (this head with only the two selector files reverted), head tests
vitest run src/cli/account-selector-boundary.test.ts src/cli/channels-account-selector.integration.test.ts
Test Files  2 failed (2)
     Tests  11 failed | 4 passed (15)
× rejects blank input before message sticker send startup
  → expected Error: --account must not be blank to be an instance of ExpectedCliError
× channels add account selection > rejects an explicit blank before loading config
  → promise resolved "undefined" instead of rejecting

# fixed source
Test Files  2 passed (2)
     Tests  15 passed (15)

The three coercion-lane rejections fail on the thrown type; the eight action-lane rejections fail because BASE swallows the guard inside runCommandWithRuntime and resolves while HEAD rethrows it to the root renderer — which is why the shipped channels add cell stays byte-identical even though its test now asserts the rejection. The four passing cases are the omitted-account default-selection paths, unchanged.

Consumer suites covering the six commands, the renderer and the same option topology, all green on HEAD:

vitest run src/cli/channel-auth.test.ts src/cli/channels-cli.test.ts src/cli/channels-cli.option-values.test.ts src/cli/directory-cli.test.ts
Test Files  4 passed (4) | Tests  67 passed (67)

vitest run src/cli/program/register.message.test.ts src/cli/program/message/helpers.test.ts src/cli/pairing-cli.test.ts src/commands/channels/dead-letters.test.ts src/commands/channels.add.test.ts src/commands/channels.remove.test.ts src/commands/channels.resolve.test.ts
Test Files  7 passed (7) | Tests  131 passed (131)

Formatting and lint on the four changed files are clean: the repository formatter reports All matched files use the correct format, and oxlint with the repository config reports Found 0 warnings and 0 errors on 259 rules.

Open PR collision check, re-run against the submission-day open-PR snapshot: a changed-file sweep over the newest 150 open PRs returns no PR touching any of the four files, nor src/cli/expected-cli-error.ts, src/cli/cli-utils.ts, src/cli/failure-output.ts or src/cli/channels-cli.ts. Keyword searches for parseAccountSelector, parseChannelSelector and throwExpectedCliError return #183099 (channels start/stop), #190470 (dead-letters), #193704 (audit --agent), #197626 (gateway status --url), #191233, #191237, #198329, #198333 and #198345 — all with zero file overlap with this change.

What was not tested: a full-graph typecheck was not run locally, so the typed lanes are left to CI on this head. The cliStartup build profile stops at check-cli-bootstrap-imports with agents/identity-file.worker.js: 240 evaluated modules exceeds budget 220 — the identical assertion on the frozen BASE build and on HEAD, i.e. pre-existing in this environment and unrelated to these two files; tsdown emitted dist/entry.js on both arms and the launcher runs it, which is what every cell above exercises. The test/cli-json-stdout.*.e2e.test.ts suites cover sibling flags (--agent, --command-cwd) rather than these guards and were not run. No Windows or macOS run, and no run against a live channel provider.

The --account and --channel option parsers ran during Commander coercion,
before the action wrapper that renders CLI errors, so a plain Error lost its
remedy text in the human lane and turned the JSON lane into a generic failure.
Throw through ExpectedCliError so both lanes report the actual message.
@clawsweeper

clawsweeper Bot commented Nov 14, 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 14, 2026
@SunnyShu0925
SunnyShu0925 marked this pull request as ready for review November 14, 2026 15:22
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Nov 14, 2026
@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes blank account and channel selectors print their specific validation error in both text and JSON modes.

Example: Run openclaw channels capabilities --account "".

  • Before: Stderr prints a generic command failure and a Doctor hint.
  • After: Stderr prints --account must not be blank; the exit code remains 1.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused repair with shipped-entry-point proof and red/green regression evidence; broad hosted validation is still pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The complete body records isolated built-launcher runs on the pinned base and head: blank account/channel inputs print the specific error in text and JSON modes, exit 1, preserve JSON stdout, and retain nonblank controls; collaborator output independently corroborates the changed paths.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An empty account or channel argument produces a generic failure that hides which flag needs correction.
Reason: Restoring existing validation diagnostics follows the established expected-error contract without adding options, changing defaults, or widening accepted inputs.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current CLI diagnostic defect with a focused change using the existing error-rendering owner; no introduced bugs were found, and hosted CI remains pending.

Priority: P2
Reviewed head: 364f15a8e618f4c274a41444cbe7b1c785973096

Before merge

None.

Findings

None.

Agent review details

How this fits together

Commander and channel command actions pass selector values through shared validators; expected errors reach the root CLI renderer, which produces stderr diagnostics and JSON failure output.

flowchart TD
  A[CLI arguments] --> B[Commander option parsing]
  B --> C[Shared selector validators]
  B --> D[Channel command actions]
  D --> C
  C --> E[Expected CLI error]
  E --> F[Root failure renderer]
  F --> G[Stderr and JSON output]
Loading

Technical review

Best possible solution:

Keep both existing selector guards and route their failures through the canonical expected-error helper as this PR does.

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

Current-main source demonstrates the failure path, and supplied built-CLI before/after output corroborates it; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch is the smallest complete fix: both producers use the existing dependency-light error owner, preserving selector rules and avoiding renderer special cases.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Account-selector rejection and startup-boundary tests keeps the original intent (8f42f0f: Reject explicit blanks before channel mutations; later parser conversion and startup-boundary coverage extended the same rule to lookups and message commands.)
  • Channel-selector rejection keeps the original intent (c1618cd: Only omission requests channel inference; explicit blanks must fail before directory setup or lookup.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jerome: Raw commit bc097bf adds src/cli/expected-cli-error.ts:27 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: bc097bf6404f; files: src/cli/expected-cli-error.ts)
  • Masato Hoshino: Raw commit c1618cd adds src/commands/channels/channel-selector.ts:3 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c1618cd937b3; files: src/commands/channels/channel-selector.ts)
  • MarMar Labs: Raw commit 8f42f0f adds src/commands/channels/account-selector.ts:5 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 8f42f0f5dfa4; files: src/commands/channels/account-selector.ts)

PR surface

Source +4, Tests -1. Total +3 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 6 2 +4
Tests 2 8 9 -1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 14 11 +3

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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Invalid selectors hide their specific explanation across several CLI commands, creating avoidable troubleshooting with limited operational impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • 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-14T15:38:29.640Z sha 364f15a :: needs maintainer review before merge. :: none

Reviewed November 14, 2026, 11:21 AM ET / 16:21 UTC (Revision 2).

@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Independent proof at 364f15a (base d98f18f), host through ocx, tiers vitest-source + source. Host eligibility checked with git diff --name-only $(git merge-base origin/main HEAD)...HEAD: only two selector modules and two tests; no install/scripts/hooks paths. No host git hook ran. No changes or push needed; after-push.sh requested exact-head review.

All commands used isolated task home/state/config and explicit p198965 profiles. No Gateway started. The boundary test verifies rejection before preAction/startup; these parsers run during Commander coercion, before action/Gateway access. Selection/name-to-ID code unchanged.

Receipts (stdout/stderr captured together in local logs):

ocx test src/cli/account-selector-boundary.test.ts src/cli/channels-account-selector.integration.test.ts
base with candidate boundary test: 3 failed / 12 passed, exit 1
candidate: 15 passed, exit 0

ocx src -- --profile p198965... channels capabilities --account "" [--json]
ocx src -- --profile p198965proof channels resolve --account "" room [--json]
ocx src -- --profile p198965... message send --channel "" [--json]
base: [openclaw] The CLI command failed. + Doctor hint
candidate: --account must not be blank / --channel must not be blank
all exit 1; text stdout empty; existing JSON error payload unchanged

control: channels capabilities --channel telegram [--json]
both exit 0: Telegram default, direct/group/channel/thread;
polls reactions threads media nativeCommands blockStreaming; send,broadcast;
not configured, enabled. JSON differs only in explicit profile name embedded in help.

control: channels resolve --channel "" room [--json]
both exit 1 with same existing Channel is required message/JSON.

Command correction: channels resolve requires an entry and its --channel option does not use parseChannelSelector. That case is intentionally an unchanged control; --account there and --channel on message send exercise the changed guards. Initial missing-entry attempts are setup-only, not proof.

Production +6/-2; tests +8/-9. Contributor commit preserved. PR author SunnyShu0925 differs from commit author AND committer: 0668000539 <[email protected]>. No agent identity trailers found. Receipts: proofs/198965. Fork CI approval has been supplied by the lead.

@obviyus
obviyus merged commit 8b8204b into openclaw:main Nov 14, 2026
173 of 191 checks passed
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Landed in 8b8204b. Thanks @SunnyShu0925.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
…penclaw#198965)

fix(cli): show the blank --account and --channel errors

A blank --account or --channel (for example an unset shell variable) made the account and channel selectors throw a plain error, so commands such as `openclaw channels capabilities`, `channels resolve --account`, `directory self`, `directory peers list` and `message send` printed only "The CLI command failed." and the doctor hint instead of the existing "--account must not be blank" or "--channel must not be blank". The selectors now throw the same messages through the existing expected-CLI-error path. Selection and name resolution are unchanged. No new text.

Evidence: vitest-source, the updated tests fail on base and pass here. Source tier with isolated state, text and --json: base printed only the generic failure; this change prints the existing "must not be blank" line, with exit codes and JSON unchanged. `channels resolve --channel ""` does not use this selector and is unchanged on both; valid values behave the same on both. Net -1 test lines. Receipts: openclaw#198965 (comment).

Thanks @SunnyShu0925.

Co-authored-by: 0668000539 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
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: 🐚 platinum hermit Good normal PR readiness with ordinary 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