Skip to content

fix(models): surface --agent blank-guard remedy on the routed fast path - #198975

Merged
obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/models-route-remedy-419
Nov 14, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/models-route-remedy-419

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw models status --agent " " and openclaw models list --agent " " reject the blank flag but collapse the text channel to a generic two-line failure — the remedy the guard already composed (--agent must not be blank) never reaches the operator on the route fast path. When an operator accidentally passes --agent " " (common in shell scripts with --agent "$AGENT_NAME" where the variable is unset), they see only [openclaw] The CLI command failed. plus a doctor hint, not the actionable hint about what went wrong.

  • Problem: resolveModelsTargetAgent in src/commands/models/shared.ts:235 throws a plain Error. On the Commander-registered path (e.g. models auth login) the runCommandWithRuntime wrapper catches and re-renders it; but the route.ts fast path for models-status / models-list (route.ts:488-495) uses defineRoutedCommand which awaits the command function directly with no wrapper, so the raw Error bubbles to the root failure renderer. formatCliFailureLines (failure-output.ts:264-266) only prints humanOutput for expected CLI errors; for plain Error it falls through to the generic failure block, yielding the two-line collapse on text mode. The json envelope keeps the message via formatCliOperatorError fallback, but the stderr path also collapses.
  • Solution: Replace throw new Error(...) with the canonical throwExpectedCliError(...) already imported and used on line 41 of the same file.
  • What changed: src/commands/models/shared.ts — one throw-site swap, import already present.
  • What did NOT change: The guard condition, the message text, the exit code, the Gateway bootstrap chain, the json envelope message field, and every Commander-registered command path that already handled the plain Error correctly.

Why This Change Was Made

The failure renderer already owns the remedy-printing contract: an ExpectedCliError carries humanOutput and machineOutput fields, and formatCliFailureLines / formatCliJsonFailure print them verbatim. Reusing the canonical throwExpectedCliError owner is the established per-site remedy for this exact anti-pattern. The file already imports it on line 41 where throwExpectedCliError("Choose either --json or --plain, not both.") handles a sibling guard in the same function family — so this is not a new dependency or a new design decision, just finishing a partial adoption.

  • Best fix: This is the best approach — single throw-site swap, zero new imports, zero new types, zero behavior change outside the text-channel remedy print. The per-site throwExpectedCliError pattern is already adopted across the repo for the same reason (see sibling anchors below).
  • Alternative: (1) Wrap route.ts routed commands with runCommandWithRuntime — wider blast radius across every routed command, not just this one guard, and the wrapper's re-throw path would still need the error to be an ExpectedCliError for the text channel to print. (2) Add models to the show-reason whitelist in failure-output.ts — would print raw reasons for every models failure, including unforeseen internal errors that should stay collapsed. Both rejected.
  • Risk: Very low. The ExpectedCliError constructor in expected-cli-error.ts:27-28 sets humanOutput: message and machineOutput: message, so both renderer lanes receive the identical remedy string verbatim. The exit code stays 1. Sibling guards in the same file already use this pattern (line 41). The only edge case would be if some downstream code pattern-matches on instanceof Error specifically to strip remedies — but the failure renderer code path (handleCliUncaughtException → formatCliFailureLines) already knows how to handle both variants.

User Impact

Operators who pass --agent " " to models status or models list now see the actionable --agent must not be blank message directly instead of a generic failure and a doctor hint. Valid invocations are untouched; the command still exits 1. Both the text channel stdout and the --json envelope message carry the remedy. This reduces the cycle of "failed → doctor → search logs → understand" down to "failed → read remedy → fix flag → retry" for a common scripted-onboarding misconfiguration.

Evidence

Before/after comparison (shipped built launcher, openclaw.mjs)

Case Before (plain Error, base origin/main) After (ExpectedCliError, this head)
models status --agent " " text mode [openclaw] The CLI command failed. + doctor hint; remedy invisible --agent must not be blank printed verbatim
models status --agent " " --json envelope message: "--agent must not be blank" preserved via fallback identical envelope (both lanes lift from machineOutput)
models list --agent " " text mode same generic collapse same remedy line printed
valid agent (control) normal status output (exit 0) byte-identical normal status output (exit 0)

Live proof — real shipped launcher (node openclaw.mjs, built tsdown dist)

Both arms were built from the same source tree by toggling the single throw-site at src/commands/models/shared.ts:235: revert our commit → tsdown build → run BASE; restore commit → tsdown build → run FIXED. This exercises the identical code path a user's installed binary runs — openclaw.mjs → dist/entry.js → route.ts → resolveModelsTargetAgent → root failure renderer.

BASE arm (plain Error, git revert --no-commit ea4c7ccc8f9):

