Skip to content

fix(cli): surface channels resolve guard remedies in --json failures - #199608

Merged
obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/channels-resolve-guards-json-remedy-416
Nov 15, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/channels-resolve-guards-json-remedy-416

Conversation

@SunnyShu0925

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw channels resolve friends --agent " " --json answers with the generic wrapper pair [openclaw] The CLI command failed. / [openclaw] For help, run openclaw doctor. on stderr and never shows the actionable --agent must not be blank text that the same command prints in the human lane, so scripts and agents that drive --json cannot tell what to fix without parsing the stdout envelope. The same gap hides the remedies of the other two input guards of channels resolve (empty entry list, catalog channel not installed).

  • Problem: the three operator-input guards in channelsResolveCommand throw a plain Error, so the structured-output renderer treats them as unexpected crashes instead of expected CLI failures. The remedy text survives only inside the JSON envelope on stdout, while stderr shows the two generic wrapper lines.
  • Solution: route all three guards through the existing throwExpectedCliError owner so the failures are classified as expected CLI errors; the renderer then prints the same remedy to stderr that the human lane already prints.
  • What changed: src/commands/channels/resolve.ts adds one import and replaces throw new Error(...) with throwExpectedCliError(...) at the three guard sites, keeping every message byte-for-byte. Regression coverage is folded into three existing it cases in src/commands/channels.resolve.test.ts by asserting the error category next to the existing message assertions (net 0 test lines, no new test file).
  • What did NOT change: message text, exit code 1, the human-lane stderr, the JSON envelope shape and content ("type": "cli_error"), and the unsupported-channel runtime capability error later in the same command, which stays a plain Error because it reports a missing runtime capability rather than invalid operator input.

Why This Change Was Made

