Skip to content

fix(hooks): hooks --agent errors print only "The CLI command failed." when the flag comes before the subcommand - #190366

Merged
obviyus merged 3 commits into
openclaw:mainfrom
yxshee:fix/hooks-parent-agent-errors
Nov 3, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
yxshee:fix/hooks-parent-agent-errors

Conversation

@yxshee

@yxshee yxshee commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw hooks --agent <id> <subcommand> hides the existing validation reason behind The CLI command failed. when the parent agent is blank or the subcommand does not accept it. Equivalent leaf-option errors already display their reason.

User Impact

Both parent preAction failures now print their existing specific diagnostic. Exit codes remain 1 and JSON error envelopes are unchanged. Valid invocations and leaf-option diagnostics retain their current behavior.

Why This Change Was Made

Factor the existing hooks failure formatter unchanged and raise the existing dependency-light ExpectedCliError class from the two preAction checks. Those checks run outside the action wrapper, so plain Error incorrectly reaches the generic root renderer.

No new production message wording, dependency, public API, policy, configuration or storage behavior. This reuses the owner introduced by #189993, following #191295's expected-condition classification pattern. Current main was integrated for that touched-owner move, not merely because it advanced.

Original fix by @yxshee; their original commit is retained.

Evidence

Independently built main 19fc93a4f2ac85acd6e5f0986e1f461816a912ce and the main-integrated candidate in secretless Linux arm64 Node 24.22.1 Docker, using fresh isolated profiles/config/state/workspaces.

  • Blank parent agent and unsupported parent agent/install, each main twice: generic root failure; candidate twice: the exact existing specific reason. All exit 1.
  • Both validations also exercised with hooks --json: identical failure JSON and existing raw messages; only human stderr framing changes.
  • Valid parent/leaf hooks list --json invocations exit 0, have clean stderr and return unchanged complete reports after normalizing only fixture/artifact paths. Blank leaf-agent control remains unchanged, including exit 1 and exact diagnostic.
  • Config bytes unchanged; rejected installation creates no hook-pack path.
  • 34 focused tests passed across hooks toggle/metadata and command suites. On main the two parent classification regressions fail as intended (20 other toggle cases pass). Targeted Oxlint/Oxfmt pass.
  • Simplification shares the existing validation matrix without dropping dispatch/write guards: production +16/-10 (net +6), tests +10/-11 (net −1), docs +4/-0 against merge base.

Detailed captured output and controls: independent proof comment.

Merge Danger

Two-way door: reverting restores the previous error classification; no migration or persistent-format change. Blast radius is human error framing for invalid parent hooks --agent usage and reuse of the existing hooks formatter. Command admission, successful behavior, exit statuses, JSON messages and sanitization policy remain unchanged.

@clawsweeper

clawsweeper Bot commented Nov 1, 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: S labels Nov 1, 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 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves specific validation reasons when hooks receives an invalid parent --agent option.

Example: Run openclaw hooks --agent ' ' list.

  • Before: The CLI prints “The CLI command failed.” and exits 1.
  • After: The CLI prints “Error: --agent must not be blank” and exits 1.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused, correct repair with shipped-command before/after evidence and meaningful regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied isolated built-CLI comparison exercises both changed preAction refusals and the extracted action formatter, showing specific stderr, unchanged exit 1 and JSON, successful controls, and no configuration or installation effects.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An invalid parent --agent option hides the actionable validation reason behind a generic CLI failure.
Reason: Restores existing diagnostics without changing wording, defaults, accepted inputs, configuration, or command permissions.

Merge readiness

✅ Ready for maintainer review

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

Priority: P2
Reviewed head: 018f68029300d390d660208026179816dd6ecee0

Before merge

None.

Findings

None.

Agent review details

How this fits together

Commander validates hooks options before dispatch; expected errors reach the root CLI renderer, which produces human stderr and optional JSON failure output.

flowchart TD
  A[Hooks CLI arguments] --> B[Commander parent validation]
  B --> C[Shared hooks failure formatter]
  C --> D[Expected CLI error]
  D --> E[Root failure renderer]
  E --> F[Human stderr and JSON stdout]
