Skip to content

fix(models): surface the --json/--plain conflict as an ExpectedCliError - #196382

Merged
obviyus merged 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/models-json-plain
Nov 10, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/models-json-plain

Conversation

@wangmiao0668000666

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: openclaw models list --json --plain (and models status --json --plain) prints only The CLI command failed. For help, run openclaw doctor. instead of the option-conflict reason. The real message (Choose either --json or --plain, not both.) was hidden from human output.

User Impact

User impact: the option-conflict reason is now printed instead of the generic failure line, with the same exit code 1. --json machine output and the exit code are unchanged; no new wording.

Why This Change Was Made

ensureFlagCompatibility rejects --json combined with --plain by throwing a bare Error, which the CLI failure handler classifies as unexpected and replaces with the generic line in human output for the route-first models list/models status commands. Throwing an ExpectedCliError instead lets the human output carry the option-conflict reason, matching the sibling --probe/--plain check (in list.status-command.ts) and the invalid provider check (in list.list-command.ts) in the same command family.

Evidence

Discriminating regression (src/commands/models/list.prepared-catalog.test.ts): the new rejects --json with --plain as an ExpectedCliError case asserts the rejection is an ExpectedCliError with the option message.

  • BASE (throw new Error(...)): test fails — rejection is a plain Error, not an ExpectedCliError.
  • HEAD (this change): 16/16 tests in the file pass.

Real CLI proof through the supported shipped launcher (node openclaw.mjs, built dist, Node 24, isolated HOME), same build with only the throw changed:

Before (base):