The CLI already has a single owner for "this failure is expected, show the remedy" (throwExpectedCliError in src/cli/expected-cli-error.ts), and the sibling guards converted in recently merged PRs (#198471, #198662, #198861, #198965, #199523) use it. The channels command family is mid-sweep: src/commands/channels/capabilities.ts already constructs ExpectedCliError while resolve.ts still threw plain errors, so this completes the family's rendering contract instead of adding a second classification path.

  • Best fix: convert each guard at its throw site inside the command owner, because every entry point (channels resolve with or without --channel, --agent, --kind) shares these three guards and gets the same remedy for free.
  • Alternative(s): catching the errors in the channels-cli.ts registration wrapper and rethrowing was rejected — it duplicates the messages in a second place and misses future callers of the command. Special-casing these messages in the JSON renderer was rejected as an over-broad change touching every command, and reclassifying the unsupported-channel capability error was rejected because genuine runtime failures must keep the generic rendering.
  • Risk: the only observable change is that --json stderr now shows the remedy instead of the generic wrapper pair for these three expected, user-input failures; the JSON envelope, exit code, and human lane are byte-identical (see the cmp results below).

User Impact

Operators and automation running openclaw channels resolve ... --json now see the exact remedy on stderr — At least one entry is required. Example: openclaw channels resolve --channel discord <name-or-id>., --agent must not be blank, or Channel plugin "discord" is not installed. Run openclaw channels add --channel discord first. — and can correct the invocation without digging into the stdout envelope. Human-output users, the JSON payload, and the exit status are unchanged.

Evidence

Case Before (base origin/main, de40bf5) After (this head, c434c61)
channels resolve " " --json stderr [openclaw] The CLI command failed. + [openclaw] For help, run \openclaw doctor`.` (remedy missing) At least one entry is required. Example: openclaw channels resolve --channel discord <name-or-id>.
channels resolve friends --agent " " --json stderr generic wrapper pair (remedy missing) --agent must not be blank
channels resolve friends --channel discord --json stderr (catalog channel not installed) generic wrapper pair (remedy missing) Channel plugin "discord" is not installed. Run openclaw channels add --channel discord first.
All three guards, human lane stderr remedy printed byte-identical (cmp)
All three guards, --json stdout envelope {"ok":false,"error":{"type":"cli_error","message":"<remedy>"}}, exit 1 byte-identical (cmp), exit 1
channels resolve friends --channel definitely-not-a-channel (control, unconverted capability error) generic wrapper pair on stderr, remedy in envelope, exit 1 byte-identical on all four streams (cmp)
src/commands/channels.resolve.test.ts `3 failed 9 passed (12)`

Both arms are real cliStartup builds of the same tree, run through the shipped launcher; --version self-reports the two commits:

$ node openclaw.mjs --version   # frozen origin/main build
OpenClaw 2026.11.3 (de40bf5)

$ node openclaw.mjs --version   # this head build
OpenClaw 2026.11.3 (c434c61)

Each cell is a complete user command in a fresh, isolated scratch HOME / state / XDG runtime directory (chmod 700, user bus cut), with no credentials and no mocks. Representative pair, --agent " " guard:

$ node openclaw.mjs channels resolve friends --agent " " --json   # base
[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw doctor`.
[openclaw] log file append failed; records dropped; check that the path is a writable regular file; file=openclaw-2026-11-15.log
exit 1

$ node openclaw.mjs channels resolve friends --agent " " --json   # this head
--agent must not be blank
[openclaw] log file append failed; records dropped; check that the path is a writable regular file; file=openclaw-2026-11-15.log
exit 1

The log-append note comes from the scratch environment and is identical on both arms; the only differing line is the remedy. Every cell's stderr was checked to contain its own guard's remedy (or, for the control, the capability message in the envelope), so no cell was short-circuited by an earlier registration-layer rejection.

Unchanged outputs are compared byte for byte across the two builds (3 guards x 2 lanes + control x 2 lanes, 16 runs total, all exit 1):

$ cmp base.g1.json.out head.g1.json.out && echo "g1 json envelope identical"
g1 json envelope identical
$ cmp base.g2.json.out head.g2.json.out && echo "g2 json envelope identical"
g2 json envelope identical
$ cmp base.g3.json.out head.g3.json.out && echo "g3 json envelope identical"
g3 json envelope identical
$ cmp base.g1.text.err head.g1.text.err && echo "g1 text lane identical"
g1 text lane identical
$ cmp base.g2.text.err head.g2.text.err && echo "g2 text lane identical"
g2 text lane identical
$ cmp base.g3.text.err head.g3.text.err && echo "g3 text lane identical"
g3 text lane identical
$ cmp base.ctl.json.out head.ctl.json.out && cmp base.ctl.json.err head.ctl.json.err \
    && cmp base.ctl.text.out head.ctl.text.out && cmp base.ctl.text.err head.ctl.text.err \
    && echo "control identical on all four streams"
control identical on all four streams

The built bundles show the executed form (base still throws a plain Error, head uses the shared owner):

# base: dist/resolve-BoXrKdfu.mjs
...if(n.length===0)throw new Error(`At least one entry is required. Example: ${formatCliCommand(`openclaw channels r...

# head: dist/resolve-D4mv2WkD.mjs
...if(n.length===0)throwExpectedCliError(`At least one entry is required. Example: ${formatCliCommand(`openclaw channels r...

Regression test, base production code with the folded assertions kept (RED), then the fixed source (GREEN):

$ vitest run --config test/vitest/vitest.commands.config.ts src/commands/channels.resolve.test.ts   # base production code
 FAIL  channelsResolveCommand > rejects missing entries before config for a named account
 FAIL  channelsResolveCommand > rejects a whitespace-only explicit agent before channel resolution
 FAIL  channelsResolveCommand > tells users to add an explicit catalog channel before resolving
AssertionError: expected Error: Channel plugin "external-chat" is ... to have property "name" with value 'ExpectedCliError'
      Tests  3 failed | 9 passed (12)

$ vitest run --config test/vitest/vitest.commands.config.ts src/commands/channels.resolve.test.ts   # this head
      Tests  12 passed (12)

Consumer suites of the touched command and its registration/selector/secret-resolution neighbors all stay green on this head:

$ vitest run --config test/vitest/vitest.cli.config.ts src/cli/channels-cli.test.ts \
    src/cli/channels-cli.option-values.test.ts src/cli/account-selector-boundary.test.ts \
    src/cli/command-secret-gateway.test.ts
      Tests  56 passed (56)

oxfmt --check passes on both touched files; oxlint (259 rules) reports 0 warnings and 0 errors on them.

Open PR collision check: scanned the changed-file lists of all 3576 open pull requests (plus a REST follow-up for every PR whose file list exceeded the API window) and ran keyword searches for channels resolve, must not be blank, The CLI command failed, and throwExpectedCliError; no open pull request touches src/commands/channels/resolve.ts or its test file, and the eight open PRs under src/commands/channels/ all own different files (status, remove, dead-letters, start-stop, add-wizard). The only two PRs whose file lists could not be enumerated normally (#144984, #155667) are conflicting September forks reporting ~39.6k changed files as a whole-repo divergence artifact; neither targets the channels resolve guards.

What was not tested: the success path of resolving against a real installed channel (the change only reclassifies three failure throws and leaves the resolution flow untouched); the full-graph typecheck is not runnable on this host, but the converted call form is byte-identical to the sibling modules already compiling on origin/main, and CI's typecheck lanes cover it.

@clawsweeper

clawsweeper Bot commented Nov 15, 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 commands Command implementations size: XS labels Nov 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes three channels resolve input failures display their existing remedies on stderr in JSON mode.

Example: Run openclaw channels resolve friends --agent " " --json.

  • Before: Stderr shows a generic CLI failure and Doctor hint.
  • After: Stderr shows --agent must not be blank; JSON stdout and exit code 1 remain unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-level repair with relevant shipped CLI proof, corroborated red/green regressions, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The body supplies pinned base/head shipped-launcher traces in isolated credential-free state for all three guards, with preserved JSON envelopes, text output, exit codes, and an unsupported-channel control; obviyus corroborates the behavior independently. Inspected Fast mode screenshots are unrelated and receive no proof credit.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: JSON-mode callers reading stderr receive generic failure guidance instead of the actionable input remedy.
Reason: The change restores the established expected-error contract while preserving accepted inputs, messages, configuration, and channel resolution.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a current-main diagnostic bug with a minimal change and no actionable findings.

Priority: P3
Reviewed head: c434c61268b94681d2f6bb1cff43e97eaf33412b

Before merge

None.

Findings

None.

Agent review details

How this fits together

The channels CLI passes arguments to the resolve command, whose rejected errors reach the shared CLI renderer for stderr diagnostics and JSON failure envelopes.

flowchart TD
  A[CLI arguments] --> B[Channels resolve command]
  B --> C[Input guards]
  C --> D[Expected CLI error]
  D --> E[Shared failure renderer]
  E --> F[Stderr remedy and JSON envelope]
  B --> G[Channel resolver]
Loading

Technical review

Best possible solution:

Use the existing expected-error helper at these three guards while preserving their messages and the shared renderer.

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

Current-main source establishes the plain-error rendering path, and supplied base/head terminal runs corroborate all three failures; this review executed no target code.

Is this the best way to solve the issue?

This is the smallest complete repair: classify expected failures where they originate and reuse the existing rendering owner without adding wrappers or message matching.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Entry and agent validation keeps the original intent (46dcc57: The merged selector sweep validates explicit agent selections and rejects blank input before channel resolution.)
  • Catalog channel not installed keeps the original intent (250376f: Plugin dependency repair work preserves explicit installation requirements; later CLI guidance supplies the channels add remedy.)
  • Existing rejection tests keeps the original intent (test(infra,agents,cli,memory,gateway,chat,auth,commands): remove low-value tests (batch d532) #183583: Maintainer-requested test reductions preserve distinct boundary coverage while removing redundant scaffolding; this PR extends existing cases without adding test groups.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 46dcc57 adds src/commands/channels/resolve.ts:134 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 46dcc57c5498; files: src/commands/channels/resolve.ts)
  • Vincent Koc: Raw commit 56916bc adds src/commands/channels/resolve.ts:151 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 56916bc8bfd9; files: src/commands/channels/resolve.ts)

PR surface

Source +1, Tests 0. Total +1 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 3 +1
Tests 1 7 7 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 11 10 +1

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:

  • P3: This improves diagnostics for invalid advanced CLI invocations; the actionable message already survives in JSON stdout.
  • 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-15T12:54:54.469Z sha c434c61 :: needs maintainer review before merge. :: none

Reviewed November 15, 2026, 9:18 AM ET / 14:18 UTC (Revision 2).

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Verified base de40bf5ca2c0 against head c434c61268b94681d2f6bb1cff43e97eaf33412b. No repository edits or push.

Host proof tiers: vitest-source and source (pinned Bun). Source commands used separate empty-config homes with the same isolated profile, an allowlisted environment with no channel credentials, and no Gateway started. Host eligibility passed: only the two src/commands files differ; no install, lifecycle, hook, or scripts changes. No host hooks ran.

Ran each command with and without --json, on both versions:

ocx src -- --profile p199608proof channels resolve ' ' --json
ocx src -- --profile p199608proof channels resolve x --agent ' ' --json
ocx src -- --profile p199608proof channels resolve x --channel agentmail --json

agentmail is a shipped catalog ID (@agentmail/agentmail), absent from the isolated profile. It naturally reached the not-installed guard; no catalog fixture or installation was used.

All three JSON cases previously printed this stderr:

[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw --profile p199608proof doctor`.

The candidate instead prints the corresponding existing message:

At least one entry is required. Example: openclaw --profile p199608proof channels resolve --channel discord <name-or-id>.
--agent must not be blank
Channel plugin "agentmail" is not installed. Run openclaw --profile p199608proof channels add --channel agentmail first.

Controls: all exit codes remain 1; JSON stdout is byte-identical on base and candidate; all text-mode stdout/stderr is identical. Unknown --channel unknown-proof-199608 is also identical in both modes, including its JSON stderr/Doctor hint. Comparisons exclude only ocx's own prefixed diagnostic lines, retained in the raw receipts.

channels.resolve.test.ts: base has the three intended failures (Error rather than ExpectedCliError) and nine passing controls; candidate passes all 12 tests. Production +4/-3; tests +7/-7 (net 0). Detailed receipts are retained in proofs/199608/.

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 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 15, 2026
@obviyus
obviyus merged commit 636454e into openclaw:main Nov 15, 2026
127 of 128 checks passed
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Landed in 636454e. Thanks @SunnyShu0925.

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

fix(cli): report channels resolve input errors through the expected-error path

`openclaw channels resolve --json` threw plain errors for three input checks (no usable entries, a blank `--agent`, and a catalog channel whose plugin is not installed), so `--json` stderr showed the generic failure plus the Doctor hint instead of the existing message. The three checks now use throwExpectedCliError with the same messages. All three run before any entry name is resolved; no resolve result, lookup order or wording changes.

Evidence: host, isolated state and config, no channel credentials. Vitest-source: three cases fail on base, 12 pass here. Pinned-Bun source: `channels resolve ' ' --json`, `channels resolve x --agent ' ' --json` and `channels resolve x --channel agentmail --json` (real uninstalled catalog plugin): base prints the generic failure and Doctor hint, this change prints the existing message. Text mode, JSON stdout, exit codes and an unknown --channel are identical on both. Receipts: openclaw#199608 (comment).

Thanks @SunnyShu0925.

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

commands Command implementations P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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