Skip to content

refactor(cli): make update help and planning faster - #133698

Merged
steipete merged 2 commits into
mainfrom
codex/update-cli-startup-performance
Aug 31, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/update-cli-startup-performance

Conversation

@steipete

@steipete steipete commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Update help and previews spend time loading doctor, restart, and plugin-repair code that they do not use. Planning also collects Git status that is discarded and repeats service/package-manager discovery. This makes a read-only preview unnecessarily slow before an operator can see the plan.

Follow-up to the update CLI cleanup in #133622, requested by a maintainer.

Why This Change Was Made

Separate command registration and read-only planning from update execution. The execution, finalization, and resume graph is still loaded together before package replacement, so recovery never depends on importing old chunks after they have been removed. Service root and Node selection use one inspection; stop/restart ownership checks still revalidate independently.

Reuse canonical Git-root ownership without collecting unused history/worktree status, and skip a package-manager root query when the installation owner already supplies the root. Full update status, ambiguous package layouts, schema checks, recovery, flags, and output contracts remain intact. Remove the old forwarding exports and duplicated planning paths.

User Impact

Help and dry-run return sooner. Measured dry-run stdout and stderr are byte-identical; rebuilt help differs only in the expected build SHA banner. These are startup/planning gains; download, installation, and build time were not benchmarked. No new flags, configuration, environment options, dependencies, or schema changes.

Evidence

Built CLI, isolated home/config/state per invocation, one warmup plus three measured runs on the same machine and Node runtime:

Command Before median Final candidate median
update --help 1.33s 0.24s
update status --help 1.32s 0.25s
update --dry-run --no-restart 2.84s 1.14s
update --dry-run --no-restart --json 2.59s 1.26s

Host load and caches affect wall time: an earlier candidate batch measured 0.40s help and 1.76s dry-run. The structural reductions are deterministic: profiled dry-run loads 2,011 modules instead of 2,615 and runs one Git ownership probe instead of six Git subprocesses. Service planning reads once instead of twice; known npm roots omit the redundant root probe while retaining the lifecycle/version probe.

  • 914 focused tests passed across updater CLI/infra, service ownership, package-manager layouts, finalization, lease, and recovery coverage; one existing PowerShell-only case skipped on macOS.
  • After the final import/lint cleanup, all 337 affected tests passed: node scripts/run-vitest.mjs src/cli/update-cli.test.ts src/cli/update-cli.startup.test.ts src/infra/update-check-install-kind.test.ts src/infra/update-check-status.test.ts src/infra/update-check.test.ts.
  • The new help guard fails against original eager registration. Service-planning cases fail on original code because it reads the service twice. Real Git fixtures cover symlinks, separate Git directories, unrelated ancestors, invalid markers, and explicit Git environment.
  • OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build passed; built execution/finalization/resume exports were loaded from an isolated home.
  • env -u OPENCLAW_TESTBOX node scripts/check-changed.mjs passed again on the final candidate, including production/test types, lint, dead exports, storage/loader guards, and zero runtime import cycles. An initial lonely-if lint finding was fixed before the successful rerun.
  • After integrating the overlapping upstream invocation-relative profile fix, 393 updater tests passed. Rebuilt CLI medians were 0.20s help, 0.20s status help, 0.91s dry-run, and 0.84s JSON; these later timings also reflect host/cache variation.
  • Initial hosted CI found an unused import after integration, a type-only cycle through an advisory forwarding export, and a stale process fixture. Removed the unused import/forwarder, imported the advisory from its owner, and updated the fixture. The existing process suite reproduced 10 failures before and 10 passes afterward, covering repair/finalize human, JSON, inherited JSON, doctor errors, and plugin errors. Madge reports zero cycles.
  • Packaged Linux multi-Node proof on final head a1ce54709c85: CI=1 pnpm test:docker:multi-node-update passed in Testbox run 33348712160, exit 0. The actual self-update retained the original Node and installation prefix, preserved the service entrypoint, and passed the real Gateway health probe. The one-shot Testbox stopped after success; its backing Actions session can show cancellation because the lease lifecycle owns completion. This uses the packaged CLI and real Gateway with a service-manager fixture.
  • Fresh Codex autoreview of the complete candidate including the CI fixes: scoped clean through P2, no findings. Exact-head CI run 33348695881 is green for a1ce54709c85cddb425f39629f0649ab0e864848.

Production LOC: +562/-571 (net -9); tests/support: +142/-29 (net +113); docs: +5. Most source churn extracts existing owners into planning and execution modules.

Maintainer review follow-through

The latest ClawSweeper review on a1ce54709c85 identified no correctness/security findings. Its remaining risk and optional Rank-up move request a current-main refresh because its partial checkout could not load source blobs. Checked current main 85ec67d66fab32cb0a858c80caf53019592d6510 directly: none of the 37 PR paths changed upstream since base 67433ff43813. git merge-tree --write-tree succeeds without conflicts, and every PR path in the resulting tree is byte-identical to reviewed/tested head a1ce54709c85. We therefore skip the optional no-op rebase and preserve the exact head with green CI and packaged-update proof. The earlier overlapping invocation-relative profile fix was already integrated and tested.

The stored-data warnings are import-only changes: fresh-doctor imports its environment helpers from their canonical service-env owner; package-update-steps drops a forwarding type export; update-runner-types imports that advisory type directly from its owner. No migration, schema, or persisted-data semantics changed. Fresh full-candidate Codex review is clean, and the native merge flow rechecks the current PR/main state before landing.

@clawsweeper

clawsweeper Bot commented Aug 31, 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 docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: XL maintainer Maintainer-authored PR labels Aug 31, 2026
@steipete
steipete force-pushed the codex/update-cli-startup-performance branch from 37f2b3b to c3dfde9 Compare August 31, 2026 01:36
@steipete
steipete marked this pull request as ready for review August 31, 2026 01:36
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 31, 2026
@clawsweeper