Loading

Technical review

Best possible solution:

Land the existing error-classification fix once the required checks pass.

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

Current-main source shows both plain errors bypassing the hooks wrapper, and the supplied built-CLI comparison reproduces both generic failures on the baseline.

Is this the best way to solve the issue?

This is the smallest complete fix: classify both refusals through the existing expected-error owner while sharing the established hooks formatter.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Parent agent validation keeps the original intent (1c055ba: Reject unsupported parent agent scoping rather than imply an agent-scoped configuration write; subsequent validation also rejects blank selectors.)
  • Root-owned report failures keeps the original intent (5e253f4: Preserve canonical JSON errors while the root renderer owns report failure output.)
  • Human failure formatting keeps the original intent (fbd7cbc: Keep multiline recovery instructions readable while stripping terminal controls; later terminalText consolidation retains that policy.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Focused introduced change: The pinned introduced diff extracts the existing formatter unchanged and uses it for two preAction refusals; accepted inputs and dispatch conditions remain unchanged. (src/cli/hooks-cli.ts:380, 018f68029300)
  • Current main still needs the fix: Current main throws plain Error from both parent-option checks, outside the action wrapper; the root renderer displays specific human output for ExpectedCliError. (src/cli/hooks-cli.ts:417, d921a2bfcc4e)
  • Shipped CLI proof: obviyus supplied before/after built-CLI output in isolated Linux arm64 Node 24.22.1 Docker for both refusals, unchanged JSON, valid parent/leaf controls, unchanged config bytes, and rejected-install non-effects: fix(hooks): hooks --agent errors print only "The CLI command failed." when the flag comes before the subcommand #190366 (comment). (018f68029300)
  • Preserved historical contracts: The original parent guard intentionally rejected unsupported agent scoping; the later formatter preserved multiline remedies and stripped terminal controls. This PR retains both contracts. (src/cli/hooks-cli.ts:419, fbd7cbc464b1)
  • Exact-head workflow state: GitHub reports this PR mergeable, with the CI gate pending; inspected check runs contain no failure, timeout, or action-required conclusion. (018f68029300)
  • Policy and history inspection: Root and docs ancestor guidance were applied; no maintainer-notes directory exists. Scoped history identifies the relevant guard and formatter changes; extended follow-history encountered the documented lazy-fetch limit at older history. (AGENTS.md:1, 018f68029300)

Likely related people:

  • Peter Steinberger: Raw commit 5e253f4 adds src/cli/hooks-cli.ts:225 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5e253f4f42b7; files: src/cli/hooks-cli.ts)

PR surface

Source +6, Tests -1, Docs +4. Total +9 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 16 10 +6
Tests 1 10 11 -1
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 30 21 +9

Review metrics

Metric Value Why it matters
Production versus test LOC Production +16/-10; tests +10/-11 The small production increase shares the existing formatter across action and preAction failures; the regression matrix consolidates existing coverage.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Invalid advanced CLI usage hides its specific reason, while command rejection and exit status remain correct.
  • 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-01T13:59:21.200Z sha 27b6be1 :: needs maintainer review before merge. :: none

Reviewed November 3, 2026, 1:37 AM ET / 06:37 UTC (Revision 2).

@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Independent built-CLI hooks validation proof

Final head: 018f68029300d390d660208026179816dd6ecee0. Baseline main: 19fc93a4f2ac85acd6e5f0986e1f461816a912ce. Original fix by @yxshee, commit 27b6be1d78b6cd6363b20f9d46e4a9472418fe18, retained. Ownership checked: unassigned contributor PR, maintainer edits enabled, sole contributor commit mapped to @yxshee.

Integrated current main because #189993 had moved the shared ExpectedCliError class to its dependency-light owner in the touched files. The built candidate includes that owner; the final follow-on commit changes only test consolidation and documentation. No dependency, policy, or public API change.

No new diagnostic wording

Both validation strings below already exist on main, unchanged. The Error: prefix, terminal-control sanitization and multiline formatter also move unchanged from the existing hooks action wrapper. The fix classifies the two preAction refusals as ExpectedCliError instead of plain Error; it does not replace generic output with newly invented text.

