Repository navigation
fix(models): surface --agent blank-guard remedy on the routed fast path - #198975
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR classifies the blank --agent guard as an expected CLI error so its explanation reaches the terminal. Example: Run openclaw models status --agent " ".
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0. Total 0 across 1 file. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed November 14, 2026, 11:25 AM ET / 16:25 UTC (Revision 3). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Independent proof at ea4c7cc against base aedf9cc. Host eligibility checked: Tiers: vitest-source and source. Fresh isolated task home/state/config, explicit p198975proof profile; no Gateway started and no live state used. 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. |
|
Landed in 54484fa. Thanks @SunnyShu0925. |
…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]>
What Problem This Solves
openclaw models status --agent " "andopenclaw 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.resolveModelsTargetAgentinsrc/commands/models/shared.ts:235throws a plainError. On the Commander-registered path (e.g.models auth login) therunCommandWithRuntimewrapper catches and re-renders it; but theroute.tsfast path formodels-status/models-list(route.ts:488-495) usesdefineRoutedCommandwhich 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 printshumanOutputfor expected CLI errors; for plainErrorit falls through to the generic failure block, yielding the two-line collapse on text mode. The json envelope keeps the message viaformatCliOperatorErrorfallback, but the stderr path also collapses.throw new Error(...)with the canonicalthrowExpectedCliError(...)already imported and used on line 41 of the same file.src/commands/models/shared.ts— one throw-site swap, import already present.messagefield, 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
ExpectedCliErrorcarrieshumanOutputandmachineOutputfields, andformatCliFailureLines/formatCliJsonFailureprint them verbatim. Reusing the canonicalthrowExpectedCliErrorowner is the established per-site remedy for this exact anti-pattern. The file already imports it on line 41 wherethrowExpectedCliError("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.throwExpectedCliErrorpattern is already adopted across the repo for the same reason (see sibling anchors below).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 anExpectedCliErrorfor the text channel to print. (2) Addmodelsto the show-reason whitelist infailure-output.ts— would print raw reasons for everymodelsfailure, including unforeseen internal errors that should stay collapsed. Both rejected.ExpectedCliErrorconstructor inexpected-cli-error.ts:27-28setshumanOutput: messageandmachineOutput: 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 oninstanceof Errorspecifically to strip remedies — but the failure renderer code path (handleCliUncaughtException→formatCliFailureLines) already knows how to handle both variants.User Impact
Operators who pass
--agent " "tomodels statusormodels listnow see the actionable--agent must not be blankmessage 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--jsonenvelope 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)Error, baseorigin/main)ExpectedCliError, this head)models status --agent " "text mode[openclaw] The CLI command failed.+ doctor hint; remedy invisible--agent must not be blankprinted verbatimmodels status --agent " " --jsonenvelopemessage: "--agent must not be blank"preserved via fallbackmachineOutput)models list --agent " "text modeLive 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):TEXT lane collapse: ✗ remedy invisible. JSON envelope: message preserved via
formatCliOperatorErrorfallback.FIXED arm (
throwExpectedCliError, this PR head):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."). ThethrowExpectedCliErrorowner (expected-cli-error.ts:27-28) constructs: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-remedyanchor, each a one-line swap at a separate throw-site, already merged or open:fix(dns): surface conflict remedies when DNS providers disagree(fix(dns): dns setup prints only "The CLI command failed." when no domain is configured #192127, merged) — canonical per-site pattern for this anti-patternfix(models): surface the auth login device-code conflict remedy(fix(models): surface the auth login device-code conflict remedy #198333, open) — sibling Commander path, identical one-line swapfix(cli): show session-target remedies for attach failures(fix(cli): show session-target remedies for attach failures #198345, open) — samethrowExpectedCliErrorowner, per-site onsession-target.tsOpen 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 touchessrc/cli/models-cli.ts(Commander registration path, disjoint hunk); #198345 touches onlysession-target.ts. Zero collision.What was not tested
build-all.mts plugins:assets:buildphase fails in this environment due to an unrelateddompurifyresolution inmarkdown-view.ts, which is absent from the worktree and appears to be a shared node_modules issue). The tsdown build step — which emitsdist/entry.jsand all runtime chunks — succeeds independently, so the shipped launcher proof is valid; the plugin-assets phase is unrelated to the models command path.openclaw@latestbinary — 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.throwExpectedCliErrorswap and would be its own PR.