Skip to content

refactor(cli): reuse function-shaped lazy loaders - #131144

Merged
steipete merged 1 commit into
mainfrom
codex/cleanup20k-cli-lazy-refresh-20260827
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cleanup20k-cli-lazy-refresh-20260827

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The gateway, daemon-status, and routed CLI paths repeat private forwarding functions around lazy import loaders even though the shared lazy-promise owner already exposes the same function-shaped API. This maintainer-requested cleanup removes that unnecessary indirection.

Why This Change Was Made

Use the existing createLazyPromise for all 22 forwarding-only loaders across these three owners. Deferred imports, cached promise identity, concurrent-load deduplication, and rejection eviction still use the unchanged canonical implementation. Remove five private type aliases used only by those wrappers.

The refresh preserves the local-port selection and authentication behavior from #130847 (gateway status leaf-port handling); daemon service registration is untouched. Production LOC: +25/-126, net -101. Tests: +0/-0. No new helper, compatibility path, flag, configuration, or dependency.

User Impact

No user-visible behavior change. Commands, options, output, startup laziness, and retry behavior remain the same. This is an AI-assisted internal refactor requested by the maintainer.

Evidence

  • Fresh independent P0-P3 precommit review: no findings. Complete owner/caller/callee/sibling/history review and AST equivalence checks preserve all 122 other top-level statements and each lazy import expression.
  • Pinned Linux baseline and candidate: the same eight existing test files passed, 214 tests plus one Darwin-only skip on each version. Coverage includes lazy-promise retries, real Commander parsing, gateway/daemon status, probe, inherited/leaf port precedence, and routing.
  • Full candidate changed gate passed: core/coreTests type checks, lint, format, all three Knip scans, and repository guards. Baseline CLI-startup build and full candidate production build passed, including the CLI bootstrap and plugin export checks; no ineffective-dynamic-import warnings.
  • 34 real built CLI processes passed using disposable state and source fallback disabled: help, health JSON/text, config lookup, tasks list/audit, status aliases, and 16 explicit-local-port cases. Six stable outputs matched literally. Remote-mode config and a distinct decoy endpoint verify leaf/inherited port selection, leaf-over-parent precedence, local auth, and no-probe behavior; zero decoy connections. The gateway transport was an owned deterministic fixture, not a live-provider or installed-service test.
  • Five complete inventories of 34,349 tracked files verified that baseline remained unchanged and candidate differed only by this three-file patch. The proof's temporary dependency build output was restored; artifacts were collected and verified before the owned environment was stopped.
  • Supplemental candidate macOS run: all 215 tests passed, including the Darwin case. Existing local Vitest/tsx versions were older than the declared pins, so pinned proof comes from Linux.

Linux provider: blacksmith-testbox; lease tbx_01m128grx6q7501h6jyj093r0b; proof workflow. The managed command completed with exit code 0 before explicit lease cleanup; the linked workflow can show cancellation after the lease is stopped. Exact proof base: 19d61d9ada04b5b9af24efc444f7bd05c53b82c0. Candidate patch SHA-256: 87223049862215602503de4b02eac8a99128794c17a0708db15ccfb471d3a7e7. Collected evidence archive SHA-256: f7f0e6f0089e6d51364222effe619df86728f23e826664331e05f4b2e469c6ac.

Focused command on both Linux versions:

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs \
  src/shared/lazy-promise.test.ts \
  src/cli/gateway-cli/register.option-collisions.test.ts \
  src/cli/daemon-cli/register-service-commands.test.ts \
  src/cli/daemon-cli/status.gather.test.ts \
  src/cli/daemon-cli/probe.test.ts \
  src/cli/gateway-port-option.test.ts \
  src/cli/program/routes.test.ts \
  src/cli/route.test.ts

Candidate gate/build commands in the isolated Linux worktree:

OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 node scripts/check-changed.mjs \
  --base 19d61d9ada04b5b9af24efc444f7bd05c53b82c0 --staged