Shipped-command comparison

Independently built runtime artifacts in secretless Linux arm64 Node v24.22.1 Docker. Each run has fresh task-owned profile/home/config/state/workspace, an explicit main agent and synthetic owner profile. The built CLI confirms its configuration path. No Gateway, external provider, paid service or contributor code runs on the host.

For each affected validation, main twice prints the generic root failure; candidate twice prints the existing reason; exit remains 1:

$ openclaw hooks --agent ' ' list
main 1/2:
[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw --profile <task-profile> doctor`.

candidate 1/2:
Error: --agent must not be blank
$ openclaw hooks --agent main install ./hook-pack
main 1/2:
[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw --profile <task-profile> doctor`.

candidate 1/2:
Error: openclaw hooks install does not support --agent; the option only selects an owner for read-only hook reports.

The same four before/after comparisons were also run with parent hooks --json. Stdout retains the identical existing JSON failure envelope and raw message, while stderr changes from generic failure to the specific human reason:

{"ok":false,"error":{"type":"cli_error","message":"--agent must not be blank"}}

For unsupported install, error.message is exactly the existing unsupported-option string above on both references.

Controls

Across main1/main2/candidate1/candidate2:

  • hooks --agent main list --json: exit 0, clean stderr, unchanged complete hook-report JSON.
  • hooks list --agent main --json: the same successful report, exit 0 and clean stderr.
  • hooks list --agent ' ': unchanged existing Error: --agent must not be blank, exit 1 and empty stdout. This also exercises the existing action-wrapper formatter after extraction.

Successful report comparison normalizes only independently created fixture-root and build-artifact paths; all other JSON, stderr and exit fields compare equal across all four runs. Config bytes remain unchanged in each run and the rejected install creates no hook-pack path.

Focused checks and simplification

  • 34 tests pass in hooks-cli.toggle.test.ts and hooks-cli.test.ts, including multiline/control-character formatter checks and dispatch/write guards.
  • Same updated toggle regression on main: 2 intended failures / 20 pass. Both parent cases still throw plain Error rather than ExpectedCliError; the existing leaf case passes.
  • Targeted Oxlint: zero warnings/errors. Oxfmt passes for all changed source/tests/docs.
  • Shared one existing validation matrix across blank leaf, blank parent, and unsupported parent usage, retaining ExpectedCliError identity, exact human output and all no-dispatch/no-write checks. Raw JSON wording is independently checked through the actual CLI above.
  • Whole-change deltas against merge base: production +16/-10 (net +6), tests +10/-11 (net −1), docs +4/-0. No new outward-facing error text, export, configuration, permission or storage behavior.

@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XS and removed size: S labels Nov 3, 2026
@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 3, 2026
@obviyus
obviyus merged commit 18bf241 into openclaw:main Nov 3, 2026
120 of 125 checks passed
@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Landed in 18bf241. Thanks @yxshee. hooks commands now show their specific validation errors.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 4, 2026
… when the flag comes before the subcommand (openclaw#190366)

fix(cli): show existing hooks validation errors instead of the generic failure



Two `hooks` command validations already had specific error messages, but the root CLI replaced them with the generic "The CLI command failed." output. These validations now raise `ExpectedCliError`, the same way as openclaw#189993 and openclaw#191295, so users see the specific reason. The message text, exit code (1) and JSON envelopes are unchanged.

Evidence: built CLI in secretless Node 24.22.1 Docker. Both validations showed the generic failure on main twice and the specific reason with this change twice, with exit code 1. Valid parent and leaf invocations, JSON output and the existing leaf diagnostic were unchanged. Details: openclaw#190366 (comment).

Thanks @yxshee.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 4, 2026
…e2e (#192621)

#190366 made hooks --agent "" print its own error; this e2e case still expected the generic failure.

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

openclaw#190366 made hooks --agent "" print its own error; this e2e case still expected the generic failure.

Co-authored-by: obviyus <[email protected]>
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 docs Improvements or additions to documentation 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