Skip to content

fix(cli): report unknown subcommands even with --help - #124707

Merged
steipete merged 4 commits into
mainfrom
steipete/help-unknown-subcommand
Aug 16, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/help-unknown-subcommand

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Adding --help to a mistyped nested command made Commander print the parent group's help and exit 0. The invalid token disappeared, so openclaw sessions lst --help looked like successful help for a valid command instead of reporting that lst does not exist.

Why This Change Was Made

Commander 15 checks its internal help hook before dispatching command actions and before its unknown-command branch. That ordering is especially important for OpenClaw's lazy placeholders: the placeholder must run its action and load the real child tree before OpenClaw can decide whether the token is a real subcommand.

The OpenClaw Commander adapter now records lazy placeholders, defers only their early help check, and classifies the token after the real tree has loaded. Unknown tokens then use the same canonical unknown-command formatter as the no-help form. Real child commands continue to render their own help normally. This keeps lazy registration lazy and adds no per-group command lists.

Production LOC: +56/-16 (net +40) | Tests: +77/-2

User Impact

<group> <unknown> --help now names the invalid subcommand, suggests a nearby real command when available, points to the parent group's help, and exits 1. Root, parent, real-subcommand, short-form, and help <command> output remain byte-identical and exit 0.

Evidence

Built-dist before and after