node --import ./scripts/tsx.mjs scripts/build-all.mts

The changed-gate environment flag is the wrapper's delegation-loop guard, not a skipped check. Built-CLI proof covers read-only commands only; it does not claim installation or service lifecycle validation.

@steipete steipete self-assigned this Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 19:32
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 3:40 PM ET / 19:40 UTC.

ClawSweeper review

What this changes

The PR removes forwarding wrappers around lazy dynamic imports in three CLI modules by using the existing function-shaped lazy-promise API directly.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open: current main does not contain this cleanup, and direct inspection found the wrapper-to-function replacement preserves the shared lazy-loader contract with no actionable regression.

Priority: P3
Reviewed head: bc57acb09ff15555d70f15a0a5a1b63a6a4052c6

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused net-reducing refactor with direct contract equivalence and detailed CLI-path validation.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied PR evidence documents after-fix built-CLI runs through the affected command paths with disposable state and an owned deterministic transport fixture.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied PR evidence documents after-fix built-CLI runs through the affected command paths with disposable state and an owned deterministic transport fixture.
Evidence reviewed 5 items Canonical loader contract: The function-shaped helper constructs the same cached loader and returns its load method; both forms retain single-flight caching and rejected-load eviction.
Introduced replacement: The introduced lines retain each dynamic-import callback while replacing forwarding-only load calls with the canonical function-shaped helper.
Caller and test coverage: Affected consumers still invoke zero-argument loaders, while the shared helper tests cover single-flight behavior and retry after rejection; route and status suites cover the consuming CLI paths.
Findings None None.
Security None None.

Live Verification

Command: pnpm build && node openclaw.mjs --help

Result: FAIL (failed) — step 1 expect_output Usage:: expected terminal output was not visible within 30 seconds: "Usage:"

$ node --import ./scripts/tsx.mjs scripts/build-all.mts
[build-all] plugins:assets:build
$ node --import ./scripts/tsx.mjs scripts/bundled-plugin-assets.mts --phase build
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 109.29 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[build-all] plugins:assets:build done in 2.09s
[build-all] tsdown-ai
[PLUGIN_TIMINGS] Your build spent significant time in plugins. Here is a breakdown:
  - tsdown:deps (51%)
  - rolldown-plugin-dts:generate (20%)
  - rolldown-plugin-dts:fake-js (18%)
See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more details.

[tsdown-build] invocation 1/1 finished in 4.6s
[build-all] tsdown-ai done in 5.25s
[build-all] tsdown-packages
[tsdown-build] invocation 1/1 finished in 22.0s
[build-all] tsdown-packages done in 22.7s
[build-all] tsdown-unified

Assertions:

  • FAIL expect_output: Usage:

How this fits together

OpenClaw’s CLI lazily imports status, gateway, and routed command implementations after command parsing. These loaders keep startup light while supplying the modules that produce CLI output or perform gateway diagnostics.

flowchart LR
  A[CLI invocation] --> B[Command registration]
  B --> C[Lazy module loader]
  C --> D[Dynamic command module]
  D --> E[Gateway or daemon action]
  E --> F[CLI output]
Loading

Before merge

  • Complete next step (P2) - No repair is needed; this maintainer-associated PR is ready for normal exact-head check completion and landing review.
Agent review details

Security

None.

PR surface

Source -101. Total -101 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 3 25 126 -101
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 25 126 -101

Review metrics

Metric Value Why it matters
Production vs. test LOC production -101, tests 0 The refactor removes private forwarding indirection without adding a runtime capability or test-only support surface.

Technical review

Best possible solution:

Land the focused refactor after exact-head checks complete, retaining createLazyPromise as the single function-shaped lazy-loading contract.

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

Not applicable: this is a refactor, and source comparison establishes that the former wrappers only delegated to the same canonical loader.