$ node openclaw.mjs models status --agent " "
[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw doctor`.

$ node openclaw.mjs models status --agent " " --json
{ "ok": false, "error": { "type": "cli_error", "message": "--agent must not be blank" } }

TEXT lane collapse: ✗ remedy invisible. JSON envelope: message preserved via formatCliOperatorError fallback.

FIXED arm (throwExpectedCliError, this PR head):

$ node openclaw.mjs models status --agent " "
--agent must not be blank

$ node openclaw.mjs models status --agent " " --json
{ "ok": false, "error": { "type": "cli_error", "message": "--agent must not be blank" } }

TEXT lane: ✓ remedy printed verbatim. JSON envelope: identical message field (both lift from machineOutput).

What changed (one-line swap)

  const requested = rawAgentId?.trim();
  if (rawAgentId !== undefined && !requested) {
-   throw new Error("--agent must not be blank");
+   throwExpectedCliError("--agent must not be blank");
  }

Sibling on line 41 of the same file already uses throwExpectedCliError("Choose either --json or --plain, not both."). The throwExpectedCliError owner (expected-cli-error.ts:27-28) constructs:

throw new ExpectedCliError({ message, humanOutput: message, machineOutput: message });

So both renderer lanes receive the identical remedy string verbatim.

Same-anchor precedent (canonical per-site pattern)

Fixes on the identical cli-guard-plain-error-hides-remedy anchor, each a one-line swap at a separate throw-site, already merged or open:

Open PR collision check (2026-11-14 sweep)

Scanned open PRs from the author's 18 open PRs and the 60 most recent repo PRs, compared changed-file lists. No open PR modifies src/commands/models/shared.ts. #198333 touches src/cli/models-cli.ts (Commander registration path, disjoint hunk); #198345 touches only session-target.ts. Zero collision.

What was not tested

  • A full upstream build (the build-all.mts plugins:assets:build phase fails in this environment due to an unrelated dompurify resolution in markdown-view.ts, which is absent from the worktree and appears to be a shared node_modules issue). The tsdown build step — which emits dist/entry.js and all runtime chunks — succeeds independently, so the shipped launcher proof is valid; the plugin-assets phase is unrelated to the models command path.
  • End-to-end through a real published openclaw@latest binary — the fix is a one-line swap in source, the source and built launcher both exercise the same guard → renderer chain; the gap is only the publication boundary.
  • All sibling same-anchor throw-sites (BUG-414/416/417/420/421/422/423/398) — each is a separate per-site throwExpectedCliError swap and would be its own PR.

resolveModelsTargetAgent throws a plain Error when the operator passes
a blank --agent flag. On the Commander path the guard goes through
runCommandWithRuntime, which routes the remedy to both text and json
channels correctly. But on the route.ts fast path (models-status,
models-list), the raw Error bubbles directly to the failure renderer
without any envelope recognition — both text and json channels collapse
to the generic two-line failure.

The fix replaces throw new Error(...) with throwExpectedCliError(...),
the canonical owner already imported and used on line 41 of the same
file. ExpectedCliError carries humanOutput and machineOutput that the
root renderer already knows how to print on both channels:
formatCliFailureLines (L264-266) returns humanOutput for text mode, and
formatCliJsonFailure (L185-186) lifts machineOutput into the json
envelope. One-line change, import already present, message verbatim.
@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 commands Command implementations 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 classifies the blank --agent guard as an expected CLI error so its explanation reaches the terminal.

Example: Run openclaw models status --agent " ".

  • Before: The CLI prints a generic failure and a Doctor hint.
  • After: The CLI prints --agent must not be blank and still exits 1.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct diagnostic repair with production-entry proof; automated selector coverage still checks wording rather than the changed rendering contract.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Built-launcher output and the collaborator's pinned, isolated CLI traces exercise the changed selector through models status and the natural models list fallback, showing visible guidance, unchanged JSON payloads, exit 1, and successful valid-agent controls.
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 operator passing a blank agent to models status receives a generic failure instead of the existing explanation identifying the invalid flag.
Reason: The change restores actionable diagnostics through the established error contract without changing agent selection, defaults, permissions, or configuration.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current diagnostic defect with the existing error helper. No introduced correctness or security defects were found; exact-head CI remains in progress.

Priority: P3
Reviewed head: ea4c7ccc8f99c4070f089cdc38ca116aac661b31

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped-entry scenario is missing for this diagnostic change; the unchanged selector test does not provide an automated red-on-base classification regression.
Agent review details

How this fits together

The models command resolves an agent before inspection; rejected arguments flow through the CLI failure renderer to terminal diagnostics and JSON error output.

flowchart LR
  A[CLI arguments] --> B[Models command route]
  B --> C[Agent selector]
  C --> D[Expected CLI error]
  D --> E[Root failure renderer]
  E --> F[Terminal and JSON output]
Loading

Technical review

Best possible solution:

Retain the one-site expected-error classification and let the existing renderer expose the unchanged argument explanation.

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

Current-main source shows the blank-selector plain Error reaching a renderer that suppresses ordinary error reasons for models commands; supplied before/after launcher traces corroborate that path.

Is this the best way to solve the issue?

The one-line change is the smallest complete repair: preserve blank-input rejection and selection policy while using the existing expected-error owner, without widening global error disclosure.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Blank-agent rejection in model command selection keeps the original intent (1ef2ebf: The merged selection repair distinguished explicit blank selectors from omitted selectors while honoring system-agent reads and explicit credential ownership.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 1ef2ebf adds src/commands/models/shared.ts:158 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1ef2ebf11468; files: src/commands/models/shared.ts)
  • Vincent Koc: Raw commit e66aa35 adds src/commands/models/shared.ts:167 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e66aa357f85b; files: src/commands/models/shared.ts)

PR surface

Source 0. Total 0 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 1 1 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 status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on maintainer: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This improves diagnostics for an invalid argument in an advanced CLI workflow; valid commands and rejection behavior remain intact.
  • 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.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Optionally strengthen the existing selector case to protect visible expected-error guidance, demonstrating failure on the base and success on the head.

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 (2 earlier review cycles)
  • reviewed 2026-11-14T15:49:41.872Z sha ea4c7cc :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-14T16:11:00.603Z sha ea4c7cc :: blocked before merge. :: none

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

@SunnyShu0925
SunnyShu0925 marked this pull request as ready for review November 14, 2026 16:03
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@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. 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 rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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
@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. labels Nov 14, 2026
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Independent proof at ea4c7cc against base aedf9cc. Host eligibility checked: git diff --name-only $(git merge-base origin/main HEAD)...HEAD changes only src/commands/models/shared.ts, no install/scripts/hooks surface. All execution through ocx on host. No host git hook ran. No edits/push needed; after-push.sh ran. Contributor SunnyShu [email protected] is author and committer; no agent trailers. Production +1/-1, tests unchanged.

Tiers: vitest-source and source. Fresh isolated task home/state/config, explicit p198975proof profile; no Gateway started and no live state used.

ocx test src/commands/models/shared.test.ts
base: 4 passed, exit 0
candidate: 4 passed, exit 0
(existing wording test is not a classification regression; no new test claimed)

ocx src -- --profile p198975proof models status --agent " " [--json]
base text + JSON stderr: The CLI command failed. + Doctor hint
candidate text + JSON stderr: --agent must not be blank
all exit 1; text stdout empty; JSON unchanged:
{"ok":false,"error":{"type":"cli_error","message":"--agent must not be blank"}}

ocx src -- --profile p198975proof models list --agent " " [--json]
both first print Gateway is not running. Showing the local cached model catalog...
text: BOTH already print --agent must not be blank, exit 1
JSON: base stderr generic + Doctor; candidate stderr --agent must not be blank
JSON payload unchanged, exit 1

controls: models status --agent main [--json]; models list --agent main [--json]
both commands exit 0 on both sides; status reports same missing auth/runtime;
list reports same local gemma model and capabilities.

Boundary correction: status resolves the target at list.status-command.ts:224 before readModelCatalog at :228. List does NOT reject before every Gateway call: list.list-command.ts:53-65 reads connection config and attempts readSelectedGatewayModelCatalog, then its local fallback invokes resolveModelsTargetAgent at :96. This proof reaches that natural fallback with no running Gateway. Validation order/selection is deliberately unchanged, as is the already-visible text-mode list error.

Raw combined stdout/stderr and exit-code receipts retained in proofs/198975. Fork workflow approvals were supplied by the lead. The previous review's sole blocker was awaiting those approvals; no code findings and regression strengthening was explicitly optional.

@obviyus
obviyus merged commit 54484fa into openclaw:main Nov 14, 2026
222 of 227 checks passed
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Landed in 54484fa. Thanks @SunnyShu0925.

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

fix(cli): show the blank --agent error for openclaw models

`openclaw models status --agent " "` threw a plain error for a blank agent, so text mode printed only "The CLI command failed." and the doctor hint instead of the existing "--agent must not be blank". It now throws the same message through the existing expected-CLI-error path. Agent selection is unchanged. No new text.

Evidence: source tier with isolated state, text and --json. `models status --agent " "`: base printed only the generic failure; this change prints the existing message, with JSON and exit code unchanged. `models list --agent " "` reaches the guard only after its Gateway fallback and already showed the message; it is unchanged. A real agent ID behaves the same on both. Existing tests pass on both sides. Receipts: openclaw#198975 (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

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. commands Command implementations P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants