Skip to content

fix(cli): surface the capability inspect remedy in --json failures - #198662

Merged
obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/capability-inspect-unknown-name-397
Nov 14, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/capability-inspect-unknown-name-397

Conversation

@SunnyShu0925

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw capability inspect --name bogus --json exits 1 and prints only [openclaw] The CLI command failed. plus [openclaw] For help, run `openclaw doctor`. on stderr, so a script or agent driving the CLI is told nothing about the mistake; the actual reason, Unknown capability: bogus, is trapped in the stdout JSON envelope. Without --json the same command does print the reason.

This change routes that one check through the CLI's expected-failure owner, so both output modes print the remedy on stderr.

  • Problem: the unknown-capability check threw a plain Error, which the root failure renderer treats as "the CLI command failed", while the text path had already printed the message locally
  • Solution: throw ExpectedCliError through the existing throwExpectedCliError() helper, the same owner every other argument guard in this command group uses
  • What changed: one throw site in src/cli/capability-cli.ts; the existing capability metadata test case now also asserts the unknown-id rejection type
  • What did NOT change: the message text, the exit code, the stdout JSON envelope, and every other capability command

Why This Change Was Made

The root renderer (src/cli/failure-output.ts) prints the producer's own remedy for expected failures and the generic "command failed / run doctor" pair for everything else. runCommandWithRuntime prints the message locally only when JSON mode is off, which is why the two lanes disagree for this check today.

#198471 converted this command group's argument guards to throwExpectedCliError() and kept runtime failures on the generic path; validating --name against the capability table is an argument check, so this site belongs with the ones already converted. Fixing it at the producer reuses the existing owner instead of adding a second rendering rule, and keeps the machine-readable envelope byte-identical.

Alternatives considered and rejected: special-casing the string in the root renderer (duplicate policy, grows the cold path); leaving it as-is because --json consumers can read stdout (the remedy then stays invisible in the stream that carries errors, and the text lane keeps contradicting it).

Risk is limited to this command's failure formatting. No schema, config, state, or exit-code change; nothing else reaches this throw.

User Impact

  • openclaw capability inspect --name <id> --json now prints Unknown capability: <id> on stderr alongside the unchanged JSON envelope, so a mistyped or unsupported capability id is self-explanatory in pipelines and agent logs
  • Text output is unchanged, including for a valid id and for capability list
  • No new flags, config keys, or documentation changes are needed

Evidence

Two arms, two lanes, shipped source entry (node --import ./scripts/tsx.mjs src/entry.ts …) against an isolated state directory, no mocks. BASE is origin/main at 94cc426fb0b; HEAD is this branch.

Case Before (94cc426fb0b) After (this head)
capability inspect --name bogus — stderr Unknown capability: bogus (271 B) Unknown capability: bogus (271 B, unchanged)
capability inspect --name bogus --json — stderr [openclaw] The CLI command failed. + doctor hint (324 B) Unknown capability: bogus (271 B)
capability inspect --name bogus --json — stdout 104 B envelope with the message 104 B envelope, byte-identical
capability inspect --name image.edit --json — stdout 497 B, exit 0 497 B, exit 0 (control unchanged)
capability list — stdout 3256 B, exit 0 3256 B, exit 0 (control unchanged)

BASE, text lane — the remedy is visible:

$ node --import ./scripts/tsx.mjs src/entry.ts capability inspect --name bogus
Unknown capability: bogus
$ echo $?
1

BASE, --json lane — stderr loses it, only stdout carries it:

$ node --import ./scripts/tsx.mjs src/entry.ts capability inspect --name bogus --json
[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw doctor`.
$ node --import ./scripts/tsx.mjs src/entry.ts capability inspect --name bogus --json 2>/dev/null
{
  "ok": false,
  "error": {
    "type": "cli_error",
    "message": "Unknown capability: bogus"
  }
}

HEAD, --json lane — the same remedy now reaches stderr, envelope unchanged:

$ node --import ./scripts/tsx.mjs src/entry.ts capability inspect --name bogus --json
Unknown capability: bogus
$ node --import ./scripts/tsx.mjs src/entry.ts capability inspect --name bogus --json 2>/dev/null
{
  "ok": false,
  "error": {
    "type": "cli_error",
    "message": "Unknown capability: bogus"
  }
}

Regression test, folded into the existing it.each(["list", "inspect"]) case in src/cli/capability-cli.test.ts (net −1 test line, no new file):

# unfixed source, new assertion only
× capability cli > queries capability metadata through inspect
AssertionError: expected Error: exit 1 to be an instance of ExpectedCliError

# fixed source
vitest run src/cli/capability-cli.test.ts
Test Files  1 passed (1)
     Tests  117 passed (117)

Sibling suites that touch the same renderer and command group, all green on HEAD:

vitest run src/cli/capability-cli.help.test.ts src/cli/capability-cli.lazy.test.ts
Test Files  2 passed (2)
     Tests  7 passed (7)

vitest run src/cli/failure-output.test.ts src/cli/failure-output.contention.test.ts
Test Files  2 passed (2)
     Tests  26 passed (26)

Open PR collision check: re-run against the submission-day open-PR snapshot, both by changed file and by keyword (capability, ExpectedCliError); no open PR touches src/cli/capability-cli.ts, src/cli/expected-cli-error.ts, or src/cli/failure-output.ts. The nearest family members in review (#198345, #196073, #191233, #197254, #198333) change other command groups with zero file overlap.

What was not tested: no Windows or macOS run, and no real Gateway (this command reads only the local capability table). The repository lint binary could not resolve its JS plugin in the isolated worktree, so oxlint was not run locally; formatting was verified with the repo formatter on both changed files.

Related: #198471 converted the sibling argument guards in this command group to the same owner; this is the remaining --name check it left on the generic path.

@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 size: XS labels Nov 14, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. 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 an unknown capability ID print its specific error on stderr when JSON output is enabled.

Example: Run openclaw capability inspect --name bogus --json.

  • Before: Stderr shows a generic command failure and Doctor hint; stdout JSON contains Unknown capability: bogus.
  • After: Stderr shows Unknown capability: bogus, with the same stdout JSON envelope and exit code 1.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, source-verified fix with matching production-entry proof and a red/green regression; required CI remains in progress.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied terminal output exercises the changed inspect owner through src/entry.ts in isolated state, showing the specific stderr error after the fix, unchanged JSON output and exit status, and unaffected successful controls.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A script or agent using JSON mode receives a generic stderr failure and an irrelevant Doctor hint after supplying an unknown capability ID.
Reason: The focused diagnostic repair follows the merged sibling pattern without changing validation, successful output, flags, or persisted state.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a current diagnostic bug with a focused change and sufficient CLI proof; no actionable defects were found.

Priority: P2
Reviewed head: f45f60286c90f18b7ff38b054cba99a753803874

Before merge

None.

Findings

None.

Agent review details

How this fits together

The infer command tree, also exposed as capability, validates IDs against local metadata and sends failures through the shared CLI runtime and root output renderer.

flowchart TD
  A[CLI arguments] --> B[Inspect capability metadata]
  B --> C[Expected CLI error]
  C --> D[Command runtime]
  D --> E[Root failure renderer]
  E --> F[JSON on stdout]
  E --> G[Specific error on stderr]
Loading

Technical review

Best possible solution:

Land the existing producer-side error classification fix after required CI succeeds.

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

Current-main source shows the plain-error path reaching generic stderr in JSON mode, matching the contributor's supplied before/after CLI output; no target code was executed during this review.

Is this the best way to solve the issue?

The patch is the smallest complete fix: classify the invalid ID at its existing producer, reuse the shared renderer, and extend the existing regression case.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Unknown capability-ID validation keeps the original intent (97c031a: The original infer CLI introduced metadata inspection and rejection of unknown IDs; subsequent CLI refactors preserved that validation.)
  • Expected versus unexpected CLI failures keeps the original intent (fix: make common error messages short and helpful #163381: Shared renderers intentionally provide concise user-facing errors while retaining detailed diagnostics; this PR classifies a known argument failure without exposing unrelated runtime errors.)
  • Existing metadata test consolidation keeps the original intent (86310c8: The approved test-reduction change consolidated overlapping coverage; this PR extends that existing case without adding a parallel suite or scaffolding.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned introduction diff changes only the unknown-ID throw to the existing expected-error helper and extends the existing metadata test. (src/cli/capability-cli.ts:73, f45f60286c90)
  • Current-main bug remains: Fetched main still throws a plain Error for an unknown capability ID. (src/cli/capability-cli.ts:72, 11b022e5d9c3)
  • Existing rendering contract: The command runtime rethrows JSON-mode and expected failures; the root renderer prints ExpectedCliError humanOutput while retaining the canonical JSON envelope. (src/cli/cli-utils.ts:44, f45f60286c90)
  • Supplied production-entry proof: The PR body records isolated before/after runs through src/entry.ts for the invalid ID in text and JSON modes, unchanged JSON output, exit code 1, and successful inspect/list controls; it also records the regression failing without the fix and passing with it. (src/entry.ts:324, f45f60286c90)
  • Merged sibling establishes the same repair pattern: fix(cli): surface capability flag-guard remedies in --json failures #198471 merged the sibling argument-guard conversions but did not change this inspect check; obviyus supplied built-CLI verification and confirmed landing there. (src/cli/capability-cli/shared.ts, d08fbbc54053)
  • Feature history and provenance: The inspect guard traces to the original infer CLI feature; later refactors preserve its validation. Some older helper-history blobs are unavailable locally, but the changed-line provenance and relevant main/base/head source were verified. (src/cli/capability-cli.ts:72, 97c031a8db48)

Likely related people:

  • Peter Steinberger: Raw commit 17cb0b6 adds src/cli/capability-cli.ts:57 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 17cb0b6bf797; files: src/cli/capability-cli.ts)
  • Tak Hoffman: Raw commit 97c031a adds src/cli/capability-cli.ts:1161 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 97c031a8db48; files: src/cli/capability-cli.ts)

PR surface

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

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

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:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on maintainer: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Invalid capability IDs produce misleading stderr in JSON mode, affecting CLI troubleshooting while retaining the correct JSON error and exit status.
  • 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-14T05:14:10.491Z sha f45f602 :: blocked before merge. :: none

Reviewed November 14, 2026, 12:42 AM ET / 05:42 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:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. 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 rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 14, 2026
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Proof on the built CLI (node openclaw.mjs, secretless node:24.22.1 container, no network, isolated state). Main 94cc426 vs this head f45f602.

Only difference between lanes (capability inspect --name bogus --json, stderr):

12,13c12
< [openclaw] The CLI command failed.
< [openclaw] For help, run `openclaw --profile X doctor`.
---
> Unknown capability: bogus

stdout JSON ({ok:false, error:{type:cli_error, message:"Unknown capability: bogus"}}) and exit 1 are the same on both. Controls unchanged: text mode prints Unknown capability: bogus with exit 1 on both; --name image.edit --json prints the same metadata with exit 0 on both. Message text is byte-identical to main.

@obviyus
obviyus merged commit 4f20ee5 into openclaw:main Nov 14, 2026
141 of 142 checks passed
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Landed in 4f20ee5. Thanks @SunnyShu0925.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@obviyus Thanks!

obviyus added a commit that referenced this pull request Nov 14, 2026
…198861)

fix(cli): show openclaw message argument errors on stderr with --json

With --json, `openclaw message` argument checks (numeric options such as --limit, --delete-days and poll durations, and --poll-anonymous with --poll-public) threw a plain error, so stderr showed only "The CLI command failed." and the doctor hint while the reason appeared only in the JSON on stdout. They now throw the same messages through the existing expected-CLI-error path, as the capability checks do since #198471 and #198662. Message text, stdout JSON and exit codes are unchanged. No new text.

Evidence: source tier with isolated state; the checks run before any channel plugin loads. --limit 0, a bad poll duration, and --poll-anonymous with --poll-public, each with --json: main's stderr had only the generic failure and the doctor hint; this change prints the existing reason. Stdout JSON and exit codes match on both, and text mode and a valid --limit behave the same. Vitest-source: the updated tests fail on base and pass here. Net -1 test lines. The one red check, checks-fast-baseline-ratchets, is inherited from #198857. Receipts: #198861 (comment).

Thanks @SunnyShu0925.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
…penclaw#198662)

fix(cli): show the capability inspect unknown-name error on stderr with --json

openclaw capability inspect threw a plain error for an unknown capability name, so with --json stderr showed only "The CLI command failed." and an openclaw doctor hint while "Unknown capability: <name>" appeared only inside the JSON on stdout. It now throws the same message through the existing expected-CLI-error path, as the other capability argument checks do since openclaw#198471. Message text, stdout JSON and the exit code are unchanged. No new text.

Evidence: the built CLI in a secretless node:24.22.1 container with no network and isolated state, main once and candidate once. With --name bogus --json, main's stderr showed only the generic failure and the Doctor hint; with this change it shows "Unknown capability: bogus" (byte-identical to main's message). Stdout JSON and exit code 1 are the same on both, text mode prints the same error, and a valid capability with --json prints the same metadata. Net -1 test lines. Details: openclaw#198662 (comment).

Thanks @SunnyShu0925.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
…penclaw#198861)

fix(cli): show openclaw message argument errors on stderr with --json

With --json, `openclaw message` argument checks (numeric options such as --limit, --delete-days and poll durations, and --poll-anonymous with --poll-public) threw a plain error, so stderr showed only "The CLI command failed." and the doctor hint while the reason appeared only in the JSON on stdout. They now throw the same messages through the existing expected-CLI-error path, as the capability checks do since openclaw#198471 and openclaw#198662. Message text, stdout JSON and exit codes are unchanged. No new text.

Evidence: source tier with isolated state; the checks run before any channel plugin loads. --limit 0, a bad poll duration, and --poll-anonymous with --poll-public, each with --json: main's stderr had only the generic failure and the doctor hint; this change prints the existing reason. Stdout JSON and exit codes match on both, and text mode and a valid --limit behave the same. Vitest-source: the updated tests fail on base and pass here. Net -1 test lines. The one red check, checks-fast-baseline-ratchets, is inherited from openclaw#198857. Receipts: openclaw#198861 (comment).

Thanks @SunnyShu0925.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 15, 2026
fix(cli): report infer preflight errors through the expected-error path

`openclaw infer ... --json` threw plain errors for three checks that run before any request (web fetch disabled, a pinned web fetch provider that is unavailable, and an embedding `--provider` that conflicts with the provider in `--model`), so `--json` stderr showed the generic failure plus the Doctor hint instead of the existing message. The three checks now use the expected-error path with the same messages, following #198662. No new text.

Evidence: host, isolated config, no network or provider credentials. Source CLI with --json and in text mode: `infer web fetch --url https://example.invalid` with web fetch disabled, `infer web fetch --url ... --provider nosuch`, and `infer embedding create --provider openai --model voyage/x --text hi`. Base prints the generic failure and Doctor hint, this change prints the existing message; text mode, JSON stdout and exit codes are identical, and neither side made a network call (positive control confirmed the watcher). Vitest-source: four cases fail on base, 118 pass here; typecheck, full build and packed smoke pass. Receipts: #199639 (comment).

Thanks @Leon-SK668.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…law#199639)

fix(cli): report infer preflight errors through the expected-error path

`openclaw infer ... --json` threw plain errors for three checks that run before any request (web fetch disabled, a pinned web fetch provider that is unavailable, and an embedding `--provider` that conflicts with the provider in `--model`), so `--json` stderr showed the generic failure plus the Doctor hint instead of the existing message. The three checks now use the expected-error path with the same messages, following openclaw#198662. No new text.

Evidence: host, isolated config, no network or provider credentials. Source CLI with --json and in text mode: `infer web fetch --url https://example.invalid` with web fetch disabled, `infer web fetch --url ... --provider nosuch`, and `infer embedding create --provider openai --model voyage/x --text hi`. Base prints the generic failure and Doctor hint, this change prints the existing message; text mode, JSON stdout and exit codes are identical, and neither side made a network call (positive control confirmed the watcher). Vitest-source: four cases fail on base, 118 pass here; typecheck, full build and packed smoke pass. Receipts: openclaw#199639 (comment).

Thanks @Leon-SK668.

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 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