Both builds used source base 715c379fd949a9a77224a590e8d9016f88b62d0c, OPENCLAW_SKIP_CHANNELS=1, and an isolated temporary OPENCLAW_STATE_DIR on Blacksmith Testbox tbx_01m05rnzy10cbmgnebpvqgjhc8 (Actions run https://github.com/openclaw/openclaw/actions/runs/31960660687).

BEFORE
$ openclaw sessions lst --help
OpenClaw 2026.8.1 (715c379) — All your chats, one OpenClaw.
Usage: openclaw sessions [options] [command]
[parent sessions help]
[exit 0]

AFTER
$ openclaw sessions lst --help
OpenClaw sessions has no command "lst".
Did you mean this?
  openclaw sessions list
Try: openclaw sessions --help
Docs: https://docs.openclaw.ai/cli
[exit 1]
BEFORE
$ openclaw memory bogusxyz --help
OpenClaw 2026.8.1 (715c379) — All your chats, one OpenClaw.
Usage: openclaw memory [options] [command]
[parent memory help]
[exit 0]

AFTER
$ openclaw memory bogusxyz --help
OpenClaw memory has no command "bogusxyz".
Try: openclaw memory --help
Docs: https://docs.openclaw.ai/cli
[exit 1]

The normalized nested help form is consistent too:

$ openclaw help sessions bogusxyz
OpenClaw sessions has no command "bogusxyz".
Try: openclaw sessions --help
Docs: https://docs.openclaw.ai/cli
[exit 1]

Valid help is byte-identical

Invocation Before After stdout SHA-256
openclaw sessions list --help exit 0 exit 0 fd5e681456d8993d9d1d6bbbf9e17219fc932e1f3142eb9dc7f050ffed5f04bc
openclaw sessions --help exit 0 exit 0 e8aca473eb906102b4f673a51539abe20b5ad05ce6cb5438aefb31c5098089f1
openclaw --help exit 0 exit 0 6d0e4f8f41eade80f0a9876c1b77c67cc7b388dd4b620fe462394f216e1a38ad
openclaw -h exit 0 exit 0 6d0e4f8f41eade80f0a9876c1b77c67cc7b388dd4b620fe462394f216e1a38ad
openclaw help sessions exit 0 exit 0 e8aca473eb906102b4f673a51539abe20b5ad05ce6cb5438aefb31c5098089f1

Every valid case also had empty stderr before and after.

Tests and review

  • Pre-fix regression: reports an unmatched lazy subcommand before --help can hide it failed with received commander.helpDisplayed, expected commander.unknownCommand.
  • node scripts/run-vitest.mjs src/cli/program — 63 files, 1,117 tests passed.
  • pnpm build — passed; no ineffective dynamic-import warning.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted --stream-engine-output — clean, no accepted/actionable findings.
  • node scripts/check-changed.mjs selected core, coreTests, accepted the new assertion-safety comment, then stopped on unrelated shrink-only baseline drift already present on origin/main: src/state/control-ui-device-auth-migration.ts: 0 < 1 and ui/src/lib/nodes/index.ts: 3 < 4. This PR does not touch those files or the protected baseline.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 16, 2026 17:28
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S maintainer Maintainer-authored PR labels Aug 16, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 2:33 PM ET / 18:33 UTC.

ClawSweeper review

What this changes

The PR makes lazy CLI groups report an unknown nested subcommand followed by --help instead of showing successful parent help.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for maintainer review: the patch addresses a real lazy-CLI parsing gap with focused behavior coverage, but its private Commander 15 hook still needs exact-head dependency-contract and built-CLI confirmation before merge.

Priority: P2
Reviewed head: 5689d833cbccbd646c9dfc9c8d0f107f92bbf221

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has strong behavioral intent and useful runtime evidence, but the private dependency contract and final-head runtime proof remain unverified.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The repository state identifies this as a member-authored PR, so the external-contributor proof gate does not apply; the body nevertheless provides useful built-distribution terminal evidence, though it should be rerun on the final head.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies this as a member-authored PR, so the external-contributor proof gate does not apply; the body nevertheless provides useful built-distribution terminal evidence, though it should be rerun on the final head.
Evidence reviewed 7 items Current-main gap: Current main only reclassifies an excess-arguments error after Commander reaches error handling, so a help exit can occur first for a lazy placeholder.
Proposed owner-boundary repair: The PR defers help only for marked lazy placeholders, then lets the real loaded tree classify a child token; normal paths delegate to Commander through super.
Lazy registration and reparse caller: All lazy command groups use the marked placeholder helper, whose action replaces the placeholder and reparses root argv after registration.
Findings None None.
Security None None.

How this fits together

OpenClaw registers many CLI command groups lazily for startup speed. Commander initially parses a placeholder, which loads the real command tree and reparses arguments before OpenClaw formats help or unknown-command output.

flowchart LR
A[CLI arguments] --> B[Lazy command placeholder]
B --> C[Commander help check]
C --> D[Load real command tree]
D --> E[Reparse arguments]
E --> F[Valid command help]
E --> G[Unknown-command guidance]
Loading

Before merge

  • Resolve merge risk (P1) - The final patch depends on Commander 15’s private _outputHelpIfRequested contract; direct inspection of the resolved 15.0.0 source and an exact-head built-CLI run remain unavailable in this review environment.
  • Complete next step (P2) - The protected maintainer PR needs dependency-contract and final-head runtime validation, not an automated replacement repair.
Agent review details

Security

None.

PR surface

Source +42, Tests +76. Total +118 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 58 16 +42
Tests 3 78 2 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 136 18 +118

Review metrics

Metric Value Why it matters
Production versus test delta production +58/-16; tests/support +78/-2 The bug fix adds a narrowly scoped lazy-parser classification path plus behavioral regression coverage; the positive production growth is justified only if the private Commander contract is confirmed.

Merge-risk options

Maintainer options:

  1. Verify the pinned Commander hook (recommended)
    Run the built CLI on the exact head in an environment with commander 15.0.0 resolved, and confirm the private hook signature and pre-action ordering before merge.
  2. Accept the pinned private-hook risk
    Merge relying on the exact 15.0.0 pin while documenting that any Commander upgrade must revalidate this override.

Technical review

Best possible solution:

Keep the narrow lazy-placeholder deferral, then validate the exact head against resolved Commander 15 source and a built CLI before merge.

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

Yes: current source shows the help hook can exit before the existing post-error reclassification, and the PR supplies a concrete built-CLI before/after path for a lazy nested command.

Is this the best way to solve the issue?

Unclear: moving the decision to the lazy parser boundary is the best apparent design, but the exact Commander 15 private-hook contract must be checked before that conclusion is merge-ready.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9d0c1f8f8c59.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: This corrects misleading CLI error behavior with limited blast radius.
  • merge-risk: 🚨 other: The patch overrides a private dependency hook whose exact pinned implementation could not be inspected locally.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository state identifies this as a member-authored PR, so the external-contributor proof gate does not apply; the body nevertheless provides useful built-distribution terminal evidence, though it should be rerun on the final head.

Evidence

What I checked:

  • Current-main gap: Current main only reclassifies an excess-arguments error after Commander reaches error handling, so a help exit can occur first for a lazy placeholder. (src/cli/program/openclaw-command.ts:10, 76f4b942e055)
  • Proposed owner-boundary repair: The PR defers help only for marked lazy placeholders, then lets the real loaded tree classify a child token; normal paths delegate to Commander through super. (src/cli/program/openclaw-command.ts:28, 5689d833cbcc)
  • Lazy registration and reparse caller: All lazy command groups use the marked placeholder helper, whose action replaces the placeholder and reparses root argv after registration. (src/cli/program/register-lazy-command.ts:27, 5689d833cbcc)
  • Behavior coverage: Tests exercise unknown lazy-child help with exit 1 and no stdout, real lazy-child help, and ordinary root/group/leaf help behavior. (src/cli/program/error-output.test.ts:110, 5689d833cbcc)
  • Dependency-contract gap: The patch overrides Commander’s untyped private help hook; OpenClaw pins commander 15.0.0, but this checkout has no resolved node_modules and network access could not retrieve the exact package source or types. (package.json:2017, 5689d833cbcc)
  • Feature provenance: The current parse-error behavior dates to the same recent CLI area change, authored by Peter Steinberger, which introduced unknown-subcommand classification on main. (src/cli/program/openclaw-command.ts:10, 76f4b942e055)

Likely related people:

  • steipete: Current-main history attributes the preceding unknown-subcommand repair to Peter Steinberger, and this PR continues the same owner boundary. (role: recent CLI parse-error contributor; confidence: high; commits: 76f4b942e055, 5689d833cbcc; files: src/cli/program/openclaw-command.ts, src/cli/program/commander-parse-facts.ts, src/cli/program/register-lazy-command.ts)

Rank-up moves

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

  • Inspect resolved commander 15.0.0 source/types for the hook contract.
  • Rerun the documented built-CLI cases on commit 5689d83 and record the result.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-16T17:35:38.763Z sha 048ce83 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-16T18:18:58.469Z sha cc8a383a3aca1e48572debb91d357b53bfde4a19 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/help-unknown-subcommand branch 2 times, most recently from 653b0cb to cc8a383 Compare August 16, 2026 18:13
@steipete
steipete force-pushed the steipete/help-unknown-subcommand branch from cc8a383 to 5689d83 Compare August 16, 2026 18:24
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 16, 2026
@steipete
steipete merged commit b80d55a into main Aug 16, 2026
216 checks passed
@steipete
steipete deleted the steipete/help-unknown-subcommand branch August 16, 2026 18:35
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 17, 2026
* fix(cli): report unknown subcommands even with --help

* fix(cli): scope Commander hook lint exceptions

* fix(cli): document Commander hook assertion

* refactor(cli): delegate the Commander help hook through super
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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.

1 participant