perf(cli): cache stable subcommand help#84786
Conversation
|
Codex review: needs maintainer review before merge. Workflow note: Future ClawSweeper reviews update this same comment in place. How this review workflow works
Summary Reproducibility: yes. at source level: current main only precomputes adjacent root/parent help paths while these four parent commands still fall through to the live CLI registration path. I did not independently run the RSS benchmark in this read-only review. PR rating What the crustacean ranks mean
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. Real behavior proof Risk before merge
Maintainer options:
Next step before merge Security Review detailsBest possible solution: Land the allowlisted metadata-backed help path after maintainer review and required gates confirm generated metadata, fast/live help equivalence, and startup budget for the four parent commands. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main only precomputes adjacent root/parent help paths while these four parent commands still fall through to the live CLI registration path. I did not independently run the RSS benchmark in this read-only review. Is this the best way to solve the issue? Yes, the allowlist plus live fallback is the narrow maintainable shape: stable parent help is cached while nested, plugin-sensitive, invalid-argv, disable-env, and version paths stay live. Label changes:
Label justifications:
Acceptance criteria:
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 8a8f9dc8cb77. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a7c72af714
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| path.join(rootDir, "src/cli/gateway-cli.ts"), | ||
| path.join(rootDir, "src/cli/gateway-cli/register.ts"), | ||
| path.join(rootDir, "src/cli/gateway-cli/run-command.ts"), |
There was a problem hiding this comment.
Hash all gateway help sources in startup metadata signature
resolveSubcommandHelpSourceSignature only hashes src/cli/gateway-cli.ts, src/cli/gateway-cli/register.ts, and src/cli/gateway-cli/run-command.ts, but gateway --help output also depends on service subcommands added by addGatewayServiceCommands in src/cli/daemon-cli/register-service-commands.ts (imported and invoked from registerGatewayCli). If that service-command file changes, the signature here will stay unchanged, writeCliStartupMetadata can skip regeneration, and shipped precomputed gateway help can go stale until another hashed file changes.
Useful? React with 👍 / 👎.
| invocation.commandPath.length !== 1 || | ||
| !hasHelpFlag(argv) || | ||
| invocation.isRootHelpInvocation |
There was a problem hiding this comment.
Validate argv before taking subcommand help fast path
resolvePrecomputedSubcommandHelpFastPath relies on commandPath + --help presence, but commandPath is built by skipping option tokens, including unknown root flags. That means inputs like openclaw --bogus doctor --help can still resolve to doctor and short-circuit to precomputed help in run-main, bypassing normal CLI parsing/validation and turning an invalid invocation into a successful help response.
Useful? React with 👍 / 👎.
| !hasHelpFlag(argv) || | ||
| invocation.isRootHelpInvocation |
There was a problem hiding this comment.
Preserve version precedence for help+version subcommand invocations
The new fast path triggers for any allowlisted subcommand with -h/--help, but it does not exclude argv that also contain -V/--version. On the live path, configureProgramHelp in src/cli/program/help.ts checks version flags first and exits with version output, so invocations like openclaw doctor --help --version now return help instead of version only when this fast path is taken. This is a behavior regression introduced by the routing condition.
Useful? React with 👍 / 👎.
|
ClawSweeper PR egg ✨ Hatched: 🥚 common Gilded Lint Imp Hatch commandComment Hatchability rules:
Rarity: 🥚 common. What is this egg doing here?
|
f31e12b to
4e25ef0
Compare
3e63c84 to
1111d0f
Compare
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Serve stable doctor, gateway, models, and plugins parent help from startup metadata while preserving strict argv validation and version precedence. Verification: - pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=default - pnpm check:changed - GitHub required checks passed
Summary
doctor --help,models --help,plugins --help, andgateway --helpstill built the full CLI path and used about 320MB RSS just to print parent help.-h/--helpinvocations through a precomputed fast path.doctor,gateway,models, andplugins;run-maincan emit those pages before full CLI registration; tests cover metadata determinism, routing, disable env, and version passthrough.--versioncontinues to use the live command path.Motivation
Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Real behavior proof (required for external PRs)
openclaw.mjs.pnpm test:startup:bench -- --case doctorHelp --case modelsHelp --case pluginsHelp --case gatewayHelp --runs 3 --warmup 1 --json --output .artifacts/perf-subcommand-help-after-rebase.json.Root Cause (if applicable)
run-mainand built enough CLI state to cost hundreds of MB RSS.Regression Test Plan (if applicable)
src/cli/run-main.test.ts,src/cli/run-main.exit.test.ts,test/scripts/write-cli-startup-metadata.test.ts.User-visible / Behavior Changes
openclaw doctor --help,openclaw gateway --help,openclaw models --help, andopenclaw plugins --helpprint materially faster with lower RSS.Diagram (if applicable)
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation: N/ARepro + Verification
Environment
Steps
OPENCLAW_DISABLE_CLI_STARTUP_HELP_FAST_PATH=1to compare live output.doctorHelp,modelsHelp,pluginsHelp, andgatewayHelp.Expected
Actual
Evidence
After rebase benchmark (
runs=3,warmup=1):doctor --help: avg 84.1ms, p95 85.0ms, RSS avg 94.6MBmodels --help: avg 87.9ms, p95 92.0ms, RSS avg 94.8MBplugins --help: avg 82.3ms, p95 84.3ms, RSS avg 94.8MBgateway --help: avg 82.7ms, p95 82.8ms, RSS avg 94.7MBVerification run:
pnpm test src/cli/run-main.test.ts src/cli/run-main.exit.test.ts src/entry.test.ts src/cli/startup-metadata.test.ts test/scripts/write-cli-startup-metadata.test.ts -- --reporter=defaultpnpm builddoctor,gateway,models,pluginspnpm test:startup:bench -- --case doctorHelp --case modelsHelp --case pluginsHelp --case gatewayHelp --runs 3 --warmup 1 --json --output .artifacts/perf-subcommand-help-after-rebase.jsonpnpm test:startup:bench:check --report .artifacts/perf-subcommand-help-after-rebase.json --skip-baselinepnpm check:changedHuman Verification (required)
gateway status --helpremains live;doctor --versionandgateway -Vdo not use precomputed help.Review Conversations
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoRisks and Mitigations
-h/--help; version equivalence was verified.