clawsweeper Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 9:55 PM ET / August 31, 2026, 01:55 UTC.

ClawSweeper review

What this changes

This PR lazily loads update execution code and consolidates read-only update planning so CLI help and dry-run avoid unnecessary startup work.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for maintainer review: this is a distinct active follow-up to the merged updater repair, has no supported introduced correctness finding, and carries the protected maintainer label.

Priority: P3
Reviewed head: a1ce54709c85cddb425f39629f0649ab0e864848
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has coherent owner-boundary extraction and focused regression coverage, pending a current-main refresh.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored CLI refactor is exempt from the external-contributor proof gate; its supplied built-CLI evidence is supplemental and was not executed by this read-only review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored CLI refactor is exempt from the external-contributor proof gate; its supplied built-CLI evidence is supplemental and was not executed by this read-only review.
Evidence reviewed 5 items Lazy registration and execution boundary: Command registration imports each update owner only when its Commander action executes, while mutable updates preload the complete execution/finalization/resume boundary before any package replacement.
Service authority remains revalidated: The planning snapshot only selects a root and Node runtime; the mutable path independently inspects/stops the service and the post-update path revalidates it before restart.
Behavior-level regression coverage: The added guard makes every execution module unavailable and verifies that top-level and leaf help still render, while existing option-collision tests exercise the lazily imported action owners.
Findings None None.
Security None None.

How this fits together

The update CLI registers help, status, repair, and update commands for operators. Read-only planning chooses an install and service context before the mutable updater performs package or Git changes and post-update recovery.

flowchart LR
  A[Operator update command] --> B[CLI registration and help]
  B --> C{Help or execution}
  C -->|Help| D[Rendered command help]
  C -->|Execution| E[Read-only update planning]
  E --> F[Preloaded update runtime]
  F --> G[Package or Git update]
  G --> H[Service recovery and result]
Loading

Decision needed

Question Recommendation
Should this protected updater refactor be refreshed against current main and landed once exact-head validation confirms the preserved update and recovery contracts? Refresh and validate: Rebase onto current main and rerun the focused update CLI and package/recovery validation before landing.

Why: The branch is a maintainer-owned, protected-label refactor and current-main updater source could not be fully inspected from this partial checkout.

Before merge

  • Resolve merge risk (P1) - Current main has changed updater paths since the pinned base, but an exact merge-result review was unavailable in this partial checkout; refresh the branch and exact-head validation before landing.
Agent review details

Security

None.

PR surface

Source -15, Tests +119, Docs +5. Total +109 across 37 files.

View PR surface stats
Area Files Added Removed Net
Source 28 565 580 -15
Tests 8 139 20 +119
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 37 709 600 +109

Review metrics

Metric Value Why it matters
Production versus test delta production net -9; tests/support net +113; docs +5 The refactor is net-negative in production code while adding focused coverage for lazy help registration and update planning.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/cli/update-cli/update-command-fresh-doctor.ts, migration/backfill/repair: src/infra/package-update-steps.ts, migration/backfill/repair: src/infra/update-runner-types.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Rebase the refactor onto current main, retain the pre-mutation runtime preload and independent service revalidation, then validate help, dry-run, package update, and recovery on the exact head.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Rebase the refactor onto current main, retain the pre-mutation runtime preload and independent service revalidation, then validate help, dry-run, package update, and recovery on the exact head.

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

Not applicable: this is a performance refactor, not a defect report; the review was read-only, while the added process-level guards target the claimed help and planning paths.

Is this the best way to solve the issue?

Yes, conditionally: lazy registration plus a pre-mutation execution preload preserves the required recovery boundary, but current-main rebase validation remains necessary.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P3: This is a performance-oriented CLI refactor with no supported user-facing regression or security finding.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored CLI refactor is exempt from the external-contributor proof gate; its supplied built-CLI evidence is supplemental and was not executed by this read-only review.

Evidence

What I checked:

  • Lazy registration and execution boundary: Command registration imports each update owner only when its Commander action executes, while mutable updates preload the complete execution/finalization/resume boundary before any package replacement. (src/cli/update-cli.ts:191, a1ce54709c85)
  • Service authority remains revalidated: The planning snapshot only selects a root and Node runtime; the mutable path independently inspects/stops the service and the post-update path revalidates it before restart. (src/cli/update-cli/update-command-execution.ts:77, a1ce54709c85)
  • Behavior-level regression coverage: The added guard makes every execution module unavailable and verifies that top-level and leaf help still render, while existing option-collision tests exercise the lazily imported action owners. (src/cli/update-cli.startup.test.ts:13, a1ce54709c85)
  • Distinct from preceding merged updater repair: The prior merged updater repair is an ancestor of this PR base and current main, but this PR head is not an ancestor of fetched current main; it remains distinct work rather than an implemented or superseded patch. (src/cli/update-cli/update-command.ts:615, 69f17266eb04)
  • Current-main context limitation: Fetched current main is c29f34d and has later updater-path changes; promised source blobs could not be loaded because the checkout's GitHub DNS fetch failed, so this review does not claim an exact current-main merge result. (c29f34dc5312)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Rebase onto current main and rerun exact-head update help, dry-run, package-update, and recovery validation.

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 (1 earlier review cycle)
  • reviewed 2026-08-31T01:42:50.228Z sha c3dfde9 :: needs maintainer review before merge. :: none

@steipete steipete self-assigned this Aug 31, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 31, 2026
@steipete
steipete merged commit 6486d28 into main Aug 31, 2026
240 of 241 checks passed
@steipete
steipete deleted the codex/update-cli-startup-performance branch August 31, 2026 02:06
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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