perf(cli): lazy-load agents actions for help#84483
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. Current main source shows 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 lazy-load refactor after maintainer review and required checks, keeping the direct import tests as the regression guardrail. Do we have a high-confidence way to reproduce the issue? Yes. Current main source shows Is this the best way to solve the issue? Yes. Callback-time direct imports are a narrow maintainable fix because they preserve the Commander help skeleton and existing command behavior while avoiding help-time action module loading. Label justifications:
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against a30ac3f8d7cb. |
|
ClawSweeper PR egg ✨ Hatched: 🥚 common Neon Signal Puff Hatch commandComment Hatchability rules:
Rarity: 🥚 common. What is this egg doing here?
|
|
@codex review Addressed the stale route-test mock finding:
Local verification after the repair: |
hxy91819
left a comment
There was a problem hiding this comment.
LGTM overall. This is a typical and appropriate Node/ESM CLI cold-start optimization: moving the heavy command implementations from static registration-time imports to action-time dynamic imports keeps the help path light, while preserving the existing command behavior and not changing any public SDK contract.
One thing I would recommend fixing before merge: the refactor appears to leave src/commands/agents.ts as a production-dead barrel. The direct lazy imports now target the individual agents.commands.* modules, so this aggregate re-export file no longer seems to be used by the production graph, and CI is flagging it as an unexpected unused file. Please either remove that barrel and update the remaining tests/mocks to use the direct modules, or restore an intentional production use if the barrel is meant to remain.
45d260b to
ce19662
Compare
ce19662 to
364a8b3
Compare
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Lazy-load agents CLI action modules from command callbacks so agents --help avoids importing the full agents runtime. Validated by GitHub required checks and local focused CLI gates.
Summary
openclaw agents --helpimported the full agents action barrel and paid heavy startup cost on a help-only path.agents-listrouted command now imports the list module directly; cold-import tests coveragents --help.Motivation
agents --helpmeasured at ~1.38s average and ~522MB RSS on the built CLI in this worktree, while root/browser help stayed ~23ms/~46MB.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Real behavior proof (required for external PRs)
openclaw agents --helpcold-start import/runtime cost.openclaw.mjsentry.pnpm build;node dist/entry.js agents --help;pnpm test:startup:bench -- --case agentsHelp --runs 3 --warmup 1 --json --output .artifacts/perf-agents-help-after.json.pnpm testsuite.Root Cause (if applicable)
register.agent.tsstatically importedagent-via-gatewayand thecommands/agents.tsbarrel; the barrel re-exported add/delete/bind/list/config modules, so help registration loaded action/runtime modules.agents --help.Regression Test Plan (if applicable)
src/cli/help-cold-imports.test.ts,src/cli/program/register.agent.test.ts.agents --helpdoes not import agent/agents action modules, while action paths still call the same command functions.User-visible / Behavior Changes
openclaw agents --helpstarts faster and uses less memory. Help text and command behavior are unchanged.Diagram (if applicable)
Security Impact (required)
Yes, explain risk + mitigation: N/ARepro + Verification
Environment
Steps
pnpm buildnode dist/entry.js agents --help > .artifacts/agents-help-after.txtdiff -u .artifacts/agents-help-before.txt .artifacts/agents-help-after.txtpnpm test:startup:bench -- --case agentsHelp --runs 3 --warmup 1 --json --output .artifacts/perf-agents-help-after.jsonExpected
agents --helpavoids loading heavy agents action modules.Actual
agents --helpbenchmark improved from 1382.0ms avg / 522.4MB RSS avg to 361.2ms avg / 321.7MB RSS avg.Evidence
Human Verification (required)
pnpm test src/cli/help-cold-imports.test.ts src/cli/program/register.agent.test.ts src/cli/run-main.exit.test.ts -- --reporter=defaultpnpm builddiff -u .artifacts/agents-help-before.txt .artifacts/agents-help-after.txtpnpm test:startup:bench -- --case agentsHelp --runs 3 --warmup 1 --json --output .artifacts/perf-agents-help-after.jsonpnpm tsgopnpm check:changedagentsdefault action still calls list; lazy-loaded action failures still route through runtime error handling; routedagents-listavoids the barrel.Review Conversations
Compatibility / Migration
Risks and Mitigations