$ openclaw models list --json --plain; echo $?
[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw doctor`.
1

After (head):

$ openclaw models list --json --plain; echo $?
Choose either --json or --plain, not both.
1

--json machine output is unchanged ({ "ok": false, "error": { "type": "cli_error", "message": "Choose either --json or --plain, not both." } }).

Test-line budget: 7 added lines, allocated in config/test-lines-allocations/models-json-plain-conflict.txt.

Maintainer options

Scope and alternatives

Narrow change to one shared option-compatibility helper plus its regression; JSON schema and exit codes unchanged.

Alternatives considered:

  • Keeping the bare throw: leaves the option-conflict reason hidden in human output.
  • Wrapping at the CLI boundary: the ExpectedCliError contract already exists for exactly this and is what sibling model commands use.

models list/status reject --json with --plain through a bare Error, which
the CLI failure handler swallows into "The CLI command failed." for the
route-first commands. Throwing an ExpectedCliError lets the human output
carry the option-conflict reason, matching the sibling --probe/--plain
check and the invalid-provider check in the same file.
@clawsweeper

clawsweeper Bot commented Nov 10, 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 10, 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: 🦞 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR displays the existing explanation when model commands receive both --json and --plain.

Example: Run openclaw models list --json --plain.

  • Before: Stderr shows a generic command failure and Doctor suggestion; exit code is 1.
  • After: Stderr shows “Choose either --json or --plain, not both.”; JSON output and exit code remain unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with shipped-entry-point proof, a discriminating regression, and no open findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Built node openclaw.mjs runs in isolated, secretless Docker exercise list and status with conflicting flags, show the corrected stderr, preserve JSON and exit code 1, and include successful single-flag 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: Conflicting model output flags produce a generic failure instead of explaining which flags to remove.
Reason: The patch restores an actionable existing diagnostic through the established error contract, with direct involvement from the shared-helper contributor.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current CLI diagnostic bug with a focused change and convincing built-CLI proof; no actionable defects were found.

Priority: P2
Reviewed head: 025f74e97fc46d7c310a453436af0bfd446cf526

Before merge

None.

Findings

None.

Agent review details

How this fits together

Model CLI commands pass output flags to a shared validator, and the root CLI failure handler renders its rejection as human-readable stderr and optional JSON.

flowchart TD
  A[CLI output flags] --> B[Model list or status]
  B --> C[Shared flag validator]
  C --> D[ExpectedCliError]
  D --> E[CLI failure renderer]
  E --> F[Conflict message and exit 1]
Loading

Technical review

Best possible solution:

Use the existing expected-error contract in the shared validator while preserving the rejection message, JSON envelope, and exit code.

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

Current-main source establishes the bare-error path, and supplied built-CLI output demonstrates the failure for both commands; this review ran no target code.

Is this the best way to solve the issue?

This is the smallest complete repair: change the error classification at the existing shared owner and extend its existing command-boundary regression.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 48beb4002e65.

Provenance checked

  • Shared output-flag rejection changes intended behavior with a stated reason (734bb6b: The original models helper rejected mutually exclusive output formats; refactor(models): retire duplicate auth and catalog test seams #144589 later relocated that guard without changing behavior.)
  • Existing invalid-options test table keeps the original intent (155bcec: The prior test consolidation retained invalid-option coverage while reducing redundant scaffolding; this PR strengthens that same table.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 82c306d adds src/commands/models/shared.ts:45 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 82c306d924c0; files: src/commands/models/shared.ts)
  • Peter Steinberger: Raw commit 734bb6b adds src/commands/models/shared.ts:32 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 734bb6b4fd9a; files: src/commands/models/shared.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 2 1 +1
Tests 1 3 3 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 5 4 +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:

  • P2: A bounded CLI diagnostic bug hides an actionable option-conflict explanation without changing successful commands or stored state.
  • 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-10T02:10:56.908Z sha 0e5d6c7 :: needs maintainer review before merge. :: none

Reviewed November 9, 2026, 9:46 PM ET / November 10, 2026, 02:46 UTC (Revision 2).

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Proof on built CLIs (pnpm build, node openclaw.mjs), node 24.22.1 in Docker, no secrets, isolated HOME and state dir. main 426543e9 vs this PR's fix, each run once.

openclaw models list --json --plain and openclaw models status --json --plain

main, stderr, exit 1 (both commands):

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

this PR, stderr, exit 1 (both commands):

Choose either --json or --plain, not both.

The JSON error on stdout ({"ok": false, "error": {"type": "cli_error", "message": "Choose either --json or --plain, not both."}}) is byte-identical on main and this PR.

Controls: stdout, stderr and exit code were identical on main and this PR (after normalizing temp paths, profile name and pids) for:

Tests: I removed the allocation file and folded the check into the existing invalid-options table in list.prepared-catalog.test.ts (it now asserts ExpectedCliError), so net test lines are 0. The file passes (15/15). With the production line reverted, the {"json":true,"plain":true} row fails.

@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. 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 10, 2026
@obviyus
obviyus merged commit 1ebc46e into openclaw:main Nov 10, 2026
117 checks passed
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Landed in 1ebc46e. Thanks @wangmiao0668000666. models now shows the real --json/--plain conflict message.

github-actions Bot pushed a commit to tbohda2025/openclaw that referenced this pull request Nov 10, 2026
…or (#196382)

fix(models): surface the --json/--plain conflict as an ExpectedCliError

openclaw models list --json --plain and models status --json --plain threw a plain Error, so the CLI showed only the generic "The CLI command failed." line instead of the existing message "Choose either --json or --plain, not both." The shared option check now uses ExpectedCliError, as #196094 and #196081 did for related checks. The exit code and the JSON error on stdout are unchanged, and no text is new.

Evidence: built CLIs on node 24.22.1 in secretless Docker with an isolated HOME. Both commands with --json --plain printed only the generic failure line on main (exit 1) and the existing conflict message with this change (exit 1); the JSON error on stdout is byte-identical. list --json, list --plain, status --json, status --plain and status --probe --plain are identical on both. Details: openclaw/openclaw#196382 (comment).

Thanks @wangmiao0668000666.

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

fix(models): surface the --json/--plain conflict as an ExpectedCliError

openclaw models list --json --plain and models status --json --plain threw a plain Error, so the CLI showed only the generic "The CLI command failed." line instead of the existing message "Choose either --json or --plain, not both." The shared option check now uses ExpectedCliError, as openclaw#196094 and openclaw#196081 did for related checks. The exit code and the JSON error on stdout are unchanged, and no text is new.

Evidence: built CLIs on node 24.22.1 in secretless Docker with an isolated HOME. Both commands with --json --plain printed only the generic failure line on main (exit 1) and the existing conflict message with this change (exit 1); the JSON error on stdout is byte-identical. list --json, list --plain, status --json, status --plain and status --probe --plain are identical on both. Details: openclaw#196382 (comment).

Thanks @wangmiao0668000666.

Co-authored-by: Ayaan Zaidi <[email protected]>
@wangmiao0668000666
wangmiao0668000666 deleted the fix/models-json-plain branch November 11, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations 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