Is this the best way to solve the issue?

Yes: direct use of createLazyPromise removes adapter-only code while preserving the underlying loader owner, cache behavior, and dynamic-import callbacks.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a behavior-neutral CLI cleanup with no reported user-facing regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied PR evidence documents after-fix built-CLI runs through the affected command paths with disposable state and an owned deterministic transport fixture.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The supplied PR evidence documents after-fix built-CLI runs through the affected command paths with disposable state and an owned deterministic transport fixture.

Label justifications:

  • P3: This is a behavior-neutral CLI cleanup with no reported user-facing regression.
  • 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. Sufficient (terminal): The supplied PR evidence documents after-fix built-CLI runs through the affected command paths with disposable state and an owned deterministic transport fixture.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied PR evidence documents after-fix built-CLI runs through the affected command paths with disposable state and an owned deterministic transport fixture.

Evidence

What I checked:

  • Canonical loader contract: The function-shaped helper constructs the same cached loader and returns its load method; both forms retain single-flight caching and rejected-load eviction. (src/shared/lazy-promise.ts:55, e2e030e2b0ae)
  • Introduced replacement: The introduced lines retain each dynamic-import callback while replacing forwarding-only load calls with the canonical function-shaped helper. (src/cli/gateway-cli/register.ts:41, bc57acb09ff1)
  • Caller and test coverage: Affected consumers still invoke zero-argument loaders, while the shared helper tests cover single-flight behavior and retry after rejection; route and status suites cover the consuming CLI paths. (src/shared/lazy-promise.test.ts:107, bc57acb09ff1)
  • Current-main necessity: Fetched main retains the prior loader-object wrappers, and the PR head is not an ancestor of fetched main; this cleanup is neither merged nor released. (src/cli/gateway-cli/register.ts:41, a509254b16ea)
  • Submitted runtime evidence: The PR body records built-CLI execution against disposable state and an owned deterministic gateway transport, plus focused lazy-loader, parser, status, and route validation. (bc57acb09ff1)

Likely related people:

  • steipete: Authored this refactor and the merged gateway-status port repair in the same status and gateway registration area. (role: recent CLI contributor; confidence: high; commits: bc57acb09ff1, d3aa4be83a73; files: src/cli/gateway-cli/register.ts, src/cli/daemon-cli/status.gather.ts)
  • Jesse Merhi: Git blame attributes the canonical lazy-promise helper and the pre-refactor routed-loader lines to the commit that introduced the shared implementation. (role: shared helper introducer; confidence: medium; commits: e2e030e2b0ae; files: src/shared/lazy-promise.ts, src/cli/program/routed-command-definitions.ts)

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Landing verification for bc57acb: exact-head CI and the required openclaw/ci-gate are green. Independent precommit and published-head reviews found no actionable defects. Fresh main inspection preserves all three owners, the shared helper, and the reviewed caller/test context; no rebase or source change was needed.

The latest ClawSweeper review has no actionable findings or Rank-up moves. Its separate 30-second smoke expectation expired during tsdown-unified, before the CLI help command ran; that is not a CLI-help failure. Separately completed proof includes the full candidate build (4m49.2s), 214 passing focused Linux tests plus one platform skip on both baseline and candidate, and 34 successful real built-CLI processes. Those processes cover help, routed outputs, and local-port/auth selection with a decoy endpoint; exact-head hosted launcher smokes also passed. The fixture uses an isolated mock gateway transport, not live provider credentials or installed-service lifecycle operations.

The cleanup removes 101 net production lines by using the existing function-shaped lazy promise helper for 22 private loaders; tests, CLI flags, and public behavior are unchanged.

@steipete
steipete merged commit 3bc404d into main Aug 27, 2026
277 checks passed
@steipete
steipete deleted the codex/cleanup20k-cli-lazy-refresh-20260827 branch August 27, 2026 20:24
@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 28, 2026
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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. 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